2014-02-23 00:28:19 +01:00
|
|
|
|
|
|
|
extends KinematicBody2D
|
|
|
|
|
|
|
|
# This is a simple collision demo showing how
|
2015-11-21 16:13:43 +01:00
|
|
|
# the kinematic controller works.
|
2014-02-23 00:28:19 +01:00
|
|
|
# move() will allow to move the node, and will
|
|
|
|
# always move it to a non-colliding spot,
|
|
|
|
# as long as it starts from a non-colliding spot too.
|
|
|
|
|
2015-11-21 16:13:43 +01:00
|
|
|
# Member variables
|
|
|
|
const MOTION_SPEED = 160 # Pixels/second
|
2014-02-23 00:28:19 +01:00
|
|
|
|
|
|
|
|
|
|
|
func _fixed_process(delta):
|
|
|
|
var motion = Vector2()
|
|
|
|
|
|
|
|
if (Input.is_action_pressed("move_up")):
|
2015-11-21 16:13:43 +01:00
|
|
|
motion += Vector2(0, -1)
|
2014-02-23 00:28:19 +01:00
|
|
|
if (Input.is_action_pressed("move_bottom")):
|
2015-11-21 16:13:43 +01:00
|
|
|
motion += Vector2(0, 1)
|
2014-02-23 00:28:19 +01:00
|
|
|
if (Input.is_action_pressed("move_left")):
|
2015-11-21 16:13:43 +01:00
|
|
|
motion += Vector2(-1, 0)
|
2014-02-23 00:28:19 +01:00
|
|
|
if (Input.is_action_pressed("move_right")):
|
2015-11-21 16:13:43 +01:00
|
|
|
motion += Vector2(1, 0)
|
2014-02-23 00:28:19 +01:00
|
|
|
|
2015-11-21 16:13:43 +01:00
|
|
|
motion = motion.normalized()*MOTION_SPEED*delta
|
2014-02-23 00:28:19 +01:00
|
|
|
move(motion)
|
2015-11-21 16:13:43 +01:00
|
|
|
|
2014-02-23 00:28:19 +01:00
|
|
|
|
|
|
|
func _ready():
|
|
|
|
# Initalization here
|
|
|
|
set_fixed_process(true)
|