game: cache some calculations for enemies
This commit is contained in:
@@ -13,6 +13,8 @@ const ENEMY_BAT = preload("res://scenes/enemies/enemy_bat.tscn")
|
||||
const ENEMY_SLIME_SMALL = preload("res://scenes/enemies/enemy_slime_small.tscn")
|
||||
const SLIME_COLOR_VARIATIONS: Array[Color] = [Color.CHARTREUSE, Color.FUCHSIA, Color.DARK_ORANGE]
|
||||
|
||||
var _elapsed_time: float = 0.0
|
||||
|
||||
|
||||
func _ready() -> void:
|
||||
timer.wait_time = 1 / spawn_rate
|
||||
@@ -21,7 +23,12 @@ func _ready() -> void:
|
||||
GlobalConst.sig_set_spawn_rate.connect(_on_set_spawn_rate)
|
||||
|
||||
|
||||
func _physics_process(delta: float) -> void:
|
||||
_elapsed_time += delta
|
||||
|
||||
|
||||
func _on_timer_timeout() -> void:
|
||||
_on_set_spawn_rate(1.0 + (_elapsed_time / 60.0) ** 2)
|
||||
var enemies = get_tree().get_nodes_in_group(GlobalConst.GROUP_ENEMY)
|
||||
GlobalConst.sig_debug_stats_set.emit("enemy_count", "%s" % len(enemies))
|
||||
var next_enemy: PackedScene
|
||||
@@ -105,4 +112,7 @@ func _on_stop_spawning(val: bool):
|
||||
|
||||
|
||||
func _on_set_spawn_rate(val: float):
|
||||
timer.wait_time = 1 / val
|
||||
timer.stop()
|
||||
timer.wait_time = 1.0 / val
|
||||
timer.start()
|
||||
print_debug("spawn_rate: %s" % timer.wait_time)
|
||||
|
Reference in New Issue
Block a user