summaryrefslogtreecommitdiff
path: root/src/entities/actors
diff options
context:
space:
mode:
Diffstat (limited to 'src/entities/actors')
-rw-r--r--src/entities/actors/snake/scripts/snake.gd24
1 files changed, 15 insertions, 9 deletions
diff --git a/src/entities/actors/snake/scripts/snake.gd b/src/entities/actors/snake/scripts/snake.gd
index 01e09da..91e4e39 100644
--- a/src/entities/actors/snake/scripts/snake.gd
+++ b/src/entities/actors/snake/scripts/snake.gd
@@ -6,8 +6,8 @@ export(PackedScene) var TAIL_SEGMENT_NP: PackedScene
onready var path: Path2D = $Path
+var finished_adding_initial_segments: bool = false
var current_body_segments: int = 0
-var max_body_initial_segments: int = 1
var body_segment_stack: Array
var tail_segment: PathFollow2D
# didn't konw how to name this, basically holds the current path lenght
@@ -20,16 +20,17 @@ func _ready():
set_physics_process(false)
set_process_input(false)
Event.connect("snake_path_new_point", self, "_on_snake_path_new_point")
+ Event.connect("snake_add_new_segment", self, "_on_snake_add_new_segment")
Event.connect("snake_added_new_segment", self, "_on_snake_added_new_segment")
Event.connect("snake_added_initial_segments", self, "_on_snake_added_initial_segments")
- Event.connect("food_eaten", self, "_on_food_eaten")
+ # Event.connect("food_eaten", self, "_on_food_eaten")
# need to always set a new curve when ready, so when restarting it's af resh curve
path.curve = Curve2D.new()
func _physics_process(delta: float) -> void:
- if body_segment_queue.size() != 0 and current_body_segments > max_body_initial_segments:
+ if body_segment_queue.size() != 0 and current_body_segments >= Global.SNAKE_INITIAL_SEGMENTS:
_add_new_segment()
# if body_segment_stack.size() > 0:
@@ -75,6 +76,7 @@ func _add_initial_segment(type: PackedScene) -> void:
tail_segment = _temp_body_segment
path.add_child(_temp_body_segment)
+ # just to keep things going, tail shouldn't count as body segment
current_body_segments += 1
Event.emit_signal("snake_added_new_segment", _temp_body_segment.TYPE)
@@ -93,14 +95,17 @@ func _on_snake_path_new_point(coordinates: Vector2) -> void:
# update call is to draw curve as there are new points to the path's curve
# update()
- if current_body_segments < max_body_initial_segments:
- _add_initial_segment(BODY_SEGMENT_NP)
- elif current_body_segments == max_body_initial_segments:
- _add_initial_segment(TAIL_SEGMENT_NP)
+ if not finished_adding_initial_segments:
+ if current_body_segments < Global.SNAKE_INITIAL_SEGMENTS:
+ _add_initial_segment(BODY_SEGMENT_NP)
+ elif current_body_segments == Global.SNAKE_INITIAL_SEGMENTS:
+ _add_initial_segment(TAIL_SEGMENT_NP)
func _on_snake_added_new_segment(type: String) -> void:
if type == "tail":
+ current_body_segments -= 1
+ finished_adding_initial_segments = true
Event.emit_signal("snake_added_initial_segments")
@@ -109,5 +114,6 @@ func _on_snake_added_initial_segments() -> void:
set_process_input(true)
-func _on_food_eaten(type: int, location: Vector2) -> void:
- _add_segment_to_queue()
+func _on_snake_add_new_segment(amount: int) -> void:
+ for i in amount:
+ _add_segment_to_queue()