extends KinematicBody2D
const UP = Vector2(0,-1)
const GRAVITY = 10
const MAXFALLSPEED = 250
const MAXSPEED = 500
const JUMPFORCE = 300
const ACCEL = 90
const STOP = 0
var motion = Vector2()
var facing_right = true
func _ready():
pass
func physicsprocess(_delta):
motion.y += GRAVITY
if motion.x > 0:
$Sprite.scale.x = 1
if motion.x < 0:
$Sprite.scale.x = -1
motion.x = clamp(motion.x, -MAXSPEED, MAXSPEED)
if motion.y > 10:
$AnimationPlayer.play("Fall")
if motion.y == 0:
$AnimationPlayer.play("Idle")
if motion.x > 0:
$AnimationPlayer.play("Run")
if motion.x < 0 :
$AnimationPlayer.play("Run")
if Input.is_action_pressed("ui_left"):
motion.x -= ACCEL
elif Input.is_action_pressed("ui_right"):
motion.x += ACCEL
elif Input.is_action_just_released("ui_left"):
motion.x = 0
$AnimationPlayer.play("Idle")
elif Input.is_action_just_released("ui_right"):
motion.x = 0
$AnimationPlayer.play("Idle")
if is_on_floor():
if Input.is_action_pressed("ui_up"):
$AnimationPlayer.play("Jump")
motion.y = -JUMPFORCE
if facing_right == true:
if Input.is_action_just_pressed("ui_page_down"):
$AnimationPlayer.play("Attack2")
position.x += 200
$Sprite.scale.x = 1
if Input.is_action_just_pressed("ui_page_up"):
$AnimationPlayer.play("Attack2")
position.x -= 200
$Sprite.scale.x = -1
if Input.is_action_pressed("ui_accept"):
$AnimationPlayer.play("Attack1")
motion = move_and_slide(motion, UP)