semi-idle-arpg/scripts/test_scroll_scene.gd

73 lines
1.8 KiB
GDScript3
Raw Normal View History

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
var questsComplete := false
var middleX
var playerPos
2024-10-08 20:51:11 -06:00
func _ready() -> void:
middleX = get_viewport_rect().size.x/2
playerPos = Vector2(middleX, get_viewport_rect().size.y*(0.75))
2024-10-08 20:51:11 -06:00
if not debug:
$MarginContainer/Menus/MenuButtons/DebugMenu.hide()
$SpawnTimer.start(spawnTimerValue)
_spawn_enemies(5)
_spawn_enemies(5)
func _process(delta: float) -> void:
playerPos = Vector2(middleX, get_viewport_rect().size.y*(0.75))
if questsComplete:
$SpawnTimer.stop()
if _get_enemies().is_empty():
print("Area Complete!")
get_tree().quit()
2024-10-08 20:51:11 -06:00
func _create_enemy():
var enemy = load("res://scenes/enemy.tscn").instantiate()
2024-10-08 20:51:11 -06:00
enemy.scale = Vector2.ONE*0.5
enemy.position = Vector2(randi_range(0, get_viewport_rect().size.x), -50)
enemy.speed *= randf_range(0.5, 2.0)
enemy.target = playerPos
2024-10-08 20:51:11 -06:00
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(maxEnemies: int) -> void:
2024-10-08 20:51:11 -06:00
#await get_tree().create_timer(time).timeout
var numEnemies = randi_range(1, maxEnemies)
2024-10-08 20:51:11 -06:00
for i in range(numEnemies):
var enemy = _create_enemy()
%SpawnArea.add_child(enemy)
# 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:
questsComplete = true
func _on_button_exit_pressed() -> void:
get_tree().quit()
func _on_spawn_timer_timeout() -> void:
_spawn_enemies(5)