spawns all entities

connected chests to color/ui
This commit is contained in:
2024-02-12 08:07:42 -06:00
parent 8aaedae7c3
commit 6f1d578ee1
23 changed files with 554 additions and 7 deletions

30
scripts/maze.gd Normal file
View File

@@ -0,0 +1,30 @@
extends Node2D
class_name Maze
const PLAYER = preload("res://scene/player.tscn")
const ENEMY = preload("res://scene/enemy.tscn")
var spawn_locations: Array[Vector2] = []
@onready var hud: HUD = $HUD
@onready var spawn_zones: Node2D = $SpawnZones
func _ready() -> void:
var spawn_zone_array := spawn_zones.get_children()
for spawn_zone in spawn_zone_array:
var zone := spawn_zone.get_child(0) as CollisionShape2D
var top_left = zone.transform.get_origin() - Vector2(24, 24)
for x in range(zone.shape.size.x / 16):
for y in range(zone.shape.size.y / 16):
spawn_locations.append(top_left + Vector2(x * 16, y * 16))
var player_loc: Vector2 = spawn_locations.pick_random()
for spawn in spawn_locations:
var entity
if spawn == player_loc:
entity = PLAYER.instantiate()
entity.color_changed.connect(hud._on_player_color_changed)
entity.lives_changed.connect(hud._on_player_lives_changed)
else:
entity = ENEMY.instantiate()
entity.position = spawn
add_child(entity)