✨ Ebb and flow
This commit is contained in:
@@ -1,6 +1,7 @@
|
||||
extends CharacterBody2D
|
||||
|
||||
@export var damage = 12.0
|
||||
@export var knockback = 4
|
||||
|
||||
func _physics_process(delta):
|
||||
var collision = move_and_collide(velocity * delta)
|
||||
@@ -8,6 +9,8 @@ func _physics_process(delta):
|
||||
if collision:
|
||||
var collider = collision.get_collider()
|
||||
if collider is Enemy:
|
||||
var normal = collision.get_normal()
|
||||
collider.velocity = collider.velocity.bounce(normal) * knockback
|
||||
collider.take_damage(damage)
|
||||
queue_free()
|
||||
|
||||
|
@@ -2,6 +2,8 @@ class_name Enemy
|
||||
|
||||
extends CharacterBody2D
|
||||
|
||||
signal enemy_defeat
|
||||
|
||||
@export var damage = 8.0
|
||||
@export var max_health = 20
|
||||
|
||||
@@ -13,4 +15,5 @@ func _ready():
|
||||
func take_damage(amount: float):
|
||||
health -= amount
|
||||
if health <= 0:
|
||||
enemy_defeat.emit()
|
||||
queue_free()
|
||||
|
@@ -1,11 +1,15 @@
|
||||
extends Node2D
|
||||
|
||||
signal enemy_defeat
|
||||
|
||||
@export var common_parent: Node2D
|
||||
@export var path_follow: PathFollow2D
|
||||
|
||||
@export var target: PackedScene
|
||||
@export var common_target: Node2D
|
||||
|
||||
@export var respawn_timer: Timer
|
||||
|
||||
func spawn():
|
||||
var instance = target.instantiate()
|
||||
|
||||
@@ -18,6 +22,16 @@ func spawn():
|
||||
instance.speed = randi_range(800, 1400)
|
||||
|
||||
instance.target = common_target
|
||||
instance.connect("enemy_defeat", _on_enemy_defeat)
|
||||
|
||||
# Add into common parent
|
||||
common_parent.add_child(instance)
|
||||
|
||||
func _on_wave_finished():
|
||||
respawn_timer.stop()
|
||||
|
||||
func _on_wave_started():
|
||||
respawn_timer.start()
|
||||
|
||||
func _on_enemy_defeat():
|
||||
enemy_defeat.emit()
|
||||
|
@@ -14,6 +14,8 @@ extends CharacterBody2D
|
||||
@export var fire_cooldown_duration = 0.2
|
||||
@export var fire_cooldown_timer: Timer
|
||||
|
||||
@export var statistics: Statistics
|
||||
|
||||
func deal_move(delta):
|
||||
var input_direction = Input.get_vector("move_left", "move_right", "move_up", "move_down")
|
||||
velocity = velocity.move_toward(input_direction * speed, speed * delta)
|
||||
@@ -36,6 +38,7 @@ func deal_weapon_shoot():
|
||||
bullet.global_position = global_position
|
||||
bullet.velocity = direction * weapon_bullet_speed
|
||||
|
||||
statistics.bullet_shoot += 1
|
||||
fire_cooldown_timer.start(fire_cooldown_duration)
|
||||
|
||||
func _on_dash_cooled_down():
|
||||
|
71
scripts/statistics.gd
Normal file
71
scripts/statistics.gd
Normal file
@@ -0,0 +1,71 @@
|
||||
class_name Statistics
|
||||
|
||||
extends Node
|
||||
|
||||
signal wave_finished
|
||||
signal wave_started
|
||||
|
||||
var time_started
|
||||
var time_survived
|
||||
|
||||
var wave_passed: int
|
||||
var in_wave_gap: bool
|
||||
|
||||
var enemies_defeated: int
|
||||
var bullet_shoot: int
|
||||
|
||||
@export var wave_gap_duration = 10
|
||||
@export var wave_duration = 10
|
||||
@export var wave_multiplier = 1.5
|
||||
|
||||
@export var wave_timer: Timer
|
||||
@export var wave_gap_timer: Timer
|
||||
|
||||
func _ready():
|
||||
time_started = Time.get_ticks_msec()
|
||||
time_survived = null
|
||||
|
||||
wave_passed = 0
|
||||
enemies_defeated = 0
|
||||
bullet_shoot = 0
|
||||
|
||||
_on_wave_gap_passed()
|
||||
|
||||
func _on_game_over():
|
||||
time_survived = get_time_survived()
|
||||
|
||||
func get_current_wave():
|
||||
return wave_passed + 1
|
||||
|
||||
func get_current_wave_time():
|
||||
if in_wave_gap:
|
||||
return get_current_wave_duration() - $WaveGapTimer.time_left
|
||||
else:
|
||||
return get_current_wave_duration() - $WaveTimer.time_left
|
||||
|
||||
func get_current_wave_duration():
|
||||
if in_wave_gap:
|
||||
return wave_gap_duration
|
||||
else:
|
||||
return wave_duration + wave_multiplier * wave_passed
|
||||
|
||||
func get_time_survived():
|
||||
if time_survived == null:
|
||||
return Time.get_ticks_msec() - time_started
|
||||
else:
|
||||
return time_survived
|
||||
|
||||
func _on_enemy_defeated():
|
||||
enemies_defeated += 1
|
||||
|
||||
func _on_wave_passed():
|
||||
wave_passed += 1
|
||||
in_wave_gap = true
|
||||
wave_finished.emit()
|
||||
wave_gap_timer.start(wave_gap_duration)
|
||||
|
||||
func _on_wave_gap_passed():
|
||||
in_wave_gap = false
|
||||
wave_started.emit()
|
||||
wave_timer.wait_time = get_current_wave_duration()
|
||||
wave_timer.start()
|
@@ -2,6 +2,6 @@ extends Sprite2D
|
||||
|
||||
@export var regeneration_progress = 0.5
|
||||
|
||||
func _process(delta):
|
||||
func _process(_wdelta):
|
||||
set_modulate(Color(1, 1, 1, regeneration_progress))
|
||||
rotation_degrees += 1
|
||||
|
6
scripts/ui/finish_screen.gd
Normal file
6
scripts/ui/finish_screen.gd
Normal file
@@ -0,0 +1,6 @@
|
||||
extends Control
|
||||
|
||||
@export var stats: Statistics
|
||||
|
||||
func _show():
|
||||
visible = true
|
25
scripts/ui/stats_overlay.gd
Normal file
25
scripts/ui/stats_overlay.gd
Normal file
@@ -0,0 +1,25 @@
|
||||
extends Control
|
||||
|
||||
@export var stats: Statistics
|
||||
|
||||
@export var survived_indicator: Label
|
||||
|
||||
@export var wave_indicator: Label
|
||||
@export var wave_progress: ProgressBar
|
||||
|
||||
var wave_stylebox = StyleBoxFlat.new()
|
||||
var wave_gap_stylebox = StyleBoxFlat.new()
|
||||
|
||||
func _ready():
|
||||
wave_stylebox.bg_color = Color("84ba7a")
|
||||
wave_gap_stylebox.bg_color = Color("89a1e5")
|
||||
|
||||
func _process(_delta):
|
||||
survived_indicator.text = "%.2fs" % (stats.get_time_survived() / 1000.0)
|
||||
wave_indicator.text = "%d" % stats.get_current_wave()
|
||||
|
||||
if stats.in_wave_gap:
|
||||
wave_progress.add_theme_stylebox_override("fill", wave_gap_stylebox)
|
||||
else:
|
||||
wave_progress.add_theme_stylebox_override("fill", wave_stylebox)
|
||||
wave_progress.value = stats.get_current_wave_time() / stats.get_current_wave_duration() * 100
|
Reference in New Issue
Block a user