forked from eclectic-kitty/fighting-hearts
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathplayer.gd
82 lines (59 loc) · 1.47 KB
/
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
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
extends Node2D
export var speed = 350
export var health = 100
var fw = 0
var held = 0
signal fired(heart_pos)
signal damaged(health)
signal dead()
var screen_size
func _ready():
screen_size = get_viewport_rect().size
func _process(delta):
var velocity = Vector2()
if Input.is_action_pressed("ui_left"):
velocity.x -= 1
if Input.is_action_pressed("ui_right"):
velocity.x += 1
if Input.is_action_pressed("ui_up"):
velocity.y -= 1
if Input.is_action_pressed("ui_down"):
velocity.y += 1
if velocity.length() > 0:
velocity = velocity.normalized() * speed
position += velocity * delta
position.x = clamp(position.x, 0, screen_size.x)
position.y = clamp(position.y, 0, screen_size.y)
if Input.is_action_just_pressed("fire") && fw == 0 && held == 0:
fire()
if Input.is_action_pressed("fire") && fw == 0 && held == 1:
fire()
if health <= 0:
dead()
func dead():
visible = 0
fw = 1
emit_signal("dead")
func fire():
emit_signal("fired", position)
fw = 1
$FireTimer.start()
func _on_FireTimer_timeout():
fw = 0
func _on_self_entered(_area_id, area, _area_shape, _self_shape):
if area.get_name() == "KnifeArea":
health = clamp(health - 10, 0, 100)
emit_signal("damaged", health)
func _on_powerup_equipped(_instance, on):
if on:
speed = 600
held = 1
$FireTimer.wait_time = 0.15
else:
speed = 350
held = 0
$FireTimer.wait_time = 0.3
func _on_Enemy_death():
health = clamp(health + 2, 0, 100)
emit_signal("damaged", health)
print(health)