diff options
Diffstat (limited to 'game/menus/mainmenu')
-rw-r--r-- | game/menus/mainmenu/ButtonTransitionPreviewSubScript.cpp | 23 | ||||
-rw-r--r-- | game/menus/mainmenu/ButtonTransitionPreviewSubScript.h | 12 | ||||
-rw-r--r-- | game/menus/mainmenu/CreditsSubScene.cpp | 132 | ||||
-rw-r--r-- | game/menus/mainmenu/CreditsSubScene.h | 9 | ||||
-rw-r--r-- | game/menus/mainmenu/CreditsSubScript.cpp | 58 | ||||
-rw-r--r-- | game/menus/mainmenu/CreditsSubScript.h | 18 | ||||
-rw-r--r-- | game/menus/mainmenu/ITransitionScript.cpp | 30 | ||||
-rw-r--r-- | game/menus/mainmenu/ITransitionScript.h | 15 | ||||
-rw-r--r-- | game/menus/mainmenu/MainMenuConfig.h | 19 | ||||
-rw-r--r-- | game/menus/mainmenu/MainMenuScene.cpp | 137 | ||||
-rw-r--r-- | game/menus/mainmenu/MainMenuScene.h | 10 | ||||
-rw-r--r-- | game/menus/mainmenu/TransitionStartSubScript.cpp | 16 | ||||
-rw-r--r-- | game/menus/mainmenu/TransitionStartSubScript.h | 9 |
13 files changed, 488 insertions, 0 deletions
diff --git a/game/menus/mainmenu/ButtonTransitionPreviewSubScript.cpp b/game/menus/mainmenu/ButtonTransitionPreviewSubScript.cpp new file mode 100644 index 0000000..4c4dfc1 --- /dev/null +++ b/game/menus/mainmenu/ButtonTransitionPreviewSubScript.cpp @@ -0,0 +1,23 @@ +#include "ButtonTransitionPreviewSubScript.h" + +#include "../MenusConfig.h" + +using namespace crepe; +using namespace std; + +void ButtonTransitionPreviewSubScript::init() { + IButtonScript::init(); + this->subscribe<ButtonPressEvent>([this](const ButtonPressEvent & e) { + return this->on_button_press(e); + }); +} + +bool ButtonTransitionPreviewSubScript::on_button_press(const ButtonPressEvent & e) { + if (!this->transition) this->transition = true; + return false; +} + +const char * ButtonTransitionPreviewSubScript::get_scene_name() const { + // Provide the next scene defined in MainMenuConfig + return PREVIEW_SCENE; +} diff --git a/game/menus/mainmenu/ButtonTransitionPreviewSubScript.h b/game/menus/mainmenu/ButtonTransitionPreviewSubScript.h new file mode 100644 index 0000000..d6d8149 --- /dev/null +++ b/game/menus/mainmenu/ButtonTransitionPreviewSubScript.h @@ -0,0 +1,12 @@ +#pragma once + +#include "ITransitionScript.h" + +#include "../IButtonScript.h" + +class ButtonTransitionPreviewSubScript : public ITransitionScript, public IButtonScript { +public: + void init() override; + bool on_button_press(const crepe::ButtonPressEvent & e); + const char * get_scene_name() const override; +}; diff --git a/game/menus/mainmenu/CreditsSubScene.cpp b/game/menus/mainmenu/CreditsSubScene.cpp new file mode 100644 index 0000000..65576ee --- /dev/null +++ b/game/menus/mainmenu/CreditsSubScene.cpp @@ -0,0 +1,132 @@ + +#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, + } + ); + + const float SIZE_CHAR_NAMES = 10; + const float Y_OFFSET_NAMES_BEGIN = 100; + const float Y_OFFSET_NAMES = 30; + const string LOEK = "Loek Le Blansch"; + crepe::vec2 size_loek + = {LOEK.size() * SIZE_CHAR_NAMES, (LOEK.size() * SIZE_CHAR_NAMES / LOEK.size()) * 2}; + titel.add_component<Text>( + size_loek, FONT, + Text::Data { + .world_space = false, + .text_color = Color::WHITE, + }, + vec2 {150, -207 + Y_OFFSET_NAMES + Y_OFFSET_NAMES_BEGIN} + FONTOFFSET, LOEK + ); + + const string WOUTER = "Wouter Boerenkamps"; + crepe::vec2 size_wouter + = {WOUTER.size() * SIZE_CHAR_NAMES, + (WOUTER.size() * SIZE_CHAR_NAMES / WOUTER.size()) * 2}; + titel.add_component<Text>( + size_wouter, FONT, + Text::Data { + .world_space = false, + .text_color = Color::WHITE, + }, + vec2 {150, -207 + Y_OFFSET_NAMES * 2 + Y_OFFSET_NAMES_BEGIN} + FONTOFFSET, WOUTER + ); + + const string JARO = "Jaro Rutjes"; + crepe::vec2 size_jaro + = {JARO.size() * SIZE_CHAR_NAMES, (JARO.size() * SIZE_CHAR_NAMES / JARO.size()) * 2}; + titel.add_component<Text>( + size_jaro, FONT, + Text::Data { + .world_space = false, + .text_color = Color::WHITE, + }, + vec2 {150, -207 + Y_OFFSET_NAMES * 3 + Y_OFFSET_NAMES_BEGIN} + FONTOFFSET, JARO + ); + + const string MAX = "Max Smits"; + crepe::vec2 size_max + = {MAX.size() * SIZE_CHAR_NAMES, (MAX.size() * SIZE_CHAR_NAMES / MAX.size()) * 2}; + titel.add_component<Text>( + size_max, FONT, + Text::Data { + .world_space = false, + .text_color = Color::WHITE, + }, + vec2 {150, -207 + Y_OFFSET_NAMES * 4 + Y_OFFSET_NAMES_BEGIN} + FONTOFFSET, MAX + ); + + const string NIELS = "Niels Stunnebrink"; + crepe::vec2 size_niels + = {NIELS.size() * SIZE_CHAR_NAMES, (NIELS.size() * SIZE_CHAR_NAMES / NIELS.size()) * 2 + }; + titel.add_component<Text>( + size_niels, FONT, + Text::Data { + .world_space = false, + .text_color = Color::WHITE, + }, + vec2 {150, -207 + Y_OFFSET_NAMES * 5 + Y_OFFSET_NAMES_BEGIN} + FONTOFFSET, NIELS + ); +} 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..4224dc8 --- /dev/null +++ b/game/menus/mainmenu/CreditsSubScript.cpp @@ -0,0 +1,58 @@ +#include "CreditsSubScript.h" + +#include "../../Events.h" +#include "../ButtonReplaySubScript.h" +#include "../IFloatingWindowScript.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..81f941a --- /dev/null +++ b/game/menus/mainmenu/CreditsSubScript.h @@ -0,0 +1,18 @@ +#pragma once + +#include "../IButtonScript.h" +#include "../IFloatingWindowScript.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/ITransitionScript.cpp b/game/menus/mainmenu/ITransitionScript.cpp new file mode 100644 index 0000000..54b0875 --- /dev/null +++ b/game/menus/mainmenu/ITransitionScript.cpp @@ -0,0 +1,30 @@ +#include "ITransitionScript.h" +#include "MainMenuConfig.h" + +#include "../../Config.h" +#include "../MenusConfig.h" + +#include <crepe/api/Camera.h> +#include <crepe/api/Transform.h> +#include <crepe/types.h> + +using namespace crepe; +using namespace std; + +void ITransitionScript::frame_update(crepe::duration_t delta_time) { + if (this->transition) { + // cout << "transition:" << velocity << std::endl; + Transform & cam = this->get_components_by_name<Transform>(CAMERA_NAME).front(); + RefVector<Transform> info_tf = this->get_components_by_tag<Transform>(MENU_INFO_TAG); + for (Transform & tf : info_tf) { + tf.position.y -= VELOCITY_INFO_UP * delta_time.count(); + } + if (velocity < VELOCITY_MAX && cam.position.x < SLOW_DOWN) + velocity += VELOCITY_STEP * delta_time.count(); + else if (velocity > 20) velocity -= VELOCITY_STEP * delta_time.count(); + if (cam.position.x < END) cam.position.x += (velocity * delta_time.count()); + if (cam.position.x >= END) { + this->set_next_scene(this->get_scene_name()); + } + } +} diff --git a/game/menus/mainmenu/ITransitionScript.h b/game/menus/mainmenu/ITransitionScript.h new file mode 100644 index 0000000..9a2ef90 --- /dev/null +++ b/game/menus/mainmenu/ITransitionScript.h @@ -0,0 +1,15 @@ +#pragma once + +#include <crepe/api/Script.h> + +class ITransitionScript : public virtual crepe::Script { +public: + void frame_update(crepe::duration_t delta_time) override; + virtual const char * get_scene_name() const = 0; + +private: + float velocity = 20; + +protected: + bool transition = false; +}; diff --git a/game/menus/mainmenu/MainMenuConfig.h b/game/menus/mainmenu/MainMenuConfig.h new file mode 100644 index 0000000..f4ca5a6 --- /dev/null +++ b/game/menus/mainmenu/MainMenuConfig.h @@ -0,0 +1,19 @@ +#pragma once +#include <crepe/types.h> + +//main menu config +static constexpr float STARTMAP_OFFSET = 50; +static constexpr crepe::vec2 MENU_OFFSET = {0, 0}; +static constexpr float MENU_BUTTON_SPACING = 10; +static constexpr const char * MENU_BUTTON_NAME = "menu_button_background"; +static constexpr crepe::vec2 MENU_OFFSET_BUTTON = {-400, -200}; +static constexpr crepe::vec2 MENU_OFFSET_BUTTON_BACKGROUND = {-400, 0}; +static constexpr const char * MENU_INFO_TAG = "menu_info"; +static constexpr crepe::vec2 MENU_OFFSET_INFO = {350, -365}; +static constexpr crepe::vec2 MENU_OFFSET_INFO_BACKGROUND = {350, -365}; //375 +//Moving to new scene (Start and Preview) +static constexpr float SLOW_DOWN = 200; +static constexpr float END = 300; +static constexpr float VELOCITY_MAX = 200; +static constexpr float VELOCITY_STEP = 200; +static constexpr float VELOCITY_INFO_UP = 40; diff --git a/game/menus/mainmenu/MainMenuScene.cpp b/game/menus/mainmenu/MainMenuScene.cpp new file mode 100644 index 0000000..c5d2030 --- /dev/null +++ b/game/menus/mainmenu/MainMenuScene.cpp @@ -0,0 +1,137 @@ + +#include "MainMenuScene.h" +#include "CreditsSubScene.h" +#include "MainMenuConfig.h" +#include "QuitScript.h" +#include "TransitionStartSubScript.h" + +#include "../ButtonSubScene.h" +#include "../MenusConfig.h" + +#include "../../Config.h" +#include "../../background/HallwaySubScene.h" +#include "../../background/StartSubScene.h" + +#include "../endgame/EndGameSubScene.h" + +#include <crepe/api/BehaviorScript.h> +#include <crepe/api/Camera.h> +#include <crepe/api/GameObject.h> +#include <crepe/api/Sprite.h> +#include <crepe/manager/SaveManager.h> + +using namespace crepe; +using namespace std; + +void MainMenuScene::load_scene() { + ButtonSubScene button; + + GameObject camera_object = this->new_object(CAMERA_NAME); + camera_object.add_component<Camera>( + ivec2(990, 720), vec2(1100, 800), + Camera::Data { + .bg_color = Color::BLACK, + } + ); + camera_object.add_component<BehaviorScript>().set_script<TransitionStartSubScript>(); + camera_object.add_component<BehaviorScript>().set_script<QuitScript>(); + + //Button menu + GameObject menu_button = this->new_object(MENU_BUTTON_NAME, MENU_BUTTON_NAME, MENU_OFFSET); + menu_button.add_component<Sprite>( + Asset("asset/ui/background.png"), + Sprite::Data { + .sorting_in_layer = STARTING_SORTING_IN_LAYER + 0, + .size = {300, 860}, + .position_offset = MENU_OFFSET_BUTTON_BACKGROUND, + } + ); + + vec2 pos_btn = MENU_OFFSET_BUTTON; + + //Preview btn + button.create( + *this, + ButtonSubScene::Data { + .text = "PREVIEW", + .text_width = 200, + .position = pos_btn, + .script_type = ButtonSubScene::ScriptSelect::PREVIEW, + .btn_side_color = ButtonSubScene::ButtonSideColor::PURPLE, + } + ); + + //Shop btn + pos_btn.y += MENU_BUTTON_SPACING + LARGE_OVERLAY_SIZE.y; + button.create( + *this, + ButtonSubScene::Data { + .text = "SHOP", + .text_offset = {-20, 0}, + .text_width = 110, + .icon_offset = {60, 0}, + .icon_type = ButtonSubScene::IconSelect::SHOP, + .position = pos_btn, + .script_type = ButtonSubScene::ScriptSelect::SHOP, + .btn_side_color = ButtonSubScene::ButtonSideColor::ORANGE, + } + ); + + //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, + .btn_side_color = ButtonSubScene::ButtonSideColor::BLUE, + } + ); + + //Start of map + StartSubScene start; + HallwaySubScene hallway; + float begin_x = start.create(*this, STARTMAP_OFFSET); + begin_x = hallway.create(*this, begin_x, 1, Color::YELLOW); + + //INFO menu + GameObject menu_info + = this->new_object("MENU_INFO_BACKGROUND", MENU_INFO_TAG, MENU_OFFSET); + menu_info.add_component<Sprite>( + Asset("asset/ui/itemsButtonBlankDark.png"), + Sprite::Data { + .sorting_in_layer = STARTING_SORTING_IN_LAYER + 0, + .size = {250, 80}, + .position_offset = MENU_OFFSET_INFO, + .world_space = false, + } + ); + SaveManager & savemgr = this->get_save_manager(); + string number = std::to_string(savemgr.get<int>(TOTAL_COINS_GAME, 0).get()); + float amount_number = static_cast<float>(number.size()); + // savemgr.set(COIN_GAME_AMOUNT, amount); + button.create( + *this, + ButtonSubScene::Data { + .text = number, + .text_offset = {-10 - (amount_number - 1) * 10, 0}, + .text_width = amount_number * 20, + .icon_offset = {60, 0}, + .icon_type = ButtonSubScene::IconSelect::COINS, + .position = MENU_OFFSET_INFO, + .script_type = ButtonSubScene::ScriptSelect::SHOP, + .scale = 0.6, + .worldspace = false, + .color_side = false, + .tag = MENU_INFO_TAG, + } + ); + + CreditsSubScene creditscene; + creditscene.create(*this); +} + +string MainMenuScene::get_name() const { return MAINMENU_SCENE; } diff --git a/game/menus/mainmenu/MainMenuScene.h b/game/menus/mainmenu/MainMenuScene.h new file mode 100644 index 0000000..1eea90e --- /dev/null +++ b/game/menus/mainmenu/MainMenuScene.h @@ -0,0 +1,10 @@ +#pragma once + +#include <crepe/api/Scene.h> +#include <string> + +class MainMenuScene : public crepe::Scene { +public: + void load_scene(); + std::string get_name() const; +}; diff --git a/game/menus/mainmenu/TransitionStartSubScript.cpp b/game/menus/mainmenu/TransitionStartSubScript.cpp new file mode 100644 index 0000000..f737f7f --- /dev/null +++ b/game/menus/mainmenu/TransitionStartSubScript.cpp @@ -0,0 +1,16 @@ +#include "TransitionStartSubScript.h" + +#include "../MenusConfig.h" + +using namespace crepe; +using namespace std; + +void TransitionStartSubScript::fixed_update(crepe::duration_t dt) { + if (this->get_key_state(Keycode::SPACE) && this->transition == false) + this->transition = true; +} + +const char * TransitionStartSubScript::get_scene_name() const { + // Provide the next scene defined in MainMenuConfig + return START_SCENE; +} diff --git a/game/menus/mainmenu/TransitionStartSubScript.h b/game/menus/mainmenu/TransitionStartSubScript.h new file mode 100644 index 0000000..f9862ea --- /dev/null +++ b/game/menus/mainmenu/TransitionStartSubScript.h @@ -0,0 +1,9 @@ +#pragma once + +#include "ITransitionScript.h" + +class TransitionStartSubScript : public ITransitionScript { +public: + void fixed_update(crepe::duration_t dt) override; + const char * get_scene_name() const override; +}; |