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,7 @@ class_name Attack
@onready var cpu_particles_2d: CPUParticles2D = $CPUParticles2D
@onready var area_2d: Area2D = $Area2D
@onready var collision_shape_2d: CollisionShape2D = $Area2D/CollisionShape2D
var initiator: Entity
@@ -13,11 +14,15 @@ func set_initiator(entity: Entity) -> void:
func _ready() -> void:
cpu_particles_2d.emitting = true
cpu_particles_2d.color = initiator.color
collision_shape_2d.shape.radius = initiator.attack_pow
cpu_particles_2d.initial_velocity_min = float(initiator.attack_pow) * 4.0
cpu_particles_2d.initial_velocity_max = float(initiator.attack_pow) * 4.0
func _on_cpu_particles_2d_finished() -> void:
var collisions := area_2d.get_overlapping_bodies()
for object in collisions:
if object is Entity and object != initiator:
object.hit()
print("attack hit %s" % collisions.size())
var color_diff = object.color - initiator.color
if abs(color_diff.r) + abs(color_diff.g) + abs(color_diff.b) > 0.5:
object.hit()
queue_free()

View File

@@ -5,8 +5,13 @@ class_name Enemy
@onready var nav_agent: NavigationAgent2D = $NavigationAgent2D
var vision: int = 100
var at_rocket := false
func _physics_process(delta: float) -> void:
if not at_rocket:
random_movement()
func random_movement():
if nav_agent.is_navigation_finished():
call_deferred("new_target_point")
return
@@ -26,7 +31,7 @@ func _physics_process(delta: float) -> void:
lives += 1
color.r -= 0.25
buff.colors.GREEN:
#$Camera2D.zoom -= Vector2(0.4, 0.4)
vision += 25
color.g -= 0.25
buff.colors.BLUE:
speed += 12
@@ -48,3 +53,6 @@ func new_target_point():
#point_delta = point_delta.normalized()
#closest_point += point_delta * 32
nav_agent.target_position = closest_point
func reach_rocket():
at_rocket = true

View File

@@ -1,14 +1,21 @@
extends CharacterBody2D
class_name Entity
signal death
signal death(entity: Entity)
var alliance: Buff.colors
var attack_pow: int = 0
var color := Color.WHITE
@export var speed = 100
@export var speed = 80
var lives: int = 1
func received_buff(color: Buff.colors) -> void:
if alliance == color:
attack_pow += 6
else:
attack_pow -= 3
func hit() -> void:
lives -= 1
if lives <= 0:
death.emit()
queue_free()
death.emit(self)

5
scripts/has_won.gd Normal file
View File

@@ -0,0 +1,5 @@
extends Node
var won := false
var inital_load := true
var escaped = {}

View File

@@ -7,6 +7,8 @@ class_name HUD
@onready var texture_rect: TextureRect = $PanelContainer/MarginContainer/VBoxContainer/TextureRect
@onready var lives_container: GridContainer = $PanelContainer/MarginContainer/VBoxContainer/LivesContainer
@onready var entity_count_label: Label = $EntityCountContainer/MarginContainer/EntityCountLabel
@onready var rocket_spawned_toast: PanelContainer = $RocketSpawnedToast
@onready var alliance_texture: TextureRect = $PanelContainer/MarginContainer/VBoxContainer/AllianceContainer/MarginContainer/AllianceTexture
const HEART = preload("res://assets/heart.png")
func _on_player_color_changed(color: Color) -> void:
@@ -27,3 +29,19 @@ func _on_player_lives_changed(lives: int) -> void:
func update_entity_count(count: int):
entity_count_label.text = "Entity Count: %s" % count
func rocket_placed() -> void:
rocket_spawned_toast.show()
rocket_spawned_toast.get_node("Timer").start()
func _on_timer_timeout() -> void:
rocket_spawned_toast.hide()
func set_alliance(alliance: Buff.colors) -> void:
match alliance:
Buff.colors.RED:
alliance_texture.modulate = Color.RED
Buff.colors.GREEN:
alliance_texture.modulate = Color.GREEN
Buff.colors.BLUE:
alliance_texture.modulate = Color.BLUE

19
scripts/main_menu.gd Normal file
View File

@@ -0,0 +1,19 @@
extends Control
class_name MainMenu
var mazes = ["res://scene/maze_1.tscn"]
@onready var win_loss_label: Label = $HBoxContainer/MarginContainer/VBoxContainer/WinLossLabel
func _on_quit_button_pressed() -> void:
get_tree().quit()
func _on_play_button_pressed() -> void:
get_tree().change_scene_to_file(mazes.pick_random())
func _ready() -> void:
if not HasWon.inital_load:
var won_text = ["YOU WON!!!" if HasWon.won else "You Lost..."]
won_text.append_array(HasWon.escaped.values())
win_loss_label.text = "%s Escaped counts: %s Red, %s Green, %s Blue" % won_text

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)

View File

@@ -18,6 +18,7 @@ func _physics_process(delta: float) -> void:
if collision.get_collider() is Chest:
var buff: Buff = collision.get_collider().open(self)
if buff:
super.received_buff(buff.color)
match(buff.color):
buff.colors.RED:
lives += 1
@@ -33,6 +34,7 @@ func _physics_process(delta: float) -> void:
color_changed.emit(color)
if Input.is_action_just_pressed("ui_accept"):
var attack: Attack = ATTACK.instantiate()
attack.set_initiator(self)
get_parent().add_sibling(attack)
if attack_pow > 0:
var attack: Attack = ATTACK.instantiate()
attack.set_initiator(self)
get_parent().add_sibling(attack)

41
scripts/rocket.gd Normal file
View File

@@ -0,0 +1,41 @@
extends Node2D
signal game_over
@onready var leave_timer: Timer = $LeaveTimer
@onready var collection_zone: Area2D = $CollectionZone
@onready var countdown_label: Label = $CountdownLabel
var countdown = 5
var count = -1
func _on_collection_zone_body_entered(body: Node2D) -> void:
leave_timer.start()
count = countdown
countdown_label.text = str(count)
countdown_label.show()
if body is Enemy:
body.reach_rocket()
func _on_collection_zone_body_exited(body: Node2D) -> void:
if collection_zone.get_overlapping_bodies().size() == 0:
leave_timer.stop()
countdown_label.hide()
func _on_leave_timer_timeout() -> void:
count -= 1
countdown_label.text = str(count)
if count == 0:
for clr in Buff.colors:
HasWon.escaped[clr] = 0
var escaped: Array[Node2D] = collection_zone.get_overlapping_bodies()
HasWon.won = false
for entity: Entity in escaped:
HasWon.escaped[Buff.colors.keys()[entity.alliance]] += 1
if entity is Player:
HasWon.won = true
game_over.emit()