You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 

51 lines
1.1 KiB

extends KinematicBody2D
# Declare member variables here. Examples:
# var a = 2
# var b = "text"
# Called when the node enters the scene tree for the first time.
var moveSpeed : int = 280
var vel = Vector2()
var facingDir = Vector2()
onready var rayCast = $RayCast2D
onready var anim = $AnimatedSprite
func _ready():
pass
func _physics_process(delta):
handle_movements()
manage_animations()
func handle_movements():
vel = Vector2(-1, 0)
# inputs
if Input.is_action_pressed("move_up"):
vel.y = -0.2
if Input.is_action_pressed("move_down"):
vel.y = 0.2
if Input.is_action_pressed("move_left"):
moveSpeed += moveSpeed/100
else:
moveSpeed -= moveSpeed/200
if Input.is_action_pressed("move_right"):
moveSpeed -= 5
moveSpeed = clamp(moveSpeed, 280, 840)
# move the player
move_and_slide(vel * moveSpeed, Vector2.ZERO)
func play_animation (anim_name):
if anim.animation != anim_name:
anim.play(anim_name)
func manage_animations ():
if Input.is_action_pressed("move_left"):
play_animation("Accelerate")
else:
play_animation("default")