diff options
| author | JAROWMR <jarorutjes07@gmail.com> | 2025-01-07 14:06:45 +0100 | 
|---|---|---|
| committer | JAROWMR <jarorutjes07@gmail.com> | 2025-01-07 14:06:45 +0100 | 
| commit | 41f890863706ee8ede43021fe83b776b638a18b7 (patch) | |
| tree | 4ee74df7e60c8c22c61a1748dd648dda2783b21f | |
| parent | bc66e7195c80facca244f933b882011e5e81fa3c (diff) | |
fixed coins and improved coin
| -rw-r--r-- | game/coins/CoinPool.cpp | 5 | ||||
| -rw-r--r-- | game/coins/CoinScript.cpp | 4 | ||||
| -rw-r--r-- | game/coins/CoinSubScene.cpp | 3 | ||||
| -rw-r--r-- | game/coins/CoinSubScene.h | 2 | ||||
| -rw-r--r-- | game/coins/CoinSystemScript.cpp | 2 | ||||
| -rw-r--r-- | game/coins/CoinSystemScript.h | 2 | ||||
| -rw-r--r-- | game/hud/HudScript.cpp | 28 | ||||
| -rw-r--r-- | game/hud/HudScript.h | 2 | ||||
| -rw-r--r-- | game/player/PlayerEndScript.cpp | 2 | ||||
| -rw-r--r-- | game/player/PlayerScript.cpp | 6 | ||||
| -rw-r--r-- | game/player/PlayerSubScene.cpp | 2 | 
11 files changed, 32 insertions, 26 deletions
| diff --git a/game/coins/CoinPool.cpp b/game/coins/CoinPool.cpp index 59b987c..439b3b3 100644 --- a/game/coins/CoinPool.cpp +++ b/game/coins/CoinPool.cpp @@ -8,6 +8,9 @@ using namespace crepe;  using namespace std;  void CoinPool::create_coins(crepe::Scene & scn) { +	int amount = 0;  	CoinSubScene coin; -	while(coin.create(scn) < this->MAXIMUM_AMOUNT); +	while(amount < this->MAXIMUM_AMOUNT){ +		amount = coin.create(scn,amount); +	}  } diff --git a/game/coins/CoinScript.cpp b/game/coins/CoinScript.cpp index 5960446..a3ee3b9 100644 --- a/game/coins/CoinScript.cpp +++ b/game/coins/CoinScript.cpp @@ -10,11 +10,11 @@ using namespace crepe;  using namespace std;  bool CoinScript::on_collision(const CollisionEvent & collisionData){ -	if(collisionData.info.other.metadata.tag != "coin") return true; +	if(collisionData.info.other.metadata.tag != "coin") return false;  	this->get_components_by_name<Sprite>(collisionData.info.other.metadata.name).front().get().active = false;  	this->get_components_by_name<CircleCollider>(collisionData.info.other.metadata.name).front().get().active = false;  	this->amount++; -	return true; +	return false;  }  void CoinScript::init(){ diff --git a/game/coins/CoinSubScene.cpp b/game/coins/CoinSubScene.cpp index 72319ca..9c9caa3 100644 --- a/game/coins/CoinSubScene.cpp +++ b/game/coins/CoinSubScene.cpp @@ -11,10 +11,9 @@  using namespace crepe;  using namespace std; -int CoinSubScene::create(Scene & scn){ +int CoinSubScene::create(Scene & scn,int coin_counter){  	vec2 size = {20, 20}; -	static int coin_counter = 0;  	string unique_name = "coin_" + to_string(coin_counter++);  	GameObject coin = scn.new_object(unique_name.c_str(),"coin",vec2{650,0},0,1); diff --git a/game/coins/CoinSubScene.h b/game/coins/CoinSubScene.h index f85f427..ddb6450 100644 --- a/game/coins/CoinSubScene.h +++ b/game/coins/CoinSubScene.h @@ -8,5 +8,5 @@ class Scene;  class CoinSubScene {  public: -	int create(crepe::Scene & scn); +	int create(crepe::Scene & scn,int coin_counter);  }; diff --git a/game/coins/CoinSystemScript.cpp b/game/coins/CoinSystemScript.cpp index c9c301e..573c825 100644 --- a/game/coins/CoinSystemScript.cpp +++ b/game/coins/CoinSystemScript.cpp @@ -9,7 +9,7 @@  using namespace crepe;  using namespace std; -std::vector<CoinSystemScript::CoinData> CoinSystemScript::coin_locations; +  void CoinSystemScript::init() {  	engine.seed(rd()); diff --git a/game/coins/CoinSystemScript.h b/game/coins/CoinSystemScript.h index f558f08..c65b533 100644 --- a/game/coins/CoinSystemScript.h +++ b/game/coins/CoinSystemScript.h @@ -49,7 +49,7 @@ private:  	static constexpr float SPAWN_DISTANCE = 600;  	static constexpr float DESPAWN_DISTANCE = 600;  	static constexpr float SPAWN_AREA = 50; -	static std::vector<CoinData> coin_locations; +	std::vector<CoinData> coin_locations;  private:  // preset one settings  // *****				***** diff --git a/game/hud/HudScript.cpp b/game/hud/HudScript.cpp index d7a043a..30a5c15 100644 --- a/game/hud/HudScript.cpp +++ b/game/hud/HudScript.cpp @@ -19,19 +19,21 @@ void HudScript::init() {  	txt.offset = TOP_LEFT+FONTOFFSET+BEST_OFFSET + vec2{record.size() * BEST_CHAR_WIDTH/2,0};  	this->subscribe<GetCoinEvent>([this](const GetCoinEvent e)-> bool { return this->get_coin(e); }); -	this->subscribe<KeyPressEvent>([this](const KeyPressEvent & ev) -> bool { -		if(ev.key != Keycode::END) return false; -		Text & txt_fps = this->get_components_by_name<Text>(HUD_FPS).front(); -		this->show_fps = !this->show_fps; -		if(this->show_fps) -		{ -			txt_fps.active = true; -		} -		else { -			txt_fps.active = false; -		} -		return true; -	}); +	this->subscribe<KeyPressEvent>([this](const KeyPressEvent & ev) -> bool { return this->toggle_fps(ev);}); +} + +bool HudScript::toggle_fps(crepe::KeyPressEvent ev){ +	if(ev.key != Keycode::END) return false; +	Text & txt_fps = this->get_components_by_name<Text>(HUD_FPS).front(); +	this->show_fps = !this->show_fps; +	if(this->show_fps) +	{ +		txt_fps.active = true; +	} +	else { +		txt_fps.active = false; +	} +	return true;  }  void HudScript::frame_update(crepe::duration_t dt) { diff --git a/game/hud/HudScript.h b/game/hud/HudScript.h index 0aa10a4..d780d4b 100644 --- a/game/hud/HudScript.h +++ b/game/hud/HudScript.h @@ -1,5 +1,6 @@  #pragma once +#include "api/Event.h"  #include "api/Script.h"  #include "manager/SaveManager.h" @@ -12,6 +13,7 @@ public:  	void init() override;  	void frame_update(crepe::duration_t dt) override;  	bool get_coin(const GetCoinEvent e); +	bool toggle_fps(crepe::KeyPressEvent ev);  private:  	crepe::SaveManager* savemgr;  	bool show_fps = false; diff --git a/game/player/PlayerEndScript.cpp b/game/player/PlayerEndScript.cpp index 1554c84..f3d9aad 100644 --- a/game/player/PlayerEndScript.cpp +++ b/game/player/PlayerEndScript.cpp @@ -94,7 +94,7 @@ bool PlayerEndScript::on_collision(const crepe::CollisionEvent & ev) {  			this->trigger_event<EndGameEvent>();  		} -		return true; +		return false;  	}  	return false; diff --git a/game/player/PlayerScript.cpp b/game/player/PlayerScript.cpp index 472d7c8..c151d53 100644 --- a/game/player/PlayerScript.cpp +++ b/game/player/PlayerScript.cpp @@ -36,7 +36,7 @@ bool PlayerScript::on_collision(const CollisionEvent & ev) {  		}  		play_scr.active = false;  		end_scr.active = true; -		return true; +		return false;  	} else if (ev.info.other.metadata.tag == "laser") {  		for (Animator & anim : animators) {  			anim.active = true; @@ -49,7 +49,7 @@ bool PlayerScript::on_collision(const CollisionEvent & ev) {  		}  		play_scr.active = false;  		end_scr.active = true; -		return true; +		return false;  	} else if (ev.info.other.metadata.tag == "missile") {  		for (Animator & anim : animators) {  			anim.active = true; @@ -62,7 +62,7 @@ bool PlayerScript::on_collision(const CollisionEvent & ev) {  		}  		play_scr.active = false;  		end_scr.active = true; -		return true; +		return false;  	}  	return false; diff --git a/game/player/PlayerSubScene.cpp b/game/player/PlayerSubScene.cpp index fff9287..e6da6f7 100644 --- a/game/player/PlayerSubScene.cpp +++ b/game/player/PlayerSubScene.cpp @@ -150,6 +150,6 @@ PlayerSubScene::PlayerSubScene(Scene & scn) {  		.collision_layer = COLL_LAY_PLAYER,  	});  	player.add_component<BehaviorScript>().set_script<PlayerScript>().active = false; -	player.add_component<BehaviorScript>().set_script<PlayerEndScript>().active = false;  	player.add_component<BehaviorScript>().set_script<CoinScript>(); +	player.add_component<BehaviorScript>().set_script<PlayerEndScript>().active = false;  } |