wild jam prototype

This commit is contained in:
2024-02-24 08:35:47 -06:00
parent e6d1f5a8df
commit bd0e9e21cd
28 changed files with 606 additions and 19 deletions

View File

@@ -3,6 +3,8 @@ class_name Maze
const PLAYER = preload("res://scene/player.tscn")
const ENEMY = preload("res://scene/enemy.tscn")
const ROCKET = preload("res://scene/rocket.tscn")
const MAIN_MENU = "res://scene/main_menu.tscn"
var spawn_locations: Array[Vector2] = []
@@ -11,6 +13,7 @@ var spawn_locations: Array[Vector2] = []
@onready var entity_container: Node = $EntityContainer
func _ready() -> void:
HasWon.inital_load = false
var spawn_zone_array := spawn_zones.get_children()
for spawn_zone in spawn_zone_array:
var zone := spawn_zone.get_child(0) as CollisionShape2D
@@ -20,18 +23,40 @@ func _ready() -> void:
spawn_locations.append(top_left + Vector2(x * 16, y * 16))
hud.update_entity_count(spawn_locations.size())
var player_loc: Vector2 = spawn_locations.pick_random()
var alliegences: Array[Buff.colors] = []
for spawn in spawn_locations:
var entity
var entity: Entity
if spawn == player_loc:
entity = PLAYER.instantiate()
entity.alliance = get_random_alliance(alliegences)
hud.set_alliance(entity.alliance)
entity.color_changed.connect(hud._on_player_color_changed)
entity.lives_changed.connect(hud._on_player_lives_changed)
else:
entity = ENEMY.instantiate()
entity.alliance = get_random_alliance(alliegences)
entity.position = spawn
entity.death.connect(_on_entity_death)
entity_container.add_child(entity)
func _on_entity_death():
var entities = entity_container.get_child_count()
func get_random_alliance(alliegences: Array[Buff.colors]) -> Buff.colors:
if alliegences.size() == 0:
alliegences.append_array([Buff.colors.RED, Buff.colors.GREEN, Buff.colors.BLUE])
return alliegences.pop_at(randi_range(0, alliegences.size() - 1))
func _on_entity_death(entity: Entity):
var entities = entity_container.get_child_count() - 1
hud.update_entity_count(entities)
entity.queue_free()
func _on_rocket_timer_timeout() -> void:
var rocket_location: Node2D = spawn_zones.get_children().pick_random().get_child(0)
var rocket = ROCKET.instantiate()
rocket.global_position = rocket_location.global_position
rocket.game_over.connect(_on_game_over)
add_child(rocket)
hud.rocket_placed()
func _on_game_over() -> void:
get_tree().change_scene_to_file(MAIN_MENU)