better spawn, heart ui, dash, new map
This commit is contained in:
parent
ce27965422
commit
34be761164
16 changed files with 137 additions and 171 deletions
|
|
@ -1,9 +1,16 @@
|
|||
extends TextureRect
|
||||
extends Control
|
||||
|
||||
|
||||
# Called when the node enters the scene tree for the first time.
|
||||
func _ready() -> void:
|
||||
EventBus.health_changed.connect(_on_health_changed)
|
||||
_on_health_changed(3)
|
||||
|
||||
func _on_health_changed(new : int):
|
||||
texture.region = Rect2(0, new * 32, 0, 32)
|
||||
var i = 0;
|
||||
for c : HealthHeart in get_children():
|
||||
print(i, new)
|
||||
if i < new:
|
||||
c.set_full()
|
||||
else:
|
||||
c.set_empty()
|
||||
i += 1
|
||||
|
||||
|
|
|
|||
|
|
@ -1,6 +1,6 @@
|
|||
class_name Player extends Entity
|
||||
|
||||
@export var dash_base_cd: float = 0.7
|
||||
@export var dash_base_cd: float = 0.2
|
||||
|
||||
@onready var player_sprite :AnimatedSprite2D = $PlayerSprite
|
||||
@onready var mask_sprite : Sprite2D = $PlayerSprite/MaskSprite
|
||||
|
|
@ -35,6 +35,11 @@ func _physics_process(delta: float) -> void:
|
|||
velocity += input_vector * move_speed
|
||||
|
||||
dash_cd_timer -= delta
|
||||
if dash_cd_timer > 0:
|
||||
collision_mask = (0xFFFF ^ 8) & collision_mask
|
||||
else:
|
||||
collision_mask = 8 | collision_mask
|
||||
|
||||
if Input.is_action_just_pressed("dash") and dash_cd_timer <= 0:
|
||||
start_dash(input_vector)
|
||||
|
||||
|
|
@ -69,8 +74,6 @@ func start_dash(dir: Vector2):
|
|||
tween.tween_property(player_sprite, "scale:x", 1, 0.1)
|
||||
|
||||
func _input(event: InputEvent) -> void:
|
||||
#if event.is_action_pressed("attack") and current_mask_data:
|
||||
#use_mask(get_global_mouse_position())
|
||||
|
||||
if event.is_action_pressed("interact") and closest_mask_drop:
|
||||
collect_drop(closest_mask_drop)
|
||||
|
|
|
|||
|
|
@ -1,8 +1,6 @@
|
|||
class_name RoomSpawn extends Area2D
|
||||
|
||||
@export var waves_container: Node2D
|
||||
|
||||
var waves: Array[Node] = []
|
||||
var waves: Array[WaveNode] = []
|
||||
var current_wave_index: int = 0
|
||||
var active_enemies: int = 0
|
||||
var has_triggered: bool = false
|
||||
|
|
@ -10,14 +8,9 @@ var has_triggered: bool = false
|
|||
func _ready() -> void:
|
||||
body_entered.connect(_on_body_entered)
|
||||
|
||||
if not waves_container:
|
||||
push_error("Waves container not assigned in RoomSpawn!")
|
||||
return
|
||||
|
||||
waves = waves_container.get_children()
|
||||
for wave in waves:
|
||||
wave.hide()
|
||||
wave.process_mode = Node.PROCESS_MODE_DISABLED
|
||||
for c in get_children():
|
||||
if c is WaveNode:
|
||||
waves.append(c)
|
||||
|
||||
func _on_body_entered(body: Node2D) -> void:
|
||||
if has_triggered:
|
||||
|
|
@ -25,30 +18,18 @@ func _on_body_entered(body: Node2D) -> void:
|
|||
|
||||
if body.is_in_group("player"):
|
||||
has_triggered = true
|
||||
start_next_wave()
|
||||
# cant spawn collision shape in body entered
|
||||
call_deferred("start_next_wave")
|
||||
|
||||
func start_next_wave() -> void:
|
||||
if current_wave_index >= waves.size():
|
||||
return
|
||||
|
||||
var current_wave = waves[current_wave_index]
|
||||
current_wave.show()
|
||||
current_wave.process_mode = Node.PROCESS_MODE_INHERIT
|
||||
|
||||
var enemies = current_wave.get_children()
|
||||
active_enemies = enemies.size()
|
||||
|
||||
if active_enemies == 0:
|
||||
current_wave_index += 1
|
||||
start_next_wave()
|
||||
return
|
||||
|
||||
for enemy in enemies:
|
||||
enemy.tree_exited.connect(_on_enemy_died)
|
||||
current_wave.finished.connect(_on_finished)
|
||||
current_wave.spawn_wave()
|
||||
|
||||
func _on_enemy_died() -> void:
|
||||
active_enemies -= 1
|
||||
|
||||
if active_enemies <= 0:
|
||||
current_wave_index += 1
|
||||
start_next_wave()
|
||||
|
||||
func _on_finished() -> void:
|
||||
current_wave_index += 1
|
||||
start_next_wave()
|
||||
|
|
|
|||
12
scripts/spawner.gd
Normal file
12
scripts/spawner.gd
Normal file
|
|
@ -0,0 +1,12 @@
|
|||
class_name Spawner extends Marker2D
|
||||
|
||||
signal finished;
|
||||
@export var spawn_instance : PackedScene;
|
||||
|
||||
func spawn():
|
||||
var entity : Entity = spawn_instance.instantiate()
|
||||
get_tree().current_scene.add_child(entity)
|
||||
entity.global_position = global_position
|
||||
entity.scale.y = 5
|
||||
#create_tween().tween_property(entity, "scale:y", 1, 0.2)
|
||||
entity.died.connect(finished.emit)
|
||||
1
scripts/spawner.gd.uid
Normal file
1
scripts/spawner.gd.uid
Normal file
|
|
@ -0,0 +1 @@
|
|||
uid://dm2ayvfebi7x5
|
||||
23
scripts/wave_node.gd
Normal file
23
scripts/wave_node.gd
Normal file
|
|
@ -0,0 +1,23 @@
|
|||
class_name WaveNode extends Node2D
|
||||
|
||||
@export var spawn_interval := 0.2
|
||||
signal finished;
|
||||
var entities := 0;
|
||||
|
||||
func _ready() -> void:
|
||||
entities = get_child_count()
|
||||
|
||||
func spawn_wave():
|
||||
if get_child_count() == 0:
|
||||
finished.emit()
|
||||
return;
|
||||
|
||||
for c : Spawner in get_children():
|
||||
c.spawn();
|
||||
c.finished.connect(entity_left)
|
||||
await get_tree().create_timer(spawn_interval).timeout
|
||||
|
||||
func entity_left():
|
||||
entities -= 1
|
||||
if entities <= 0:
|
||||
finished.emit()
|
||||
1
scripts/wave_node.gd.uid
Normal file
1
scripts/wave_node.gd.uid
Normal file
|
|
@ -0,0 +1 @@
|
|||
uid://beuumo3n5tycr
|
||||
Loading…
Add table
Add a link
Reference in a new issue