-
Notifications
You must be signed in to change notification settings - Fork 1
/
Player.gd
37 lines (32 loc) · 940 Bytes
/
Player.gd
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
extends KinematicBody2D
export (int) var speed = 175
var isMoving = 0
var lastDir = "left"
var velocity = Vector2()
func get_input():
velocity = Vector2()
if (!MyGlobals.gameOver):
if (Input.is_action_pressed('ui_right') || (isMoving && lastDir == "right")):
isMoving = 1
lastDir = "right"
velocity.x += 1
$AnimatedSprite.flip_h = false
if (Input.is_action_pressed('ui_left') || (isMoving && lastDir == "left")):
isMoving = 1
lastDir = "left"
velocity.x -= 1
$AnimatedSprite.flip_h = true
if (Input.is_action_pressed('ui_down') || (isMoving && lastDir == "down")):
isMoving = 1
lastDir = "down"
velocity.y += 1
if (Input.is_action_pressed('ui_up') || (isMoving && lastDir == "up")):
isMoving = 1
lastDir = "up"
velocity.y -= 1
velocity = velocity.normalized() * speed
else:
velocity = Vector2(0,0)
func _physics_process(delta):
get_input()
velocity = move_and_slide(velocity)