-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathAMB1.gd
51 lines (40 loc) · 1.15 KB
/
AMB1.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
38
39
40
41
42
43
44
45
46
47
48
49
50
51
extends Player
var velocity := Vector2.ZERO
var speed := 200.0
var acceleration := 0.2
var state = "idle-forward"
var flipped = false
func _ready():
pass
func _process(delta):
velocity = Vector2.ZERO
var new_state = 'idle-forward'
if Input.is_action_pressed("amb_up"):
velocity.y -= 1.0
new_state = 'move-up'
elif Input.is_action_pressed("amb_down"):
velocity.y += 1.0
new_state = 'move-down'
if Input.is_action_pressed("amb_left"):
velocity.x -= 1.0
new_state = 'move-side'
flipped = true
elif Input.is_action_pressed("amb_right"):
velocity.x += 1.0
new_state = 'move-side'
flipped = false
_change_state(new_state)
$AnimatedSprite.flip_h = flipped
velocity = velocity.normalized() * speed
# TODO(koger): Movement is snappy. Is this desirable? Do we want acceleration,
# sliding, and other effects that make it feel more slugish?
func _physics_process(delta):
velocity = move_and_slide(velocity)
func _change_state(new_state):
if new_state != state:
state = new_state
$AnimatedSprite.play(state)
func increment_energy_collected():
Globals.ambi_energy_collected += 1
func increment_hits_taken():
Globals.ambi_hits_taken += 1