Skip to content

Commit 3c6b914

Browse files
authored
Merge pull request #49 from Sparrowworks/documentation
Added documentation
2 parents 926252d + 9203762 commit 3c6b914

File tree

15 files changed

+65
-19
lines changed

15 files changed

+65
-19
lines changed

src/Game/Enemies/Barnacle/barnacle.gd

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,13 +23,17 @@ func collision_check(body: Node2D) -> void:
2323
kill()
2424
return
2525

26+
# The barnacle can only be killed while rising from or lowering to the ground.
2627
if animated_sprite_2d.animation == "open":
2728
player_hit.emit(true)
2829
hide_timer.paused = true
2930
animated_sprite_2d.play("bite")
31+
3032
await animated_sprite_2d.animation_finished
33+
3134
hide_timer.paused = false
3235
animated_sprite_2d.play("open")
36+
3337
elif animated_sprite_2d.animation == "close":
3438
if Globals.player.velocity.y == 0:
3539
player_hit.emit(true)

src/Game/Enemies/Bat/bat.gd

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,8 +18,10 @@ func kill() -> void:
1818
super()
1919

2020
func move(delta: float) -> void:
21+
# Move the bat towards the player when detected
2122
if player_ray.is_colliding():
2223
var collider: Node = player_ray.get_collider() as Node
24+
2325
if ray_collider != collider:
2426
if collider.is_in_group("Player"):
2527
player_tracked.emit()
@@ -30,6 +32,7 @@ func move(delta: float) -> void:
3032
ray_collider = collider
3133
elif player_ray_2.is_colliding():
3234
var collider: Node = player_ray_2.get_collider() as Node
35+
3336
if ray2_collider != collider:
3437
if collider.is_in_group("Player"):
3538
player_tracked.emit()
@@ -64,6 +67,7 @@ func _on_player_tracked() -> void:
6467
if not is_chasing:
6568
is_chasing = true
6669

70+
# Calculate the bat's target position and flight time.
6771
var desired_pos: Vector2 = Vector2(Globals.player.global_position.x, Globals.player.global_position.y)
6872
var fly_time: float = clampf((desired_pos.y - initial_pos.y)/2000, 1, 1.5)
6973
animated_sprite_2d.play("fly")

src/Game/Enemies/Bee/bee.gd

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,7 @@ func _on_player_tracked() -> void:
3434
if not is_chasing:
3535
is_chasing = true
3636

37+
# Calculate the bee's target position and flight time.
3738
var initial_pos: Vector2 = global_position
3839
var desired_pos: Vector2 = Vector2(Globals.player.global_position.x, Globals.player.global_position.y)
3940
var fly_time: float = clampf((desired_pos.y - initial_pos.y)/2000, 1, 1.5)

src/Game/Enemies/Ghost/ghost.gd

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ func _ready() -> void:
44
animated_sprite_2d.play("normal")
55

66
func collision_check(body: Node2D) -> void:
7+
# A ghost is killable only if the player has immunity
78
if body.is_in_group("Player"):
89
if Globals.player.is_immune:
910
player_hit.emit(false)

src/Game/Enemies/Piranha/piranha.gd

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,18 +21,22 @@ func _ready() -> void:
2121
func move(delta: float) -> void:
2222
super(delta)
2323

24+
# Use trigonometric functions to smooth the fish's jump and fall.
2425
if is_jumping:
2526
animated_sprite_2d.play("jump")
2627
time += delta
2728
y_direction = -abs(cos(time) * jump_power)
29+
2830
if abs(y_direction) < 0.2:
2931
y_direction = 0.0
3032
is_jumping = false
3133
is_falling = true
34+
3235
elif is_falling:
3336
animated_sprite_2d.play("fall")
3437
time += delta
3538
y_direction = abs(cos(time) * jump_power * 2)
39+
3640
if global_position.y - init_pos.y > -1.0:
3741
collision_shape_2d.set_deferred("disabled", true)
3842
y_direction = 0.0

src/Game/Enemies/Spider/spider.gd

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,12 +12,11 @@ func kill() -> void:
1212
animated_sprite_2d.play("dead")
1313
super()
1414

15-
15+
# Speeden up the spider if its tracking the player
1616
func _on_player_tracked() -> void:
1717
actual_speed = chase_speed
1818
animated_sprite_2d.speed_scale = 2
1919

