From 016b36b6d340be958bb047ca5f26dd54aa658c88 Mon Sep 17 00:00:00 2001 From: WBoerenkamps Date: Wed, 8 Jan 2025 12:43:54 +0100 Subject: battlescript battle won working --- game/enemy/BattleScript.cpp | 9 ++++----- game/enemy/BattleScript.h | 1 + game/enemy/EnemyScript.cpp | 2 ++ game/main.cpp | 4 ++-- 4 files changed, 9 insertions(+), 7 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 #include "BattleScript.h" #include #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 enemy_scripts = this->get_components_by_tag("enemy"); @@ -33,10 +30,12 @@ void BattleScript::fixed_update(duration_t dt){ } } if(!enemies_alive){ + this->battle_active = false; this->trigger_event(); } } bool BattleScript::create_battle(const BattleStartEvent& e){ + this->battle_active = true; RefVector enemy_scripts = this->get_components_by_tag("enemy"); std::uniform_real_distribution 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(); + enemy_script.active = false; return false; } void EnemyScript::despawn_enemy(){ diff --git a/game/main.cpp b/game/main.cpp index 3f7e17e..9b25444 100644 --- a/game/main.cpp +++ b/game/main.cpp @@ -9,10 +9,10 @@ using namespace crepe; int main() { Engine gameloop; - gameloop.add_scene(); + gameloop.add_scene(); gameloop.add_scene(); - + gameloop.add_scene(); return gameloop.main(); } -- cgit v1.2.3