2024-10-05 15:57:40 +00:00
|
|
|
extends Node2D
|
|
|
|
|
|
|
|
const MAX_HEALTH = 100.0
|
|
|
|
const RECOVERY_RATE = 10.0
|
|
|
|
const BAD_PRESS_DAMAGE = 20.0
|
2024-10-06 17:38:16 +00:00
|
|
|
const MAX_ENEMIES = 4
|
2024-10-05 15:57:40 +00:00
|
|
|
|
|
|
|
const INIT_COLOR = Color(1,0,0,0)
|
|
|
|
var health = MAX_HEALTH
|
|
|
|
|
2024-10-06 17:38:16 +00:00
|
|
|
var spawn_interval = 0.8
|
|
|
|
var interval_step = 0.1
|
|
|
|
var max_out = 0.8
|
2024-10-06 12:18:16 +00:00
|
|
|
|
|
|
|
var player_score = 0
|
|
|
|
var first_time = true
|
2024-10-06 17:38:16 +00:00
|
|
|
var game_active = false
|
2024-10-06 12:18:16 +00:00
|
|
|
|
2024-10-05 20:09:04 +00:00
|
|
|
func _unhandled_input(event: InputEvent) -> void:
|
|
|
|
if event.is_action_pressed("ui_accept"):
|
2024-10-06 17:38:16 +00:00
|
|
|
start_game()
|
|
|
|
|
2024-10-05 20:09:04 +00:00
|
|
|
|
|
|
|
func _ready() -> void:
|
2024-10-06 13:57:47 +00:00
|
|
|
$Dialog.start()
|
|
|
|
|
|
|
|
func start_game():
|
2024-10-06 17:38:16 +00:00
|
|
|
game_active = true
|
2024-10-06 13:57:47 +00:00
|
|
|
$SpawnTimer.start()
|
2024-10-05 20:09:04 +00:00
|
|
|
change_red_button()
|
2024-10-06 12:18:16 +00:00
|
|
|
first_time = false
|
|
|
|
$SpawnTimer.wait_time = spawn_interval
|
|
|
|
for button in get_tree().get_nodes_in_group("button_group"):
|
|
|
|
button.enemy_killed.connect(on_enemy_killed)
|
2024-10-05 20:09:04 +00:00
|
|
|
|
2024-10-06 13:57:47 +00:00
|
|
|
|
2024-10-05 15:57:40 +00:00
|
|
|
func _process(delta: float) -> void:
|
|
|
|
health = minf(health + RECOVERY_RATE * delta ,MAX_HEALTH)
|
|
|
|
|
2024-10-06 12:18:16 +00:00
|
|
|
if(spawn_interval > max_out):
|
|
|
|
spawn_interval -= interval_step*delta
|
|
|
|
|
2024-10-05 15:57:40 +00:00
|
|
|
var new_color = Color(INIT_COLOR)
|
|
|
|
new_color.a = 1 - health / MAX_HEALTH
|
|
|
|
%DamageColorOverlay.color = new_color
|
2024-10-05 20:09:04 +00:00
|
|
|
if health < 5:
|
|
|
|
$SpawnTimer.paused =true
|
2024-10-06 17:38:16 +00:00
|
|
|
game_active = false
|
2024-10-05 20:09:04 +00:00
|
|
|
|
2024-10-05 15:57:40 +00:00
|
|
|
func bad_press():
|
|
|
|
health = maxf(health - BAD_PRESS_DAMAGE, 0)
|
2024-10-06 12:18:16 +00:00
|
|
|
spawn_interval -= interval_step
|
2024-10-06 17:38:16 +00:00
|
|
|
$Camera2D.apply_shake()
|
2024-10-06 12:18:16 +00:00
|
|
|
|
|
|
|
func ate():
|
|
|
|
health = maxf(health - BAD_PRESS_DAMAGE, 0)
|
|
|
|
spawn_interval += interval_step
|
2024-10-06 17:38:16 +00:00
|
|
|
$Camera2D.apply_shake()
|
2024-10-05 20:09:04 +00:00
|
|
|
|
|
|
|
func red_button_press():
|
|
|
|
health = 0
|
|
|
|
|
|
|
|
func change_red_button():
|
|
|
|
var buttons = get_tree().get_nodes_in_group("button_group")
|
2024-10-06 12:18:16 +00:00
|
|
|
var old_red_button_index = -1
|
2024-10-05 20:09:04 +00:00
|
|
|
if buttons.filter(func (n: Node): return n.red_button).size() > 0:
|
|
|
|
var old_red_button = buttons.filter(func (n: Node): return n.red_button)[0]
|
2024-10-06 12:18:16 +00:00
|
|
|
old_red_button_index = buttons.find(old_red_button)
|
2024-10-05 20:09:04 +00:00
|
|
|
var r = randi_range(0, buttons.size()-1)
|
|
|
|
|
2024-10-06 12:18:16 +00:00
|
|
|
while (r == old_red_button_index || buttons[r].get_has_enemy()):
|
2024-10-05 20:09:04 +00:00
|
|
|
r= randi_range(0, buttons.size()-1)
|
2024-10-06 12:18:16 +00:00
|
|
|
if(!first_time):
|
|
|
|
buttons[old_red_button_index].red_out()
|
|
|
|
buttons[r].red_in()
|
|
|
|
else:
|
|
|
|
buttons[r].set_red_button(true)
|
|
|
|
|
|
|
|
|
|
|
|
|
2024-10-05 20:09:04 +00:00
|
|
|
|
|
|
|
func _on_spawn_timer_timeout() -> void:
|
2024-10-06 12:18:16 +00:00
|
|
|
$SpawnTimer.wait_time = spawn_interval
|
2024-10-05 20:09:04 +00:00
|
|
|
var buttons = get_tree().get_nodes_in_group("button_group")
|
|
|
|
var enemies_to_spawn = randi_range(1, MAX_ENEMIES)
|
|
|
|
while (enemies_to_spawn > 0):
|
|
|
|
var button = buttons[randi_range(0, buttons.size()-1)]
|
|
|
|
if button.has_method("get_has_enemy"):
|
|
|
|
if button.get_has_enemy():
|
|
|
|
enemies_to_spawn -=1
|
|
|
|
continue
|
|
|
|
button.spawn_enemy()
|
|
|
|
enemies_to_spawn -=1
|
|
|
|
return
|
2024-10-06 12:18:16 +00:00
|
|
|
func on_enemy_killed():
|
|
|
|
player_score+=1
|
2024-10-06 17:38:16 +00:00
|
|
|
$CanvasLayer/Label.text = str(player_score)
|
2024-10-06 13:57:47 +00:00
|
|
|
|
|
|
|
|
|
|
|
func _on_dialog_dialogue_over() -> void:
|
|
|
|
start_game()
|