|
|
|
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 initVel = Vector2()
|
|
|
|
var facingDir = Vector2()
|
|
|
|
var yVel = 1
|
|
|
|
var xVel = 1
|
|
|
|
var reverse = true
|
|
|
|
onready var rayCast = $RayCast2D
|
|
|
|
onready var anim = $AnimatedSprite
|
|
|
|
|
|
|
|
func _ready():
|
|
|
|
pass
|
|
|
|
|
|
|
|
func _physics_process(delta):
|
|
|
|
handle_movements()
|
|
|
|
manage_animations()
|
|
|
|
|
|
|
|
func handle_movements():
|
|
|
|
var vel = initVel
|
|
|
|
# inputs
|
|
|
|
if Input.is_action_pressed("move_up"):
|
|
|
|
vel.y = -yVel
|
|
|
|
if Input.is_action_pressed("move_down"):
|
|
|
|
vel.y = yVel
|
|
|
|
if Input.is_action_pressed("move_left"):
|
|
|
|
vel.x = -xVel
|
|
|
|
moveSpeed += moveSpeed/100
|
|
|
|
else:
|
|
|
|
moveSpeed -= moveSpeed/200
|
|
|
|
if Input.is_action_pressed("move_right"):
|
|
|
|
if reverse:
|
|
|
|
vel.x = 0.5 * xVel
|
|
|
|
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")
|