diff options
| -rw-r--r-- | game/enemy/BattleScript.cpp | 9 | ||||
| -rw-r--r-- | game/enemy/BattleScript.h | 1 | ||||
| -rw-r--r-- | game/enemy/EnemyScript.cpp | 2 | ||||
| -rw-r--r-- | 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 <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(){ 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<GameScene>(); +	  	gameloop.add_scene<MainMenuScene>();  	gameloop.add_scene<ShopMenuScene>(); -	 +	gameloop.add_scene<GameScene>();  	return gameloop.main();  }  |