parent
9178c777b9
commit
84780473d9
@ -1,27 +1,42 @@
|
||||
extends KinematicBody2D
|
||||
|
||||
# export allows us to change the value of this variable from
|
||||
# the inspector in the editor!
|
||||
export var Speed = 5
|
||||
|
||||
|
||||
# this is where we do node initialization stuff
|
||||
func _ready():
|
||||
pass
|
||||
|
||||
# this is where we perform actions every frame (delta is how long
|
||||
# it's been since the last frame)
|
||||
func _process(delta):
|
||||
# if we set up velocity to be 0 then we stop as soon as the player
|
||||
# stops giving input
|
||||
var velocity = Vector2()
|
||||
|
||||
# an action is defined in Project->Project Settings->Input Map
|
||||
# it allows us to set up multiple keys to strings so we don't
|
||||
# have to poll for specific keys every frame
|
||||
|
||||
# going left and right
|
||||
if Input.is_action_pressed('ui_left'):
|
||||
velocity.x -= Speed
|
||||
elif Input.is_action_pressed('ui_right'):
|
||||
velocity.x += Speed
|
||||
|
||||
# going up and down
|
||||
if Input.is_action_pressed('ui_up'):
|
||||
velocity.y -= Speed
|
||||
elif Input.is_action_pressed('ui_down'):
|
||||
velocity.y += Speed
|
||||
|
||||
# if the player is holding shift, give us a speedboost
|
||||
if Input.is_key_pressed(KEY_SHIFT):
|
||||
velocity *= 2
|
||||
|
||||
# and finally, we move and collide!
|
||||
move_and_slide(velocity)
|
||||
|
||||
pass
|
||||
|
Loading…
Reference in new issue