-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathPlayer.gd
More file actions
169 lines (146 loc) · 4.97 KB
/
Copy pathPlayer.gd
File metadata and controls
169 lines (146 loc) · 4.97 KB
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
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
class_name Player
extends Node2D
export var speed = 100
onready var light_detection_area = $LightDetectionArea
onready var animation_player = $AnimationPlayer
export(NodePath) var waypoint_1
export(NodePath) var waypoint_2_1
export(NodePath) var waypoiny_2_detect_area
export(NodePath) var waypoint_2_2
export(NodePath) var waypoint_2_3
export(NodePath) var waypoiny_2_3_detect_area
export(NodePath) var waypoint_2_4
export(NodePath) var door_1
export(NodePath) var waypoint_3
export(NodePath) var waypoint_4_1
export(NodePath) var waypoiny_4_detect_area
export(NodePath) var waypoint_4_2
export(NodePath) var waypoint_5_1
export(NodePath) var waypoiny_5_detect_area
export(NodePath) var waypoint_5_2
var current_waypoint_sequence : WaypointSequence
var current_waypoint_index = 0
var waypoint_distance_threshold = 10
var waypoint_sequence_count = -1
var walk_playing = false
var scared_playing = false
var last_respawn_point: RespawnPoint
var game_started = false
var diamond = false
func start_game():
game_started = true
func is_lit() -> bool:
for area in light_detection_area.get_overlapping_areas():
if(area.is_in_group("light")):
return true
for body in light_detection_area.get_overlapping_bodies():
if(body.is_in_group("light")):
return true
return false
func move_to_waypoint(delta: float, waypoint: Vector2):
position += global_position.direction_to(waypoint) * delta * speed
func has_reached_waypoint(waypoint: Vector2) -> bool:
return global_position.distance_to(waypoint) <= waypoint_distance_threshold
func get_next_waypoint_sequence() -> WaypointSequence:
match waypoint_sequence_count:
-1:
return get_node(waypoint_1) as WaypointSequence
0:
if(get_node(waypoiny_2_detect_area).is_overlapping_player()):
return get_node(waypoint_2_2) as WaypointSequence
else:
return get_node(waypoint_2_1) as WaypointSequence
1:
if(get_node(waypoiny_2_3_detect_area).is_overlapping_player()):
return get_node(waypoint_2_4) as WaypointSequence
else:
return get_node(waypoint_2_3) as WaypointSequence
2:
return null
3:
return get_node(waypoint_3) as WaypointSequence
4:
if(get_node(waypoiny_4_detect_area).is_overlapping_player()):
return get_node(waypoint_4_2) as WaypointSequence
else:
return get_node(waypoint_4_1) as WaypointSequence
5:
if(get_node(waypoiny_5_detect_area).is_overlapping_player()):
return get_node(waypoint_5_2) as WaypointSequence
else:
return get_node(waypoint_5_1) as WaypointSequence
6:
get_tree().get_nodes_in_group("orby")[0].game_started = false
animation_player.play("diamond")
waypoint_sequence_count = -1
diamond = true
$CanvasLayer.add_child(preload("res://GameOver.tscn").instance())
return null
return null
func has_finished_waiting() -> bool:
match waypoint_sequence_count:
-1:
return game_started
3:
return get_node(door_1).is_open
return false
func advance_waypoint_sequence():
current_waypoint_index = 0
current_waypoint_sequence = get_next_waypoint_sequence()
waypoint_sequence_count += 1
func navigate_waypoint_sequence(delta: float):
if(not current_waypoint_sequence):
if(is_lit()):
$WalkSound.playing = false
walk_playing = false
play_or_continue_animation("idle")
scared_playing = false
$ScaredSound.playing = false
else:
$WalkSound.playing = false
walk_playing = false
play_or_continue_animation("scared")
if(!scared_playing):
scared_playing = true
$ScaredSound.playing = true
if(has_finished_waiting()):
advance_waypoint_sequence()
else:
var current_waypoint = current_waypoint_sequence.get_waypoints()[current_waypoint_index]
if(is_lit()):
move_to_waypoint(delta, current_waypoint)
play_or_continue_animation("walk")
scared_playing = false
$ScaredSound.playing = false
if(!walk_playing):
$WalkSound.playing = true
walk_playing = true
else:
play_or_continue_animation("scared")
$WalkSound.playing = false
walk_playing = false
if(!scared_playing):
scared_playing = true
$ScaredSound.playing = true
if(has_reached_waypoint(current_waypoint)):
current_waypoint_index += 1
if(current_waypoint_index >= current_waypoint_sequence.get_waypoints().size()):
advance_waypoint_sequence()
func respawn():
$DeathSound.play()
$Sprite.visible = false
$Particles2D.emitting = true
current_waypoint_index = last_respawn_point.saved_waypoint_index
current_waypoint_sequence = last_respawn_point.saved_waypoint_sequence
waypoint_sequence_count = last_respawn_point.saved_waypoint_sequence_count
yield(get_tree().create_timer(2.0), "timeout")
$Sprite.visible = true
global_position = current_waypoint_sequence.get_waypoints()[current_waypoint_index]
var orby = get_tree().get_nodes_in_group("orby")[0]
orby.respawn_to($OrbyRespawnPosition.global_position)
func _physics_process(delta):
if(not diamond):
navigate_waypoint_sequence(delta)
func play_or_continue_animation(animation: String):
if(animation_player.current_animation != animation):
animation_player.play(animation)