diff options
| -rw-r--r-- | game/CMakeLists.txt | 4 | ||||
| -rw-r--r-- | game/hud/SpeedScript.cpp | 2 | ||||
| -rw-r--r-- | game/hud/SpeedScript.h | 2 | ||||
| -rw-r--r-- | game/menus/ButtonReplaySubScript.cpp | 31 | ||||
| -rw-r--r-- | game/menus/ButtonReplaySubScript.h | 17 | ||||
| -rw-r--r-- | game/menus/ButtonShowCreditsSubScript.cpp | 20 | ||||
| -rw-r--r-- | game/menus/ButtonShowCreditsSubScript.h | 14 | ||||
| -rw-r--r-- | game/menus/ButtonSubScene.cpp | 15 | ||||
| -rw-r--r-- | game/menus/ButtonSubScene.h | 3 | ||||
| -rw-r--r-- | game/menus/endgame/EndGameSubScene.cpp | 2 | ||||
| -rw-r--r-- | game/menus/endgame/EndGameSubScript.cpp | 1 | ||||
| -rw-r--r-- | game/menus/mainmenu/CreditsSubScene.cpp | 67 | ||||
| -rw-r--r-- | game/menus/mainmenu/CreditsSubScene.h | 9 | ||||
| -rw-r--r-- | game/menus/mainmenu/CreditsSubScript.cpp | 60 | ||||
| -rw-r--r-- | game/menus/mainmenu/CreditsSubScript.h | 18 | ||||
| -rw-r--r-- | game/menus/mainmenu/MainMenuScene.cpp | 19 | ||||
| -rw-r--r-- | src/crepe/api/Sprite.cpp | 15 | ||||
| -rw-r--r-- | src/crepe/api/Sprite.h | 10 | 
18 files changed, 304 insertions, 5 deletions
diff --git a/game/CMakeLists.txt b/game/CMakeLists.txt index 4e31f80..f81850d 100644 --- a/game/CMakeLists.txt +++ b/game/CMakeLists.txt @@ -33,14 +33,18 @@ add_executable(main  	menus/IButtonScript.cpp  	menus/ButtonSetShopSubScript.cpp  	menus/ButtonSetMainMenuSubScript.cpp +	menus/ButtonReplaySubScript.cpp  	menus/ButtonNextMainMenuSubScript.cpp  	menus/FloatingWindowSubScene.cpp  	menus/IFloatingWindowScript.cpp +	menus/ButtonShowCreditsSubScript.cpp  	menus/shop/ShopMenuScene.cpp  	menus/mainmenu/ButtonTransitionPreviewSubScript.cpp  	menus/mainmenu/ITransitionScript.cpp  	menus/mainmenu/MainMenuScene.cpp  	menus/mainmenu/TransitionStartSubScript.cpp +	menus/mainmenu/CreditsSubScene.cpp +	menus/mainmenu/CreditsSubScript.cpp  	menus/endgame/EndGameSubScene.cpp  	menus/endgame/EndGameSubScript.cpp  	coins/CoinSubScene.cpp diff --git a/game/hud/SpeedScript.cpp b/game/hud/SpeedScript.cpp index d0a4dfe..29d4193 100644 --- a/game/hud/SpeedScript.cpp +++ b/game/hud/SpeedScript.cpp @@ -26,9 +26,11 @@ void SpeedScript::init() {  void SpeedScript::fixed_update(crepe::duration_t dt) {  	LoopTimerManager & lp = this->get_loop_timer();  	if (this->get_key_state(Keycode::PAGE_UP)) { +		if(lp.get_time_scale() >= 2) return;  		lp.set_time_scale(lp.get_time_scale() + 0.1);  	}  	if (this->get_key_state(Keycode::PAGE_DOWN)) { +		if(lp.get_time_scale() <= 0.5) return;  		lp.set_time_scale(lp.get_time_scale() - 0.1);  	}  } diff --git a/game/hud/SpeedScript.h b/game/hud/SpeedScript.h index 6c15a89..b40f7cc 100644 --- a/game/hud/SpeedScript.h +++ b/game/hud/SpeedScript.h @@ -10,6 +10,6 @@ public:  private:  	crepe::SaveManager * savemgr; -	bool toggle = true; +	bool toggle = false;  	float timescale = 1;  }; diff --git a/game/menus/ButtonReplaySubScript.cpp b/game/menus/ButtonReplaySubScript.cpp new file mode 100644 index 0000000..26cb8ee --- /dev/null +++ b/game/menus/ButtonReplaySubScript.cpp @@ -0,0 +1,31 @@ +#include "ButtonReplaySubScript.h" +#include "MenusConfig.h" + +#include <crepe/api/AudioSource.h> +#include <crepe/types.h> +#include "../Events.h" + +using namespace crepe; +using namespace std; + +void ButtonReplaySubScript::init() { +	IButtonScript::init(); +	this->subscribe<ButtonPressEvent>([this](const ButtonPressEvent & e) { +		return this->on_button_press(e); +	}); +	this->subscribe<EndGameEvent>([this](const EndGameEvent & e) { +		return this->set_recording(); +	}); +	replay.record_start(); +} + + +bool ButtonReplaySubScript::on_button_press(const ButtonPressEvent & e) { +	replay.play(this->recording); +	return false; +} + +bool ButtonReplaySubScript::set_recording(){ +	this->recording = replay.record_end(); +	return false; +} diff --git a/game/menus/ButtonReplaySubScript.h b/game/menus/ButtonReplaySubScript.h new file mode 100644 index 0000000..7e63d06 --- /dev/null +++ b/game/menus/ButtonReplaySubScript.h @@ -0,0 +1,17 @@ +#pragma once + +#include "IButtonScript.h" + +#include <crepe/api/Script.h> + +class ButtonReplaySubScript : public IButtonScript { +public: +	void init() override; +	bool on_button_press(const crepe::ButtonPressEvent & e); +private: +	crepe::recording_t recording = 0; +	bool set_recording(); + +protected: +	bool transition = false; +}; diff --git a/game/menus/ButtonShowCreditsSubScript.cpp b/game/menus/ButtonShowCreditsSubScript.cpp new file mode 100644 index 0000000..ec0e980 --- /dev/null +++ b/game/menus/ButtonShowCreditsSubScript.cpp @@ -0,0 +1,20 @@ +#include "ButtonShowCreditsSubScript.h" +#include "MenusConfig.h" +#include "mainmenu/CreditsSubScript.h" +#include <crepe/api/AudioSource.h> +#include <crepe/types.h> + +using namespace crepe; +using namespace std; + +void ButtonShowCreditsSubScript::init() { +	IButtonScript::init(); +	this->subscribe<ButtonPressEvent>([this](const ButtonPressEvent & e) { +		return this->on_button_press(e); +	}); +} + +bool ButtonShowCreditsSubScript::on_button_press(const ButtonPressEvent & e) { +	this->trigger_event<ShowCreditsEvent>(); +	return false; +} diff --git a/game/menus/ButtonShowCreditsSubScript.h b/game/menus/ButtonShowCreditsSubScript.h new file mode 100644 index 0000000..3c73c44 --- /dev/null +++ b/game/menus/ButtonShowCreditsSubScript.h @@ -0,0 +1,14 @@ +#pragma once + +#include "IButtonScript.h" + +#include <crepe/api/Script.h> + +class ButtonShowCreditsSubScript : public IButtonScript { +public: +	void init() override; +	bool on_button_press(const crepe::ButtonPressEvent & e); + +protected: +	bool transition = false; +}; diff --git a/game/menus/ButtonSubScene.cpp b/game/menus/ButtonSubScene.cpp index e41c798..d657be9 100644 --- a/game/menus/ButtonSubScene.cpp +++ b/game/menus/ButtonSubScene.cpp @@ -1,13 +1,16 @@  #include "ButtonSubScene.h"  #include "ButtonNextMainMenuSubScript.h" +#include "ButtonReplaySubScript.h"  #include "ButtonSetMainMenuSubScript.h"  #include "ButtonSetShopSubScript.h" +#include "ButtonShowCreditsSubScript.h"  #include "IButtonScript.h"  #include "MenusConfig.h"  #include "mainmenu/ButtonTransitionPreviewSubScript.h"  #include "../Config.h" +#include "mainmenu/CreditsSubScript.h"  #include <crepe/api/BehaviorScript.h>  #include <crepe/api/Button.h> @@ -58,6 +61,18 @@ void ButtonSubScene::set_script(crepe::GameObject & button_object, const Data &  			button_object.add_component<BehaviorScript>()  				.set_script<ButtonNextMainMenuSubScript>();  			break; +		case ScriptSelect::REPLAY: +			button_object.add_component<BehaviorScript>() +				.set_script<ButtonReplaySubScript>(); +			break; +		case ScriptSelect::CREDITS_BACK: +			button_object.add_component<BehaviorScript>() +				.set_script<CreditsSubScript>(data.tag); +			break; +		case ScriptSelect::CREDITS_SHOW: +			button_object.add_component<BehaviorScript>() +				.set_script<ButtonShowCreditsSubScript>(); +			break;  		case ScriptSelect::NONE:  			button_object.add_component<BehaviorScript>().set_script<IButtonScript>();  			break; diff --git a/game/menus/ButtonSubScene.h b/game/menus/ButtonSubScene.h index c1c6de8..74f9464 100644 --- a/game/menus/ButtonSubScene.h +++ b/game/menus/ButtonSubScene.h @@ -16,6 +16,9 @@ public:  		SHOP,  		MAINMENU,  		NEXT, +		REPLAY, +		CREDITS_SHOW, +		CREDITS_BACK,  		NONE,  	};  	//icon enum diff --git a/game/menus/endgame/EndGameSubScene.cpp b/game/menus/endgame/EndGameSubScene.cpp index 3ef0f9a..a6f8b25 100644 --- a/game/menus/endgame/EndGameSubScene.cpp +++ b/game/menus/endgame/EndGameSubScene.cpp @@ -71,7 +71,7 @@ void EndGameSubScene::create(Scene & scn) {  			.text = "REPLAY",  			.text_width = 150,  			.position = {-button_position.x, button_position.y}, -			// .script_type = ButtonSubScene::ScriptSelect::MAINMENU, +			.script_type = ButtonSubScene::ScriptSelect::REPLAY,  			.button_type = ButtonSubScene::ButtonSelect::BACK,  			.scale = 0.6,  			.worldspace = false, diff --git a/game/menus/endgame/EndGameSubScript.cpp b/game/menus/endgame/EndGameSubScript.cpp index f120e2d..08a9f8c 100644 --- a/game/menus/endgame/EndGameSubScript.cpp +++ b/game/menus/endgame/EndGameSubScript.cpp @@ -2,6 +2,7 @@  #include "../../Events.h"  #include "../IFloatingWindowScript.h" +#include "../ButtonReplaySubScript.h"  #include <string> diff --git a/game/menus/mainmenu/CreditsSubScene.cpp b/game/menus/mainmenu/CreditsSubScene.cpp new file mode 100644 index 0000000..df4616e --- /dev/null +++ b/game/menus/mainmenu/CreditsSubScene.cpp @@ -0,0 +1,67 @@ + +#include "CreditsSubScene.h" +#include "CreditsSubScript.h" + +#include "../../Config.h" +#include "../ButtonSubScene.h" +#include "../FloatingWindowSubScene.h" + +#include <string> + +#include <crepe/api/BehaviorScript.h> +#include <crepe/api/GameObject.h> +#include <crepe/api/Text.h> +#include <crepe/types.h> + +using namespace crepe; +using namespace std; + +void CreditsSubScene::create(Scene & scn) { + +	const std::string TAG = "credits_tag"; +	GameObject script = scn.new_object("script"); +	script.add_component<BehaviorScript>().set_script<CreditsSubScript>(TAG); + +	// Window +	FloatingWindowSubScene window; +	window.create( +		scn, +		FloatingWindowSubScene::Data { +			.group_tag = TAG, +			.width = 500, +			.offset = {150, -50}, +			.width_middle_offset = -2, +		} +	); + +	// Titel +	const string TITEL_STRING = "Credits"; +	GameObject titel = scn.new_object("titel", TAG); +	crepe::vec2 size = {200, (200.0f / TITEL_STRING.size()) * 2}; +	titel.add_component<Text>( +		size, FONT, +		Text::Data { +			.world_space = false, +			.text_color = Color::WHITE, +		}, +		vec2 {150, -207} + FONTOFFSET, TITEL_STRING +	); + +	// Buttons +	vec2 button_position = {190, 190}; +	ButtonSubScene button; +	button.create( +		scn, +		ButtonSubScene::Data { +			.text = "Back", +			.text_width = 150, +			.position = {-button_position.x+150, button_position.y}, +			.script_type = ButtonSubScene::ScriptSelect::CREDITS_BACK, +			.button_type = ButtonSubScene::ButtonSelect::BACK, +			.scale = 0.6, +			.worldspace = false, +			.tag = TAG, +			.sorting_layer_offset = 20, +		} +	); +} diff --git a/game/menus/mainmenu/CreditsSubScene.h b/game/menus/mainmenu/CreditsSubScene.h new file mode 100644 index 0000000..e7ff735 --- /dev/null +++ b/game/menus/mainmenu/CreditsSubScene.h @@ -0,0 +1,9 @@ +#pragma once + +#include <crepe/api/Scene.h> + +class CreditsSubScene { + +public: +	void create(crepe::Scene & scn); +}; diff --git a/game/menus/mainmenu/CreditsSubScript.cpp b/game/menus/mainmenu/CreditsSubScript.cpp new file mode 100644 index 0000000..ce74ba4 --- /dev/null +++ b/game/menus/mainmenu/CreditsSubScript.cpp @@ -0,0 +1,60 @@ +#include "CreditsSubScript.h" + +#include "../../Events.h" +#include "../IFloatingWindowScript.h" +#include "../ButtonReplaySubScript.h" + +#include <string> + +#include <crepe/api/Button.h> +#include <crepe/api/Sprite.h> +#include <crepe/api/Text.h> +#include <crepe/types.h> + +using namespace crepe; + + +CreditsSubScript::CreditsSubScript(const std::string & tag) { this->tag = tag; } + +void CreditsSubScript::init() { +	IButtonScript::init(); +	this->subscribe<ButtonPressEvent>([this](const ButtonPressEvent & e) { +		return this->on_button_press(e); +	}); +	this->subscribe<ShowCreditsEvent>([this](const ShowCreditsEvent & e) { +		this->enable_all(); +		return false; +	}); +	this->disable_all(); +} + +bool CreditsSubScript::disable_all() { +	IFloatingWindowScript::disable_all_sprites(); +	RefVector<Button> buttons = this->get_components_by_tag<Button>(this->tag); +	for (Button & button : buttons) { +		button.active = false; +	} +	RefVector<Text> texts = this->get_components_by_tag<Text>(this->tag); +	for (Text & text : texts) { +		text.active = false; +	} +	return false; +} + +bool CreditsSubScript::enable_all() { +	IFloatingWindowScript::enable_all_sprites(); +	RefVector<Button> buttons = this->get_components_by_tag<Button>(this->tag); +	for (Button & button : buttons) { +		button.active = true; +	} +	RefVector<Text> texts = this->get_components_by_tag<Text>(this->tag); +	for (Text & text : texts) { +		text.active = true; +	} +	return false; +} + +bool CreditsSubScript::on_button_press(const ButtonPressEvent & e) { +	return this->disable_all(); +} + diff --git a/game/menus/mainmenu/CreditsSubScript.h b/game/menus/mainmenu/CreditsSubScript.h new file mode 100644 index 0000000..e411202 --- /dev/null +++ b/game/menus/mainmenu/CreditsSubScript.h @@ -0,0 +1,18 @@ +#pragma once + +#include "../IFloatingWindowScript.h" +#include "../IButtonScript.h" + +#include <crepe/api/Event.h> +#include <crepe/api/Script.h> + +struct ShowCreditsEvent : public crepe::Event {}; + +class CreditsSubScript : public IFloatingWindowScript, public IButtonScript { +public: +	CreditsSubScript(const std::string & tag); +	void init() override; +	bool disable_all(); +	bool enable_all(); +	bool on_button_press(const crepe::ButtonPressEvent & e); +}; diff --git a/game/menus/mainmenu/MainMenuScene.cpp b/game/menus/mainmenu/MainMenuScene.cpp index 43418e3..fba90ac 100644 --- a/game/menus/mainmenu/MainMenuScene.cpp +++ b/game/menus/mainmenu/MainMenuScene.cpp @@ -1,5 +1,6 @@  #include "MainMenuScene.h" +#include "CreditsSubScene.h"  #include "MainMenuConfig.h"  #include "TransitionStartSubScript.h" @@ -64,7 +65,7 @@ void MainMenuScene::load_scene() {  		ButtonSubScene::Data {  			.text = "SHOP",  			.text_offset = {-20, 0}, -			.text_width = 115, +			.text_width = 110,  			.icon_offset = {60, 0},  			.icon_type = ButtonSubScene::IconSelect::SHOP,  			.position = pos_btn, @@ -72,6 +73,19 @@ void MainMenuScene::load_scene() {  		}  	); +	//Credits btn +	pos_btn.y += MENU_BUTTON_SPACING + LARGE_OVERLAY_SIZE.y; +	button.create( +		*this, +		ButtonSubScene::Data { +			.text = "CREDITS", +			.text_offset = {0, 0}, +			.text_width = 200, +			.position = pos_btn, +			.script_type = ButtonSubScene::ScriptSelect::CREDITS_SHOW, +		} +	); +  	//Start of map  	StartSubScene start;  	HallwaySubScene hallway; @@ -110,6 +124,9 @@ void MainMenuScene::load_scene() {  			.tag = MENU_INFO_TAG,  		}  	); + +	CreditsSubScene creditscene; +	creditscene.create(*this);  }  string MainMenuScene::get_name() const { return MAINMENU_SCENE; } diff --git a/src/crepe/api/Sprite.cpp b/src/crepe/api/Sprite.cpp index 0107c7b..2919857 100644 --- a/src/crepe/api/Sprite.cpp +++ b/src/crepe/api/Sprite.cpp @@ -19,3 +19,18 @@ Sprite::Sprite(game_object_id_t id, const Asset & texture, const Sprite::Data &  }  Sprite::~Sprite() { dbg_trace(); } + +unique_ptr<Component> Sprite::save() const { +	return unique_ptr<Component>(new Sprite(*this)); +} + +void Sprite::restore(const Component & snapshot) { +	*this = static_cast<const Sprite &>(snapshot); +} + +Sprite & Sprite::operator=(const Sprite & snapshot) { +	this->active = snapshot.active; +	this->data = snapshot.data; +	this->mask = snapshot.mask; +	return *this; +} diff --git a/src/crepe/api/Sprite.h b/src/crepe/api/Sprite.h index a3fc319..3565bed 100644 --- a/src/crepe/api/Sprite.h +++ b/src/crepe/api/Sprite.h @@ -42,10 +42,10 @@ public:  		FlipSettings flip;  		//! Layer sorting level of the sprite -		const int sorting_in_layer = 0; +		int sorting_in_layer = 0;  		//! Order within the sorting layer -		const int order_in_layer = 0; +		int order_in_layer = 0;  		/**  		 * \brief width and height of the sprite in game units @@ -119,6 +119,12 @@ private:  	//! Render area of the sprite this will also be adjusted by the AnimatorSystem if an Animator  	// object is present in GameObject. this is in sprite pixels  	Rect mask; + +protected: +	virtual std::unique_ptr<Component> save() const; +	Sprite(const Sprite &) = default; +	virtual void restore(const Component & snapshot); +	virtual Sprite & operator=(const Sprite &);  };  } // namespace crepe  |