cooking again

This commit is contained in:
Tabby 2025-09-02 23:17:10 +10:00
parent b0b210a8be
commit dafae35985
14 changed files with 218 additions and 10 deletions

View file

@ -5,10 +5,16 @@ var segements : Array[snake_segment]
@export var SNAKE_SPEED : float = 0.2
@export var snake_line : Line2D
@export var player : Node2D
var food : float = 5
@export var max_food = 5
@export var food_drain = 0.1
var pit_apples : int = 0
# Called when the node enters the scene tree for the first time.
func _ready() -> void:
Router.activate_seg.connect(activate_segment)
Router.eat_apple.connect(rec_apple)
food = max_food
#segements = get_children() as Array[snake_segment]
segements.assign(segements_holder.get_children())
for i in segements.size():
@ -28,6 +34,13 @@ func _ready() -> void:
# Called every frame. 'delta' is the elapsed time since the previous frame.
func _process(delta: float) -> void:
redraw_line()
if(Input.is_action_just_pressed("test_add_segment")):
add_segment()
if food > max_food:
food = max_food
food -= food_drain * delta
pass
func activate_segment(act_segment : int):
@ -47,3 +60,21 @@ func redraw_line():
snake_line.clear_points()
for segment in segements:
snake_line.add_point(segment.global_position)
func add_segment():
var new_segement : Node2D = load("res://prefabs/snake_segment.tscn").instantiate()
new_segement.global_position = segements[-1].global_position
new_segement.next_segment = segements[-1]
new_segement.door_disabled = true
segements.append(new_segement)
segements_holder.add_child(new_segement)
pass
func rec_apple():
#food += 1
pit_apples += 1
SNAKE_SPEED += 0.1
add_segment()
for seg in segements:
seg.snake_speed = SNAKE_SPEED