semi-idle-arpg/scripts/test_scroll_scene.gd
2024-10-18 16:17:39 -06:00

117 lines
3.2 KiB
GDScript

# TODO: convert to just combat UI, instancing appropriate zone/area
extends Control
@export var debug = false
@export var spawnTimerValue = 5.0
var deltaCount := 0
var enemyMoveSpeed := 5.0
# var questComplete := false
var canContinue := false
var middleX
var playerPos
func _ready() -> void:
if debug:
%DebugMenu.show()
Engine.time_scale = 3.0
SignalBus.quest_completed.connect(_on_quest_completed)
SignalBus.enemy_damaged_player.connect(_on_enemy_damaged_player)
_generate_quest()
middleX = get_viewport_rect().size.x / 2
playerPos = Vector2(middleX, get_viewport_rect().size.y * (0.75))
_set_player_display()
$SpawnTimer.start(spawnTimerValue)
_spawn_enemies(1)
# _spawn_enemies(5)
func _process(_delta: float) -> void:
deltaCount += 1
playerPos = Vector2(middleX, get_viewport_rect().size.y * (0.75))
func _generate_quest() -> void:
var quest = load("res://scenes/quest.tscn").instantiate()
%QuestsContainer.add_child(quest)
func _create_enemy():
var enemy = load("res://scenes/enemy.tscn").instantiate()
enemy.scale = Vector2.ONE * 0.5
enemy.position = Vector2(randi_range(0, get_viewport_rect().size.x), -50)
enemy.speed *= randf_range(0.67, 1.5)
enemy.target = playerPos
return enemy
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)
func _spawn_enemies(numEnemies: int) -> void:
#await get_tree().create_timer(time).timeout
# var numEnemies = randi_range(1, maxEnemies)
for i in range(numEnemies):
var enemy = _create_enemy()
%WorldArea.add_child(enemy)
# var randEnemyMoveSpeed := randf_range(0.5, 2.0)*enemyMoveSpeed
# create_tween().tween_property(enemy, "position", playerPos, randEnemyMoveSpeed)
func _on_button_test_pressed() -> void:
%DebugMenu/ButtonTest.text = "pass"
pass
func _on_button_exit_pressed() -> void:
get_tree().quit()
func _on_spawn_timer_timeout() -> void:
_spawn_enemies(1)
func _get_player_current_health() -> void:
var playerCurrHeath = PlayerState.player_currenthealth
%PlayerInfo/PlayerHealthBar/PlayerHealthCurrent.text = str(playerCurrHeath)
%PlayerInfo/PlayerHealthBar.value = playerCurrHeath
if playerCurrHeath <= 0:
get_tree().paused = true
func _set_player_display() -> void:
var playerMaxHeath = PlayerState.player_maxhealth
var playerCurrHeath = PlayerState.player_currenthealth
%PlayerInfo/PlayerHealthBar/PlayerHealthMax.text = str(playerMaxHeath)
%PlayerInfo/PlayerHealthBar/PlayerHealthCurrent.text = str(playerCurrHeath)
%PlayerInfo/PlayerHealthBar.value = playerCurrHeath
# TODO: move all quest stuff to quest class?
func _on_quest_completed() -> void:
# $SpawnTimer.stop()
# questComplete = true
if _get_enemies().is_empty(): # and questComplete:
canContinue = true
# print("Area Complete!")
# get_tree().quit()
func _on_enemy_damaged_player() -> void:
_get_player_current_health()