20-
2120
func _on_player_tracked_stopped() -> void:
2221
actual_speed = speed
2322
animated_sprite_2d.speed_scale = 1

src/Game/Enemies/Spinner/spinner.gd

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,7 @@ func turn_left() -> void:
3737
animated_sprite_2d.flip_h = false
3838

3939
func move(delta: float) -> void:
40+
# Change the direction of the enemy if reached a wall
4041
if wall_ray.is_colliding():
4142
var collider: Node = wall_ray.get_collider() as Node2D
4243
if not collider.is_in_group("Player"):
@@ -45,6 +46,7 @@ func move(delta: float) -> void:
4546
else:
4647
turn_right()
4748

49+
# Code for player raycast used to check if an enemy spotted the player
4850
if player_ray.is_colliding():
4951
var collider: Node = player_ray.get_collider() as Node
5052
if ray_collider != collider:
@@ -81,6 +83,7 @@ func collision_check(body: Node2D) -> void:
8183
else:
8284
player_hit.emit(true)
8385

86+
# Make the spinner jump with the player when its tracking them
8487
func _physics_process(delta: float) -> void:
8588
if ray_collider != null:
8689
if ray_collider.is_in_group("Player"):
@@ -89,6 +92,7 @@ func _physics_process(delta: float) -> void:
8992

9093
move(delta)
9194

95+
# Speeden up the spinner if its tracking the player
9296
func _on_player_tracked() -> void:
9397
actual_speed = chase_speed
9498
animated_sprite_2d.speed_scale = 2
@@ -97,6 +101,5 @@ func _on_player_tracked_stopped() -> void:
97101
actual_speed = speed
98102
animated_sprite_2d.speed_scale = 1
99103

100-
101104
func _on_hit_box_body_entered(body: Node2D) -> void:
102105
collision_check(body)

src/Game/Enemies/enemy.gd

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,12 +31,14 @@ func turn_left() -> void:
3131
player_ray.rotation = deg_to_rad(0)
3232

3333
func move(delta: float) -> void:
34+
# Change the direction of the enemy if trying to move off a platform or a cliff
3435
if not left_ray.is_colliding():
3536
turn_right()
3637

3738
if not right_ray.is_colliding():
3839
turn_left()
3940

41+
# Code for player raycast used to check if an enemy spotted the player
4042
if player_ray.is_colliding():
4143
var collider: Node = player_ray.get_collider() as Node
4244
if ray_collider != collider:
@@ -62,14 +64,17 @@ func kill() -> void:
6264

6365
func collision_check(area: Area2D) -> void:
6466
if area.is_in_group("Player"):
67+
# Kill the enemy by default if a player has immunity
6568
if Globals.player.is_immune:
6669
player_hit.emit(false)
6770
kill()
6871
return
6972

73+
# If a player isn't jumping, hurt them
7074
if Globals.player.velocity.y == 0:
7175
player_hit.emit(true)
7276
else:
77+
# If a player's position is higher than the enemy's, kill the enemy, else hurt the player
7378
if Globals.player.feet_pos.global_position.y >= top_pos.global_position.y:
7479
player_hit.emit(true)
7580
else:
@@ -84,6 +89,7 @@ func _on_area_entered(area: Area2D) -> void:
8489
collision_check(area)
8590

8691
func _on_body_entered(body: Node2D) -> void:
92+
# Change the direction if an enemy hit something (that is not the player)
8793
if not body.is_in_group("Player"):
8894
if direction == Vector2.RIGHT:
8995
turn_left()

src/Game/Level/level.gd

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,8 +8,10 @@ signal level_end()
88
@export var level_time: int = 200
99

1010
func _ready() -> void:
11+
# Calculate the camera limit of the level (so that the player doesn't see beyond the boundaries)
1112
player.camera_limit_x = (tiles.get_used_rect().size.x * 128) - 128
1213

14+
# Connect all signals of objects in the level to player
1315
for pickup: Pickup in get_tree().get_nodes_in_group("PickupInternal"):
1416
pickup.pickup_collected.connect(player._on_pickup_collected)
1517

src/Game/Objects/LevelEnd/level_end.gd

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ func _on_body_entered(body: Node2D) -> void:
99
if not body.is_in_group("Player"):
1010
return
1111

12+
# Signal the end of the level when crossed by the player
1213
end_reached.emit()
1314

1415
collision_shape_2d.set_deferred("disabled", true)

0 commit comments

Comments
 (0)