summaryrefslogtreecommitdiff
path: root/src/entities/actors/snake/scripts/head.gd
diff options
context:
space:
mode:
Diffstat (limited to 'src/entities/actors/snake/scripts/head.gd')
-rw-r--r--src/entities/actors/snake/scripts/head.gd13
1 files changed, 13 insertions, 0 deletions
diff --git a/src/entities/actors/snake/scripts/head.gd b/src/entities/actors/snake/scripts/head.gd
index 32847f7..8747910 100644
--- a/src/entities/actors/snake/scripts/head.gd
+++ b/src/entities/actors/snake/scripts/head.gd
@@ -28,6 +28,19 @@ func _physics_process(delta: float) -> void:
# not sure if needed, worked wonders when using a Node2D instead of KB2D
velocity = move_and_slide(velocity)
+
+ # slow down on collisions, so it isn't as unfair
+ if get_last_slide_collision():
+ var speed: float = velocity.length()
+ Global.SNAKE_SPEED = speed
+ else:
+ Global.SNAKE_SPEED = Global.SNAKE_SPEED_BACKUP
+
+ # handle slow speeds
+ if Global.SNAKE_SPEED <= Global.SNAKE_SPEED_BACKUP / 4.0:
+ Global.SNAKE_SPEED = Global.SNAKE_SPEED_BACKUP
+ Event.emit_signal("game_over")
+
_handle_time_elapsed(delta)