aboutsummaryrefslogtreecommitdiff
path: root/game/enemy
diff options
context:
space:
mode:
Diffstat (limited to 'game/enemy')
-rw-r--r--game/enemy/BattleScript.cpp9
-rw-r--r--game/enemy/BattleScript.h1
-rw-r--r--game/enemy/EnemyScript.cpp2
3 files changed, 7 insertions, 5 deletions
diff --git a/game/enemy/BattleScript.cpp b/game/enemy/BattleScript.cpp
index 463ddf3..1d263a3 100644
--- a/game/enemy/BattleScript.cpp
+++ b/game/enemy/BattleScript.cpp
@@ -1,4 +1,3 @@
-#include <iostream>
#include "BattleScript.h"
#include <crepe/api/AI.h>
#include "EnemyScript.h"
@@ -8,10 +7,7 @@
#include "EnemyScript.h"
using namespace std;
using namespace crepe;
-// stop player movement
-// spawn enemies
-// resume game once enemies are defeated
-// optional: spawn lazers during fight
+
BattleScript::BattleScript(){
engine.seed(rd());
}
@@ -24,6 +20,7 @@ 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");
@@ -33,10 +30,12 @@ void BattleScript::fixed_update(duration_t dt){
}
}
if(!enemies_alive){
+ this->battle_active = false;
this->trigger_event<BattleWonEvent>();
}
}
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++){
diff --git a/game/enemy/BattleScript.h b/game/enemy/BattleScript.h
index d239e70..55ca166 100644
--- a/game/enemy/BattleScript.h
+++ b/game/enemy/BattleScript.h
@@ -14,6 +14,7 @@ class BattleScript : public crepe::Script{
void init() override;
void fixed_update(crepe::duration_t dt) override;
private:
+ bool battle_active = false;
std::random_device rd;
std::default_random_engine engine;
bool create_battle(const BattleStartEvent& e);
diff --git a/game/enemy/EnemyScript.cpp b/game/enemy/EnemyScript.cpp
index 4b75846..f9b79ea 100644
--- a/game/enemy/EnemyScript.cpp
+++ b/game/enemy/EnemyScript.cpp
@@ -82,6 +82,8 @@ bool EnemyScript::on_collide(const CollisionEvent & e){
if(e.info.other.metadata.tag == "player_bullet"){
this->despawn_enemy();
}
+ BehaviorScript& enemy_script = this->get_component<BehaviorScript>();
+ enemy_script.active = false;
return false;
}
void EnemyScript::despawn_enemy(){