48 lines
1.5 KiB
GDScript
48 lines
1.5 KiB
GDScript
extends Control
|
|
|
|
@export var food_bar : ProgressBar
|
|
@export var snake_manager : Node2D
|
|
@export var score_label : Label
|
|
@export var speed_label : Label
|
|
@export var gameover_score_label : RichTextLabel
|
|
@export var gameover_screen : MarginContainer
|
|
|
|
|
|
# Called when the node enters the scene tree for the first time.
|
|
func _ready() -> void:
|
|
Router.die.connect(show_gameover)
|
|
pass # Replace with function body.
|
|
|
|
|
|
# Called every frame. 'delta' is the elapsed time since the previous frame.
|
|
func _process(delta: float) -> void:
|
|
food_bar.max_value = snake_manager.max_food
|
|
food_bar.value = snake_manager.food
|
|
score_label.text = str(snake_manager.score)
|
|
gameover_score_label.text = str(snake_manager.score)
|
|
if snake_manager.SNAKE_SPEED < snake_manager.max_snake_speed:
|
|
speed_label.text = str(round(snake_manager.SNAKE_SPEED*100)/100)
|
|
else:
|
|
speed_label.text = str(round(snake_manager.max_snake_speed*100)/100) + " MAX"
|
|
speed_label.label_settings.font_color = Color.RED
|
|
if snake_manager.burn_apples > 0:
|
|
food_bar.modulate = Color.GREEN
|
|
elif food_bar.value < food_bar.max_value*0.3:
|
|
food_bar.modulate = Color.RED
|
|
else:
|
|
food_bar.modulate = Color.WHITE
|
|
|
|
func show_gameover():
|
|
gameover_screen.show()
|
|
|
|
|
|
func _on_again_button_pressed() -> void:
|
|
get_tree().get_root().process_mode = Node.PROCESS_MODE_ALWAYS
|
|
Router.player_mode = false
|
|
get_tree().change_scene_to_file("res://test.tscn")
|
|
|
|
|
|
func _on_menu_button_pressed() -> void:
|
|
get_tree().get_root().process_mode = Node.PROCESS_MODE_ALWAYS
|
|
Router.player_mode = false
|
|
get_tree().change_scene_to_file("res://scenes/menu.tscn")
|