-
Notifications
You must be signed in to change notification settings - Fork 0
/
Spikes.gd
44 lines (35 loc) · 901 Bytes
/
Spikes.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
extends Area2D
# Nodes
onready var c = get_node("/root/Constants")
onready var hitbox = $Hitbox
export(int, "RED", "GREEN", "BLUE", "YELLOW", "WHITE") var color
enum {
ENABLED
DISABLED
}
var current_state = ENABLED
func _ready():
if !color: color = 0
$AnimatedSprite.animation = String(color)
if is_bg_color():
disable()
func _physics_process(delta):
if current_state == ENABLED:
if is_bg_color(): disable()
elif current_state == DISABLED:
if !is_bg_color(): enable()
func is_bg_color():
if color == 4: return false
return c.COLORS[color] == c.COLORS[c.color_index]
func disable():
if current_state == ENABLED:
hitbox.disabled = true
current_state = DISABLED
func enable():
if current_state == DISABLED:
hitbox.disabled = false
current_state = ENABLED
func _on_Spikes_body_entered(body):
if body.get_name() == "Player" && !body.is_dead:
$Audio.play()
body.die()