spawns all entities
connected chests to color/ui
This commit is contained in:
11
scripts/buff.gd
Normal file
11
scripts/buff.gd
Normal file
@@ -0,0 +1,11 @@
|
||||
extends Resource
|
||||
class_name Buff
|
||||
|
||||
enum colors {
|
||||
RED,
|
||||
GREEN,
|
||||
BLUE
|
||||
}
|
||||
|
||||
@export var image: Texture2D
|
||||
@export var color: colors
|
||||
@@ -1 +1,20 @@
|
||||
extends StaticBody2D
|
||||
class_name Chest
|
||||
|
||||
@export var buff: Buff
|
||||
|
||||
const CHEST_OPENED = preload("res://assets/chest_opened.png")
|
||||
var recipients = []
|
||||
var opened := false
|
||||
|
||||
func open(entity) -> Buff:
|
||||
if not recipients.has(entity):
|
||||
if not opened:
|
||||
opened = true
|
||||
$Sprite2D.texture = CHEST_OPENED
|
||||
var buff_texture := Sprite2D.new()
|
||||
buff_texture.texture = buff.image
|
||||
add_child(buff_texture)
|
||||
recipients.append(entity)
|
||||
return buff
|
||||
return null
|
||||
|
||||
37
scripts/enemy.gd
Normal file
37
scripts/enemy.gd
Normal file
@@ -0,0 +1,37 @@
|
||||
extends CharacterBody2D
|
||||
class_name Enemy
|
||||
|
||||
@onready var sprite_2d: Sprite2D = $Sprite2D
|
||||
|
||||
var color := Color.WHITE
|
||||
@export var speed = 100
|
||||
var lives: int = 1
|
||||
|
||||
func _physics_process(delta: float) -> void:
|
||||
velocity = Vector2.ZERO
|
||||
if Input.is_action_pressed("ui_down"):
|
||||
velocity += Vector2.DOWN
|
||||
if Input.is_action_pressed("ui_up"):
|
||||
velocity += Vector2.UP
|
||||
if Input.is_action_pressed("ui_left"):
|
||||
velocity += Vector2.LEFT
|
||||
if Input.is_action_pressed("ui_right"):
|
||||
velocity += Vector2.RIGHT
|
||||
velocity = velocity.normalized() * speed
|
||||
move_and_slide()
|
||||
for i in range(get_slide_collision_count()):
|
||||
var collision := get_slide_collision(i)
|
||||
if collision.get_collider() is Chest:
|
||||
var buff: Buff = collision.get_collider().open(self)
|
||||
if buff:
|
||||
match(buff.color):
|
||||
buff.colors.RED:
|
||||
lives += 1
|
||||
color.r -= 0.25
|
||||
buff.colors.GREEN:
|
||||
#$Camera2D.zoom -= Vector2(0.4, 0.4)
|
||||
color.g -= 0.25
|
||||
buff.colors.BLUE:
|
||||
speed += 12
|
||||
color.b -= 0.25
|
||||
sprite_2d.modulate = color
|
||||
25
scripts/hud.gd
Normal file
25
scripts/hud.gd
Normal file
@@ -0,0 +1,25 @@
|
||||
extends CanvasLayer
|
||||
class_name HUD
|
||||
|
||||
@onready var progress_bar_red: ProgressBar = $PanelContainer/MarginContainer/VBoxContainer/HBoxContainer/PanelContainerRed/ProgressBar
|
||||
@onready var progress_bar_green: ProgressBar = $PanelContainer/MarginContainer/VBoxContainer/HBoxContainer/PanelContainerGreen/ProgressBar
|
||||
@onready var progress_bar_blue: ProgressBar = $PanelContainer/MarginContainer/VBoxContainer/HBoxContainer/PanelContainerBlue/ProgressBar
|
||||
@onready var texture_rect: TextureRect = $PanelContainer/MarginContainer/VBoxContainer/TextureRect
|
||||
@onready var lives_container: GridContainer = $PanelContainer/MarginContainer/VBoxContainer/LivesContainer
|
||||
const HEART = preload("res://assets/heart.png")
|
||||
|
||||
func _on_player_color_changed(color: Color) -> void:
|
||||
progress_bar_red.value = color.r
|
||||
progress_bar_green.value = color.g
|
||||
progress_bar_blue.value = color.b
|
||||
texture_rect.modulate = color
|
||||
|
||||
|
||||
func _on_player_lives_changed(lives: int) -> void:
|
||||
var heart_containers = lives_container.get_children()
|
||||
if heart_containers.size() < lives:
|
||||
var life = TextureRect.new()
|
||||
life.texture = HEART
|
||||
lives_container.add_child(life)
|
||||
elif heart_containers.size() > lives:
|
||||
heart_containers.pop_back().queue_free()
|
||||
30
scripts/maze.gd
Normal file
30
scripts/maze.gd
Normal 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)
|
||||
@@ -1,7 +1,14 @@
|
||||
extends CharacterBody2D
|
||||
class_name Player
|
||||
|
||||
signal color_changed(color: Color)
|
||||
signal lives_changed(lives: int)
|
||||
|
||||
@onready var sprite_2d: Sprite2D = $Sprite2D
|
||||
|
||||
var color := Color.WHITE
|
||||
@export var speed = 100
|
||||
var lives: int = 1
|
||||
|
||||
func _physics_process(delta: float) -> void:
|
||||
velocity = Vector2.ZERO
|
||||
@@ -15,3 +22,21 @@ func _physics_process(delta: float) -> void:
|
||||
velocity += Vector2.RIGHT
|
||||
velocity = velocity.normalized() * speed
|
||||
move_and_slide()
|
||||
for i in range(get_slide_collision_count()):
|
||||
var collision := get_slide_collision(i)
|
||||
if collision.get_collider() is Chest:
|
||||
var buff: Buff = collision.get_collider().open(self)
|
||||
if buff:
|
||||
match(buff.color):
|
||||
buff.colors.RED:
|
||||
lives += 1
|
||||
color.r -= 0.25
|
||||
lives_changed.emit(lives)
|
||||
buff.colors.GREEN:
|
||||
$Camera2D.zoom -= Vector2(0.4, 0.4)
|
||||
color.g -= 0.25
|
||||
buff.colors.BLUE:
|
||||
speed += 12
|
||||
color.b -= 0.25
|
||||
sprite_2d.modulate = color
|
||||
color_changed.emit(color)
|
||||
|
||||
Reference in New Issue
Block a user