2024-10-18 11:25:29 -06:00
|
|
|
# TODO: convert to just combat UI, instancing appropriate zone
|
2024-10-08 20:51:11 -06:00
|
|
|
extends Control
|
|
|
|
|
|
|
|
|
|
|
|
@export var debug = false
|
|
|
|
@export var spawnTimerValue = 5.0
|
|
|
|
|
|
|
|
var deltaCount := 0
|
|
|
|
var enemyMoveSpeed := 5.0
|
2024-10-17 16:50:40 -06:00
|
|
|
var questComplete := false
|
2024-10-08 20:51:11 -06:00
|
|
|
|
2024-10-09 20:55:46 -06:00
|
|
|
var middleX
|
|
|
|
var playerPos
|
|
|
|
|
2024-10-08 20:51:11 -06:00
|
|
|
|
|
|
|
func _ready() -> void:
|
2024-10-18 09:11:15 -06:00
|
|
|
if debug:
|
|
|
|
$MarginContainer/UIBottom/UIBottomCenter/MenuButtons/DebugMenu.show()
|
|
|
|
Engine.time_scale = 3.0
|
2024-10-17 16:50:40 -06:00
|
|
|
|
|
|
|
SignalBus.quest_completed.connect(_on_quest_completed)
|
|
|
|
|
|
|
|
middleX = get_viewport_rect().size.x / 2
|
|
|
|
playerPos = Vector2(middleX, get_viewport_rect().size.y * (0.75))
|
|
|
|
|
2024-10-09 20:55:46 -06:00
|
|
|
$SpawnTimer.start(spawnTimerValue)
|
2024-10-15 16:35:03 -06:00
|
|
|
_spawn_enemies(1)
|
|
|
|
# _spawn_enemies(5)
|
2024-10-15 15:04:40 -06:00
|
|
|
|
|
|
|
|
2024-10-17 16:50:40 -06:00
|
|
|
func _process(_delta: float) -> void:
|
2024-10-18 09:11:15 -06:00
|
|
|
deltaCount += 1
|
2024-10-15 16:35:03 -06:00
|
|
|
playerPos = Vector2(middleX, get_viewport_rect().size.y * (0.75))
|
2024-10-17 16:50:40 -06:00
|
|
|
if _get_enemies().is_empty() and questComplete:
|
|
|
|
print("Area Complete!")
|
|
|
|
get_tree().quit()
|
2024-10-15 15:04:40 -06:00
|
|
|
|
2024-10-08 20:51:11 -06:00
|
|
|
|
|
|
|
func _create_enemy():
|
2024-10-15 08:14:02 -06:00
|
|
|
var enemy = load("res://scenes/enemy.tscn").instantiate()
|
2024-10-15 16:35:03 -06:00
|
|
|
enemy.scale = Vector2.ONE * 0.5
|
2024-10-08 20:51:11 -06:00
|
|
|
enemy.position = Vector2(randi_range(0, get_viewport_rect().size.x), -50)
|
2024-10-15 15:04:40 -06:00
|
|
|
enemy.speed *= randf_range(0.5, 2.0)
|
|
|
|
enemy.target = playerPos
|
2024-10-08 20:51:11 -06:00
|
|
|
|
|
|
|
return enemy
|
2024-10-09 20:55:46 -06:00
|
|
|
|
|
|
|
func _get_enemies() -> Array:
|
|
|
|
var enemies := get_tree().get_nodes_in_group("enemies")
|
|
|
|
return enemies
|
|
|
|
|
|
|
|
|
|
|
|
func _get_num_enemies() -> int:
|
|
|
|
var enemies := get_tree().get_nodes_in_group("enemies")
|
|
|
|
return len(enemies)
|
|
|
|
|
|
|
|
|
2024-10-15 16:35:03 -06:00
|
|
|
func _spawn_enemies(numEnemies: int) -> void:
|
2024-10-08 20:51:11 -06:00
|
|
|
#await get_tree().create_timer(time).timeout
|
2024-10-15 16:35:03 -06:00
|
|
|
# var numEnemies = randi_range(1, maxEnemies)
|
2024-10-08 20:51:11 -06:00
|
|
|
for i in range(numEnemies):
|
|
|
|
var enemy = _create_enemy()
|
2024-10-17 16:50:40 -06:00
|
|
|
%WorldArea.add_child(enemy)
|
2024-10-15 15:04:40 -06:00
|
|
|
# var randEnemyMoveSpeed := randf_range(0.5, 2.0)*enemyMoveSpeed
|
|
|
|
# create_tween().tween_property(enemy, "position", playerPos, randEnemyMoveSpeed)
|
2024-10-08 20:51:11 -06:00
|
|
|
|
|
|
|
|
|
|
|
func _on_button_test_pressed() -> void:
|
2024-10-17 16:50:40 -06:00
|
|
|
pass
|
2024-10-08 20:51:11 -06:00
|
|
|
|
|
|
|
|
|
|
|
func _on_button_exit_pressed() -> void:
|
|
|
|
get_tree().quit()
|
|
|
|
|
|
|
|
|
|
|
|
func _on_spawn_timer_timeout() -> void:
|
2024-10-15 16:35:03 -06:00
|
|
|
_spawn_enemies(1)
|
2024-10-17 16:50:40 -06:00
|
|
|
|
|
|
|
|
|
|
|
# TODO: move all quest stuff to quest class
|
|
|
|
func _on_quest_completed() -> void:
|
|
|
|
$SpawnTimer.stop()
|
|
|
|
questComplete = true
|