game: add slime enemy

This commit is contained in:
2025-08-21 23:56:18 +02:00
parent 7cff7b62e9
commit 7aedea8206
4 changed files with 69 additions and 2 deletions

View File

@@ -10,7 +10,8 @@ extends Node2D
const ENEMY_RAT = preload("res://scenes/enemies/enemy_rat.tscn")
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 ]
func _ready() -> void:
timer.wait_time = 1 / spawn_rate
@@ -23,16 +24,21 @@ func _on_timer_timeout() -> void:
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
match randi() % 2:
match randi() % 3:
0:
next_enemy = ENEMY_BAT
1:
next_enemy = ENEMY_RAT
2:
next_enemy = ENEMY_SLIME_SMALL
if len(enemies) < max_enemies:
var new_enemy = next_enemy.instantiate()
new_enemy.position = _get_spawn_pos()
new_enemy.target = target
if is_instance_of(new_enemy, EnemySlimeSmall):
var slime_color: Color = SLIME_COLOR_VARIATIONS.pick_random()
new_enemy.color = slime_color
add_child(new_enemy)