diff options
author | heavydemon21 <nielsstunnebrink1@gmail.com> | 2025-01-10 19:51:02 +0100 |
---|---|---|
committer | heavydemon21 <nielsstunnebrink1@gmail.com> | 2025-01-10 19:51:02 +0100 |
commit | 16917357837916d1ef88b6122218fa0d567d1ddc (patch) | |
tree | eefa561b81c48549277950692fdad714a2f501f2 /game/enemy/BattleScript.cpp | |
parent | 0b19fe5a9168368d4be0993407dd3fc3bdfa0611 (diff) | |
parent | b9d00961a8894356c7cff7597de424a12d2841a6 (diff) |
Merge remote-tracking branch 'origin/master' into niels/game
Diffstat (limited to 'game/enemy/BattleScript.cpp')
-rw-r--r-- | game/enemy/BattleScript.cpp | 36 |
1 files changed, 23 insertions, 13 deletions
diff --git a/game/enemy/BattleScript.cpp b/game/enemy/BattleScript.cpp index 6d96ef6..798cbb9 100644 --- a/game/enemy/BattleScript.cpp +++ b/game/enemy/BattleScript.cpp @@ -1,5 +1,7 @@ #include "BattleScript.h" +#include "EnemyConfig.h" #include "EnemyScript.h" +#include "api/Transform.h" #include <crepe/api/AI.h> #include <crepe/api/BehaviorScript.h> #include <crepe/api/Metadata.h> @@ -18,11 +20,10 @@ void BattleScript::init() { void BattleScript::fixed_update(duration_t dt) { if (!battle_active) return; bool enemies_alive = false; - RefVector<BehaviorScript> enemy_scripts - = this->get_components_by_tag<BehaviorScript>("enemy"); + RefVector<AI> enemy_ai = this->get_components_by_tag<AI>("enemy"); - for (BehaviorScript & script : enemy_scripts) { - if (script.active) { + for (AI & ai : enemy_ai) { + if (ai.active) { enemies_alive = true; } } @@ -32,20 +33,29 @@ void BattleScript::fixed_update(duration_t dt) { } } bool BattleScript::create_battle(const BattleStartEvent & e) { - this->battle_active = true; - RefVector<BehaviorScript> enemy_scripts - = this->get_components_by_tag<BehaviorScript>("enemy"); - std::uniform_real_distribution<float> dist(10, 30); - for (int i = 0; i < e.num_enemies; i++) { - BehaviorScript & script = enemy_scripts[i]; - script.active = true; + this->battle_active = e.battle; + this->spawn_enemies(e.num_enemies); + return false; +} +void BattleScript::spawn_enemies(int amount) { + RefVector<AI> enemy_ai = this->get_components_by_tag<AI>("enemy"); + std::uniform_real_distribution<float> dist(70, 150); + int spawned = 0; + for (int i = 0; i < ENEMY_POOL_MAX; i++) { + AI & ai = enemy_ai[i]; + Transform & enemy_transform + = this->get_components_by_id<Transform>(ai.game_object_id).front(); + if (ai.active == true || enemy_transform.position != ENEMY_POOL_LOCATION) continue; this->queue_event<SpawnEnemyEvent>( SpawnEnemyEvent { .speed = dist(engine), .column = i, }, - script.game_object_id + ai.game_object_id ); + spawned++; + if (spawned >= amount) { + return; + } } - return false; } |