From 07615060da6c211e08a3d7f2e1bb9e99ffc05364 Mon Sep 17 00:00:00 2001 From: JAROWMR Date: Mon, 6 Jan 2025 17:49:39 +0100 Subject: moved and updated files --- .../mainmenu/ButtonTransitionPreviewScript.cpp | 24 ++++++ .../menus/mainmenu/ButtonTransitionPreviewScript.h | 11 +++ game/menus/mainmenu/ITransitionScript.cpp | 30 +++++++ game/menus/mainmenu/ITransitionScript.h | 13 +++ game/menus/mainmenu/MainMenuConfig.h | 22 +++++ game/menus/mainmenu/MainMenuScene.cpp | 99 ++++++++++++++++++++++ game/menus/mainmenu/MainMenuScene.h | 11 +++ game/menus/mainmenu/TransitionStartScript.cpp | 20 +++++ game/menus/mainmenu/TransitionStartScript.h | 10 +++ 9 files changed, 240 insertions(+) create mode 100644 game/menus/mainmenu/ButtonTransitionPreviewScript.cpp create mode 100644 game/menus/mainmenu/ButtonTransitionPreviewScript.h create mode 100644 game/menus/mainmenu/ITransitionScript.cpp create mode 100644 game/menus/mainmenu/ITransitionScript.h create mode 100644 game/menus/mainmenu/MainMenuConfig.h create mode 100644 game/menus/mainmenu/MainMenuScene.cpp create mode 100644 game/menus/mainmenu/MainMenuScene.h create mode 100644 game/menus/mainmenu/TransitionStartScript.cpp create mode 100644 game/menus/mainmenu/TransitionStartScript.h (limited to 'game/menus/mainmenu') diff --git a/game/menus/mainmenu/ButtonTransitionPreviewScript.cpp b/game/menus/mainmenu/ButtonTransitionPreviewScript.cpp new file mode 100644 index 0000000..c702260 --- /dev/null +++ b/game/menus/mainmenu/ButtonTransitionPreviewScript.cpp @@ -0,0 +1,24 @@ +#include "ButtonTransitionPreviewScript.h" +#include "../MenusConfig.h" +#include "iostream" + +using namespace crepe; +using namespace std; + + +void ButtonTransitionPreviewScript::init(){ + cout << "script init" << endl; + IButtonScript::init(); + this->subscribe([this](const ButtonPressEvent& e) { return this->on_button_press(e); }); +} + +bool ButtonTransitionPreviewScript::on_button_press(const ButtonPressEvent& e){ + if(!this->transition) this->transition = true; + cout << "Start triggered:" << e.metadata.game_object_id << std::endl; + return false; +} + +const char* ButtonTransitionPreviewScript::get_scene_name() const { + // Provide the next scene defined in MainMenuConfig + return PREVIEW_SCENE; +} diff --git a/game/menus/mainmenu/ButtonTransitionPreviewScript.h b/game/menus/mainmenu/ButtonTransitionPreviewScript.h new file mode 100644 index 0000000..26a778a --- /dev/null +++ b/game/menus/mainmenu/ButtonTransitionPreviewScript.h @@ -0,0 +1,11 @@ +#pragma once + +#include "../IButtonScript.h" +#include "ITransitionScript.h" + +class ButtonTransitionPreviewScript : 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/ITransitionScript.cpp b/game/menus/mainmenu/ITransitionScript.cpp new file mode 100644 index 0000000..07360a0 --- /dev/null +++ b/game/menus/mainmenu/ITransitionScript.cpp @@ -0,0 +1,30 @@ +#include "ITransitionScript.h" +#include "api/Transform.h" +#include +#include "MainMenuConfig.h" +#include "../MenusConfig.h" +#include "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(CAMERA_NAME).front(); + RefVector info_tf = this->get_components_by_tag(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..78f1016 --- /dev/null +++ b/game/menus/mainmenu/ITransitionScript.h @@ -0,0 +1,13 @@ +#pragma once + +#include + +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..7227f84 --- /dev/null +++ b/game/menus/mainmenu/MainMenuConfig.h @@ -0,0 +1,22 @@ +#pragma once +#include "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..f6f8220 --- /dev/null +++ b/game/menus/mainmenu/MainMenuScene.cpp @@ -0,0 +1,99 @@ + +#include "MainMenuScene.h" +#include "../ButtonSubScene.h" +#include "TransitionStartScript.h" +#include "api/BehaviorScript.h" +#include "api/Camera.h" +#include "../../background/StartSubScene.h" +#include "../../background/HallwaySubScene.h" +#include "MainMenuConfig.h" +#include "api/GameObject.h" +#include "api/Sprite.h" +#include "manager/SaveManager.h" +#include "../../Config.h" +#include "../MenusConfig.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(ivec2(990, 720), vec2(1100, 800), + Camera::Data{ + .bg_color = Color::RED, + }); + camera_object.add_component().set_script(); + + + //Button menu + GameObject menu_button = this->new_object(MENU_BUTTON_NAME,MENU_BUTTON_NAME,MENU_OFFSET); + menu_button.add_component( + 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, + }); + + //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 = 115, + .icon_offset = {60,0}, + .icon_type = ButtonSubScene::IconSelect::SHOP, + .position = pos_btn, + .script_type = ButtonSubScene::ScriptSelect::SHOP, + }); + + //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( + 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(TOTAL_COINS_GAME,0).get()); + float amount_number = static_cast(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, + }); + +} + +string MainMenuScene::get_name() const { return "mainmenu"; } diff --git a/game/menus/mainmenu/MainMenuScene.h b/game/menus/mainmenu/MainMenuScene.h new file mode 100644 index 0000000..f7319cb --- /dev/null +++ b/game/menus/mainmenu/MainMenuScene.h @@ -0,0 +1,11 @@ +#pragma once + +#include +#include + +class MainMenuScene : public crepe::Scene { +public: + void load_scene(); + + std::string get_name() const; +}; diff --git a/game/menus/mainmenu/TransitionStartScript.cpp b/game/menus/mainmenu/TransitionStartScript.cpp new file mode 100644 index 0000000..d03adf0 --- /dev/null +++ b/game/menus/mainmenu/TransitionStartScript.cpp @@ -0,0 +1,20 @@ +#include "TransitionStartScript.h" +#include "../MenusConfig.h" +#include "iostream" + +using namespace crepe; +using namespace std; + + +void TransitionStartScript::init(){ + cout << "script init" << endl; +} + +void TransitionStartScript::fixed_update(crepe::duration_t dt){ + if(this->get_key_state(Keycode::ENTER) && this->transition == false) this->transition = true; +} + +const char* TransitionStartScript::get_scene_name() const { + // Provide the next scene defined in MainMenuConfig + return START_SCENE; +} diff --git a/game/menus/mainmenu/TransitionStartScript.h b/game/menus/mainmenu/TransitionStartScript.h new file mode 100644 index 0000000..76f532e --- /dev/null +++ b/game/menus/mainmenu/TransitionStartScript.h @@ -0,0 +1,10 @@ +#pragma once + +#include "ITransitionScript.h" + +class TransitionStartScript : public ITransitionScript { +public: + void init() override; + void fixed_update(crepe::duration_t dt) override; + const char* get_scene_name() const override; +}; -- cgit v1.2.3 From 4c83562ef39a0364cd01f1f3615eb7672ca9f4a2 Mon Sep 17 00:00:00 2001 From: JAROWMR Date: Mon, 6 Jan 2025 17:57:50 +0100 Subject: corrected includes --- game/menus/BannerSubScene.cpp | 2 +- game/menus/BannerSubScene.h | 2 +- game/menus/ButtonSetMainMenuScript.cpp | 3 --- game/menus/ButtonSetMainMenuScript.h | 1 + game/menus/ButtonSetShopScript.cpp | 3 --- game/menus/ButtonSetShopScript.h | 1 + game/menus/ButtonSubScene.cpp | 8 +++++--- game/menus/ButtonSubScene.h | 1 + game/menus/IButtonScript.cpp | 12 +++++------- game/menus/MenusConfig.h | 3 +-- game/menus/mainmenu/ButtonTransitionPreviewScript.cpp | 5 +---- game/menus/mainmenu/ButtonTransitionPreviewScript.h | 3 ++- game/menus/mainmenu/ITransitionScript.cpp | 8 +++++--- game/menus/mainmenu/MainMenuConfig.h | 2 +- game/menus/mainmenu/MainMenuScene.cpp | 19 +++++++++++-------- game/menus/mainmenu/MainMenuScene.h | 1 - game/menus/mainmenu/TransitionStartScript.cpp | 7 +------ game/menus/mainmenu/TransitionStartScript.h | 1 - game/menus/shop/ShopMenuScene.cpp | 6 ++++-- game/menus/shop/ShopMenuScene.h | 3 ++- 20 files changed, 43 insertions(+), 48 deletions(-) (limited to 'game/menus/mainmenu') diff --git a/game/menus/BannerSubScene.cpp b/game/menus/BannerSubScene.cpp index 638b330..ea43c69 100644 --- a/game/menus/BannerSubScene.cpp +++ b/game/menus/BannerSubScene.cpp @@ -1,7 +1,7 @@ #include "BannerSubScene.h" #include "MenusConfig.h" -#include "../Config.h" +#include "../Config.h" #include #include diff --git a/game/menus/BannerSubScene.h b/game/menus/BannerSubScene.h index 341943d..888897d 100644 --- a/game/menus/BannerSubScene.h +++ b/game/menus/BannerSubScene.h @@ -1,6 +1,6 @@ #pragma once -#include "types.h" +#include #include namespace crepe { diff --git a/game/menus/ButtonSetMainMenuScript.cpp b/game/menus/ButtonSetMainMenuScript.cpp index 74773a0..12b7256 100644 --- a/game/menus/ButtonSetMainMenuScript.cpp +++ b/game/menus/ButtonSetMainMenuScript.cpp @@ -1,19 +1,16 @@ #include "ButtonSetMainMenuScript.h" #include "MenusConfig.h" -#include "iostream" using namespace crepe; using namespace std; void ButtonSetMainMenuScript::init(){ - cout << "script init" << endl; IButtonScript::init(); this->subscribe([this](const ButtonPressEvent& e) { return this->on_button_press(e); }); } bool ButtonSetMainMenuScript::on_button_press(const ButtonPressEvent& e){ this->set_next_scene(MAINMENU_SCENE); - cout << "Start triggered:" << e.metadata.game_object_id << std::endl; return false; } diff --git a/game/menus/ButtonSetMainMenuScript.h b/game/menus/ButtonSetMainMenuScript.h index 44c21aa..13a33bf 100644 --- a/game/menus/ButtonSetMainMenuScript.h +++ b/game/menus/ButtonSetMainMenuScript.h @@ -1,6 +1,7 @@ #pragma once #include "IButtonScript.h" + #include class ButtonSetMainMenuScript : public IButtonScript { diff --git a/game/menus/ButtonSetShopScript.cpp b/game/menus/ButtonSetShopScript.cpp index 035419f..88639bd 100644 --- a/game/menus/ButtonSetShopScript.cpp +++ b/game/menus/ButtonSetShopScript.cpp @@ -1,19 +1,16 @@ #include "ButtonSetShopScript.h" -#include "iostream" #include "MenusConfig.h" using namespace crepe; using namespace std; void ButtonSetShopScript::init(){ - cout << "script init" << endl; IButtonScript::init(); this->subscribe([this](const ButtonPressEvent& e) { return this->on_button_press(e); }); } bool ButtonSetShopScript::on_button_press(const ButtonPressEvent& e){ this->set_next_scene(SHOP_SCENE); - cout << "Start triggered:" << e.metadata.game_object_id << std::endl; return false; } diff --git a/game/menus/ButtonSetShopScript.h b/game/menus/ButtonSetShopScript.h index 51db928..434abc0 100644 --- a/game/menus/ButtonSetShopScript.h +++ b/game/menus/ButtonSetShopScript.h @@ -1,6 +1,7 @@ #pragma once #include "IButtonScript.h" + #include class ButtonSetShopScript : public IButtonScript { diff --git a/game/menus/ButtonSubScene.cpp b/game/menus/ButtonSubScene.cpp index 3d68657..6aad352 100644 --- a/game/menus/ButtonSubScene.cpp +++ b/game/menus/ButtonSubScene.cpp @@ -1,17 +1,19 @@ #include "ButtonSubScene.h" #include "ButtonSetMainMenuScript.h" #include "ButtonSetShopScript.h" -#include "mainmenu/ButtonTransitionPreviewScript.h" #include "IButtonScript.h" -#include "../Config.h" -#include "api/Color.h" #include "MenusConfig.h" +#include "mainmenu/ButtonTransitionPreviewScript.h" + +#include "../Config.h" + #include #include #include #include #include +#include using namespace crepe; using namespace std; diff --git a/game/menus/ButtonSubScene.h b/game/menus/ButtonSubScene.h index 06006ac..5609ecb 100644 --- a/game/menus/ButtonSubScene.h +++ b/game/menus/ButtonSubScene.h @@ -1,6 +1,7 @@ #pragma once #include + #include namespace crepe { diff --git a/game/menus/IButtonScript.cpp b/game/menus/IButtonScript.cpp index ab907c4..da535ca 100644 --- a/game/menus/IButtonScript.cpp +++ b/game/menus/IButtonScript.cpp @@ -1,13 +1,14 @@ #include "IButtonScript.h" -#include "api/Sprite.h" -#include "iostream" + #include "system/InputSystem.h" -#include "types.h" + +#include +#include + using namespace crepe; using namespace std; void IButtonScript::init(){ - cout << "script init" << endl; this->subscribe([this](const ButtonExitEvent& e) { return this->on_button_exit(e); }); this->subscribe([this](const ButtonEnterEvent& e) { return this->on_button_enter(e); }); } @@ -17,8 +18,6 @@ bool IButtonScript::on_button_exit(const ButtonExitEvent& e){ { sprite.data.color = Color{255,255,255,255}; } - - cout << "button triggered:" << e.metadata.game_object_id << std::endl; return false; } bool IButtonScript::on_button_enter(const ButtonEnterEvent& e){ @@ -27,7 +26,6 @@ bool IButtonScript::on_button_enter(const ButtonEnterEvent& e){ { sprite.data.color = Color{200,200,200,255}; } - cout << "button Enter:" << e.metadata.game_object_id << std::endl; return false; } diff --git a/game/menus/MenusConfig.h b/game/menus/MenusConfig.h index 692a4d2..ffcbc34 100644 --- a/game/menus/MenusConfig.h +++ b/game/menus/MenusConfig.h @@ -1,6 +1,5 @@ #pragma once -#include "types.h" - +#include //generic menu config static constexpr unsigned int STARTING_SORTING_IN_LAYER = 7; diff --git a/game/menus/mainmenu/ButtonTransitionPreviewScript.cpp b/game/menus/mainmenu/ButtonTransitionPreviewScript.cpp index c702260..084d02b 100644 --- a/game/menus/mainmenu/ButtonTransitionPreviewScript.cpp +++ b/game/menus/mainmenu/ButtonTransitionPreviewScript.cpp @@ -1,20 +1,17 @@ #include "ButtonTransitionPreviewScript.h" + #include "../MenusConfig.h" -#include "iostream" using namespace crepe; using namespace std; - void ButtonTransitionPreviewScript::init(){ - cout << "script init" << endl; IButtonScript::init(); this->subscribe([this](const ButtonPressEvent& e) { return this->on_button_press(e); }); } bool ButtonTransitionPreviewScript::on_button_press(const ButtonPressEvent& e){ if(!this->transition) this->transition = true; - cout << "Start triggered:" << e.metadata.game_object_id << std::endl; return false; } diff --git a/game/menus/mainmenu/ButtonTransitionPreviewScript.h b/game/menus/mainmenu/ButtonTransitionPreviewScript.h index 26a778a..5973dbf 100644 --- a/game/menus/mainmenu/ButtonTransitionPreviewScript.h +++ b/game/menus/mainmenu/ButtonTransitionPreviewScript.h @@ -1,8 +1,9 @@ #pragma once -#include "../IButtonScript.h" #include "ITransitionScript.h" +#include "../IButtonScript.h" + class ButtonTransitionPreviewScript : public ITransitionScript, public IButtonScript { public: void init() override; diff --git a/game/menus/mainmenu/ITransitionScript.cpp b/game/menus/mainmenu/ITransitionScript.cpp index 07360a0..9e547e6 100644 --- a/game/menus/mainmenu/ITransitionScript.cpp +++ b/game/menus/mainmenu/ITransitionScript.cpp @@ -1,9 +1,11 @@ #include "ITransitionScript.h" -#include "api/Transform.h" -#include #include "MainMenuConfig.h" + #include "../MenusConfig.h" -#include "types.h" + +#include +#include +#include using namespace crepe; using namespace std; diff --git a/game/menus/mainmenu/MainMenuConfig.h b/game/menus/mainmenu/MainMenuConfig.h index 7227f84..01995f0 100644 --- a/game/menus/mainmenu/MainMenuConfig.h +++ b/game/menus/mainmenu/MainMenuConfig.h @@ -1,5 +1,5 @@ #pragma once -#include "types.h" +#include //main menu config static constexpr float STARTMAP_OFFSET = 50; diff --git a/game/menus/mainmenu/MainMenuScene.cpp b/game/menus/mainmenu/MainMenuScene.cpp index f6f8220..fcbd43f 100644 --- a/game/menus/mainmenu/MainMenuScene.cpp +++ b/game/menus/mainmenu/MainMenuScene.cpp @@ -1,17 +1,20 @@ #include "MainMenuScene.h" -#include "../ButtonSubScene.h" #include "TransitionStartScript.h" -#include "api/BehaviorScript.h" -#include "api/Camera.h" +#include "MainMenuConfig.h" + +#include "../ButtonSubScene.h" +#include "../MenusConfig.h" + #include "../../background/StartSubScene.h" #include "../../background/HallwaySubScene.h" -#include "MainMenuConfig.h" -#include "api/GameObject.h" -#include "api/Sprite.h" -#include "manager/SaveManager.h" #include "../../Config.h" -#include "../MenusConfig.h" + +#include +#include +#include +#include +#include using namespace crepe; using namespace std; diff --git a/game/menus/mainmenu/MainMenuScene.h b/game/menus/mainmenu/MainMenuScene.h index f7319cb..1eea90e 100644 --- a/game/menus/mainmenu/MainMenuScene.h +++ b/game/menus/mainmenu/MainMenuScene.h @@ -6,6 +6,5 @@ class MainMenuScene : public crepe::Scene { public: void load_scene(); - std::string get_name() const; }; diff --git a/game/menus/mainmenu/TransitionStartScript.cpp b/game/menus/mainmenu/TransitionStartScript.cpp index d03adf0..9b395de 100644 --- a/game/menus/mainmenu/TransitionStartScript.cpp +++ b/game/menus/mainmenu/TransitionStartScript.cpp @@ -1,15 +1,10 @@ #include "TransitionStartScript.h" + #include "../MenusConfig.h" -#include "iostream" using namespace crepe; using namespace std; - -void TransitionStartScript::init(){ - cout << "script init" << endl; -} - void TransitionStartScript::fixed_update(crepe::duration_t dt){ if(this->get_key_state(Keycode::ENTER) && this->transition == false) this->transition = true; } diff --git a/game/menus/mainmenu/TransitionStartScript.h b/game/menus/mainmenu/TransitionStartScript.h index 76f532e..c6df1b9 100644 --- a/game/menus/mainmenu/TransitionStartScript.h +++ b/game/menus/mainmenu/TransitionStartScript.h @@ -4,7 +4,6 @@ class TransitionStartScript : public ITransitionScript { public: - void init() override; void fixed_update(crepe::duration_t dt) override; const char* get_scene_name() const override; }; diff --git a/game/menus/shop/ShopMenuScene.cpp b/game/menus/shop/ShopMenuScene.cpp index c0a5a72..d35d296 100644 --- a/game/menus/shop/ShopMenuScene.cpp +++ b/game/menus/shop/ShopMenuScene.cpp @@ -1,11 +1,13 @@ #include "ShopMenuScene.h" + #include "../ButtonSubScene.h" -#include "api/Camera.h" #include "../MenusConfig.h" -#include "api/Sprite.h" #include "../BannerSubScene.h" +#include +#include + using namespace crepe; using namespace std; diff --git a/game/menus/shop/ShopMenuScene.h b/game/menus/shop/ShopMenuScene.h index 7178372..34c05ff 100644 --- a/game/menus/shop/ShopMenuScene.h +++ b/game/menus/shop/ShopMenuScene.h @@ -1,8 +1,9 @@ #pragma once -#include #include +#include + class ShopMenuScene : public crepe::Scene { public: void load_scene(); -- cgit v1.2.3 From 867414de0e2e963b0d1c35b3a46884a8a03a9294 Mon Sep 17 00:00:00 2001 From: JAROWMR Date: Mon, 6 Jan 2025 19:09:52 +0100 Subject: popup window --- game/CMakeLists.txt | 1 + game/menus/ButtonSubScene.cpp | 5 +- game/menus/ButtonSubScene.h | 3 +- game/menus/endgame/EndGameSubScene.cpp | 163 +++++++++++++++++++++++++++++++++ game/menus/endgame/EndGameSubScene.h | 12 +++ game/menus/mainmenu/MainMenuScene.cpp | 7 +- game/menus/shop/ShopMenuScene.cpp | 4 +- 7 files changed, 190 insertions(+), 5 deletions(-) create mode 100644 game/menus/endgame/EndGameSubScene.cpp create mode 100644 game/menus/endgame/EndGameSubScene.h (limited to 'game/menus/mainmenu') diff --git a/game/CMakeLists.txt b/game/CMakeLists.txt index 949312f..4c5bd53 100644 --- a/game/CMakeLists.txt +++ b/game/CMakeLists.txt @@ -32,6 +32,7 @@ add_executable(main menus/mainmenu/ITransitionScript.cpp menus/mainmenu/MainMenuScene.cpp menus/mainmenu/TransitionStartScript.cpp + menus/endgame/EndGameSubScene.cpp coins/CoinSubScene.cpp coins/CoinPool.cpp coins/CoinSystemScript.cpp diff --git a/game/menus/ButtonSubScene.cpp b/game/menus/ButtonSubScene.cpp index 6aad352..d735d08 100644 --- a/game/menus/ButtonSubScene.cpp +++ b/game/menus/ButtonSubScene.cpp @@ -80,7 +80,10 @@ void ButtonSubScene::set_button_overlay(crepe::GameObject & button_object,const case ButtonSelect::LARGE: this->large_btn_overlay(button_object,data); break; - case ButtonSelect::SMALL: + case ButtonSelect::BACK: + this->small_btn_overlay(button_object,data); + break; + case ButtonSelect::NEXT: this->small_btn_overlay(button_object,data); break; } diff --git a/game/menus/ButtonSubScene.h b/game/menus/ButtonSubScene.h index 5609ecb..6781d19 100644 --- a/game/menus/ButtonSubScene.h +++ b/game/menus/ButtonSubScene.h @@ -25,7 +25,8 @@ public: }; //icon enum enum class ButtonSelect { - SMALL, + BACK, + NEXT, LARGE, }; //data struct diff --git a/game/menus/endgame/EndGameSubScene.cpp b/game/menus/endgame/EndGameSubScene.cpp new file mode 100644 index 0000000..029bf1c --- /dev/null +++ b/game/menus/endgame/EndGameSubScene.cpp @@ -0,0 +1,163 @@ + +#include "EndGameSubScene.h" + +#include "../MenusConfig.h" +#include "../../Config.h" +#include "api/GameObject.h" +#include "api/Scene.h" +#include "api/Sprite.h" + +#include + +using namespace crepe; +using namespace std; + +void EndGameSubScene::create(Scene & scn){ + const vec2 SIZE = {200,100}; + const float THICKNESS_BANNER = 34; + const float MIDDLE_OFFSET_FACTOR_TICKNESS = 0.83; + const float MIDDLE_OFFSET_FACTOR_OFFSET = 1.2; + const float MIDDLE_OFFSET_TICKNESS_ADDITION = -8; + const float MIDDLE_OFFSET_OFFSET_ADDITION = -0.5; + const float BOTTOM_OFFSET_X = 3; + const float BOTTOM_OFFSET_Y = -5; + + GameObject endgame = scn.new_object("EndGameSubScene"); + + // Top_middle + endgame.add_component( + Asset("asset/ui/settings_container/top_middle_setting.png"), + Sprite::Data{ + .sorting_in_layer = STARTING_SORTING_IN_LAYER+8, + .size = {SIZE.x,THICKNESS_BANNER}, + .position_offset = {0,0}, + }); + + // Top_Left + endgame.add_component( + Asset("asset/ui/settings_container/top_left_setting.png"), + Sprite::Data{ + .sorting_in_layer = STARTING_SORTING_IN_LAYER+8, + .size = {THICKNESS_BANNER,THICKNESS_BANNER}, + .position_offset = {-SIZE.x/2-THICKNESS_BANNER/2,0}, + }); + + // Top_Right + endgame.add_component( + Asset("asset/ui/settings_container/top_right_setting.png"), + Sprite::Data{ + .sorting_in_layer = STARTING_SORTING_IN_LAYER+8, + .size = {THICKNESS_BANNER,THICKNESS_BANNER}, + .position_offset = {SIZE.x/2+THICKNESS_BANNER/2,0}, + }); + + // Top_middle_2 + endgame.add_component( + Asset("asset/ui/settings_container/top_2_middle_setting.png"), + Sprite::Data{ + .sorting_in_layer = STARTING_SORTING_IN_LAYER+8, + .size = {SIZE.x,THICKNESS_BANNER}, + .position_offset = {0,THICKNESS_BANNER}, + }); + + // Top_Left_2 + endgame.add_component( + Asset("asset/ui/settings_container/top_2_left_setting.png"), + Sprite::Data{ + .sorting_in_layer = STARTING_SORTING_IN_LAYER+8, + .size = {THICKNESS_BANNER,THICKNESS_BANNER}, + .position_offset = {-SIZE.x/2-THICKNESS_BANNER/2,THICKNESS_BANNER}, + }); + + // Top_Right_2 + endgame.add_component( + Asset("asset/ui/settings_container/top_2_right_setting.png"), + Sprite::Data{ + .sorting_in_layer = STARTING_SORTING_IN_LAYER+8, + .size = {THICKNESS_BANNER,THICKNESS_BANNER}, + .position_offset = {SIZE.x/2+THICKNESS_BANNER/2,THICKNESS_BANNER}, + }); + + // Top_middle_3 + endgame.add_component( + Asset("asset/ui/settings_container/top_3_middle_setting.png"), + Sprite::Data{ + .sorting_in_layer = STARTING_SORTING_IN_LAYER+8, + .size = {SIZE.x,THICKNESS_BANNER}, + .position_offset = {0,THICKNESS_BANNER*2}, + }); + + // Top_Left_3 + endgame.add_component( + Asset("asset/ui/settings_container/top_3_left_setting.png"), + Sprite::Data{ + .sorting_in_layer = STARTING_SORTING_IN_LAYER+8, + .size = {THICKNESS_BANNER,THICKNESS_BANNER}, + .position_offset = {-SIZE.x/2-THICKNESS_BANNER/2,THICKNESS_BANNER*2}, + }); + + // Top_Right_3 + endgame.add_component( + Asset("asset/ui/settings_container/top_3_right_setting.png"), + Sprite::Data{ + .sorting_in_layer = STARTING_SORTING_IN_LAYER+8, + .size = {THICKNESS_BANNER,THICKNESS_BANNER}, + .position_offset = {SIZE.x/2+THICKNESS_BANNER/2,THICKNESS_BANNER*2}, + }); + + // Middle_Mid + endgame.add_component( + Asset("asset/ui/settings_container/middle_mid_setting.png"), + Sprite::Data{ + .sorting_in_layer = STARTING_SORTING_IN_LAYER+7, + .size = {SIZE.x*MIDDLE_OFFSET_FACTOR_OFFSET+MIDDLE_OFFSET_TICKNESS_ADDITION,SIZE.y}, + .position_offset = {0,THICKNESS_BANNER*3+SIZE.y/2-THICKNESS_BANNER/2}, + }); + + // Middle_Left + endgame.add_component( + Asset("asset/ui/settings_container/middle_left_setting.png"), + Sprite::Data{ + .sorting_in_layer = STARTING_SORTING_IN_LAYER+8, + .size = {THICKNESS_BANNER*MIDDLE_OFFSET_FACTOR_TICKNESS,SIZE.y}, + .position_offset = {-SIZE.x/2-THICKNESS_BANNER/2*MIDDLE_OFFSET_FACTOR_OFFSET-MIDDLE_OFFSET_OFFSET_ADDITION,THICKNESS_BANNER*3+SIZE.y/2-THICKNESS_BANNER/2}, + }); + + // Middle_Right + endgame.add_component( + Asset("asset/ui/settings_container/middle_right_setting.png"), + Sprite::Data{ + .sorting_in_layer = STARTING_SORTING_IN_LAYER+8, + .size = {THICKNESS_BANNER*MIDDLE_OFFSET_FACTOR_TICKNESS,SIZE.y}, + .position_offset = {SIZE.x/2+THICKNESS_BANNER/2*MIDDLE_OFFSET_FACTOR_OFFSET+MIDDLE_OFFSET_OFFSET_ADDITION,THICKNESS_BANNER*3+SIZE.y/2-THICKNESS_BANNER/2}, + }); + + // Bot_Middle + endgame.add_component( + Asset("asset/ui/settings_container/bot_middle_setting.png"), + Sprite::Data{ + .sorting_in_layer = STARTING_SORTING_IN_LAYER+7, + .size = {SIZE.x*MIDDLE_OFFSET_FACTOR_OFFSET+MIDDLE_OFFSET_TICKNESS_ADDITION,THICKNESS_BANNER*MIDDLE_OFFSET_FACTOR_TICKNESS}, + .position_offset = {0,THICKNESS_BANNER*3+SIZE.y-5}, + }); + + // Bot_Left + endgame.add_component( + Asset("asset/ui/settings_container/bot_left_setting.png"), + Sprite::Data{ + .sorting_in_layer = STARTING_SORTING_IN_LAYER+8, + .size = {THICKNESS_BANNER*MIDDLE_OFFSET_FACTOR_TICKNESS,THICKNESS_BANNER*MIDDLE_OFFSET_FACTOR_TICKNESS}, + .position_offset = {-SIZE.x/2-THICKNESS_BANNER/2-BOTTOM_OFFSET_X,THICKNESS_BANNER*3+SIZE.y+BOTTOM_OFFSET_Y}, + }); + + // Bot_Right + endgame.add_component( + Asset("asset/ui/settings_container/bot_right_setting.png"), + Sprite::Data{ + .sorting_in_layer = STARTING_SORTING_IN_LAYER+8, + .size = {THICKNESS_BANNER*MIDDLE_OFFSET_FACTOR_TICKNESS,THICKNESS_BANNER*MIDDLE_OFFSET_FACTOR_TICKNESS}, + .position_offset = {SIZE.x/2+THICKNESS_BANNER/2+BOTTOM_OFFSET_X,THICKNESS_BANNER*3+SIZE.y+BOTTOM_OFFSET_Y}, + }); +} + + diff --git a/game/menus/endgame/EndGameSubScene.h b/game/menus/endgame/EndGameSubScene.h new file mode 100644 index 0000000..5c727a7 --- /dev/null +++ b/game/menus/endgame/EndGameSubScene.h @@ -0,0 +1,12 @@ +#pragma once + +#include "Component.h" +#include + +#include +#include + +class EndGameSubScene { +public: + void create(crepe::Scene & scn); +}; diff --git a/game/menus/mainmenu/MainMenuScene.cpp b/game/menus/mainmenu/MainMenuScene.cpp index fcbd43f..a515b45 100644 --- a/game/menus/mainmenu/MainMenuScene.cpp +++ b/game/menus/mainmenu/MainMenuScene.cpp @@ -10,6 +10,8 @@ #include "../../background/HallwaySubScene.h" #include "../../Config.h" +#include "../endgame/EndGameSubScene.h" + #include #include #include @@ -97,6 +99,9 @@ void MainMenuScene::load_scene(){ .tag = MENU_INFO_TAG, }); + EndGameSubScene test; + test.create(*this); + } -string MainMenuScene::get_name() const { return "mainmenu"; } +string MainMenuScene::get_name() const { return MAINMENU_SCENE; } diff --git a/game/menus/shop/ShopMenuScene.cpp b/game/menus/shop/ShopMenuScene.cpp index d35d296..6c88dc8 100644 --- a/game/menus/shop/ShopMenuScene.cpp +++ b/game/menus/shop/ShopMenuScene.cpp @@ -38,9 +38,9 @@ void ShopMenuScene::load_scene(){ .text_width = 115, .position = {-400,-350}, .script_type = ButtonSubScene::ScriptSelect::MAINMENU, - .button_type = ButtonSubScene::ButtonSelect::SMALL, + .button_type = ButtonSubScene::ButtonSelect::BACK, .scale = 0.8 }); } -string ShopMenuScene::get_name() const { return "shopmenu"; } +string ShopMenuScene::get_name() const { return SHOP_SCENE; } -- cgit v1.2.3 From fcae8934916c9f429e58c8e178ab14fcf65a2bbc Mon Sep 17 00:00:00 2001 From: JAROWMR Date: Tue, 7 Jan 2025 11:20:58 +0100 Subject: added end game --- game/CMakeLists.txt | 2 ++ game/Events.h | 5 ++++ game/GameScene.cpp | 6 ++-- game/menus/IFloatingWindowScript.cpp | 23 +++++++++++++++ game/menus/IFloatingWindowScript.h | 15 ++++++++++ game/menus/endgame/EndGameSubScene.cpp | 14 +++++++-- game/menus/endgame/EndGameSubScript.cpp | 51 +++++++++++++++++++++++++++++++++ game/menus/endgame/EndGameSubScript.h | 16 +++++++++++ game/menus/mainmenu/MainMenuScene.cpp | 3 -- game/player/PlayerEndScript.cpp | 5 ++++ 10 files changed, 131 insertions(+), 9 deletions(-) create mode 100644 game/Events.h create mode 100644 game/menus/IFloatingWindowScript.cpp create mode 100644 game/menus/IFloatingWindowScript.h create mode 100644 game/menus/endgame/EndGameSubScript.cpp create mode 100644 game/menus/endgame/EndGameSubScript.h (limited to 'game/menus/mainmenu') diff --git a/game/CMakeLists.txt b/game/CMakeLists.txt index 9886973..fffe6d3 100644 --- a/game/CMakeLists.txt +++ b/game/CMakeLists.txt @@ -28,12 +28,14 @@ add_executable(main menus/ButtonSetShopScript.cpp menus/ButtonSetMainMenuScript.cpp menus/FloatingWindowSubScene.cpp + menus/IFloatingWindowScript.cpp menus/shop/ShopMenuScene.cpp menus/mainmenu/ButtonTransitionPreviewScript.cpp menus/mainmenu/ITransitionScript.cpp menus/mainmenu/MainMenuScene.cpp menus/mainmenu/TransitionStartScript.cpp menus/endgame/EndGameSubScene.cpp + menus/endgame/EndGameSubScript.cpp coins/CoinSubScene.cpp coins/CoinPool.cpp coins/CoinSystemScript.cpp diff --git a/game/Events.h b/game/Events.h new file mode 100644 index 0000000..cf0be68 --- /dev/null +++ b/game/Events.h @@ -0,0 +1,5 @@ +#pragma once + +#include "api/Event.h" + +struct EndGameEvent : public crepe::Event {}; diff --git a/game/GameScene.cpp b/game/GameScene.cpp index 24b4287..a1f3fa6 100644 --- a/game/GameScene.cpp +++ b/game/GameScene.cpp @@ -11,6 +11,7 @@ #include "hud/HudSubScene.h" #include "hud/SpeedScript.h" #include "menus/endgame/EndGameSubScene.h" +#include "menus/endgame/EndGameSubScript.h" #include "player/PlayerSubScene.h" #include @@ -135,9 +136,8 @@ void GameScene::load_scene() { }); missile.add_component(vec2(100, 100)); - - EndGameSubScene test; - test.create(*this); + EndGameSubScene endgamewindow; + endgamewindow.create(*this); } string GameScene::get_name() const { return "scene1"; } diff --git a/game/menus/IFloatingWindowScript.cpp b/game/menus/IFloatingWindowScript.cpp new file mode 100644 index 0000000..ce84de7 --- /dev/null +++ b/game/menus/IFloatingWindowScript.cpp @@ -0,0 +1,23 @@ +#include "IFloatingWindowScript.h" +#include "api/Sprite.h" +#include "types.h" + +using namespace crepe; + +void IFloatingWindowScript::init(){ + this->disable_all_sprites(); +} + +void IFloatingWindowScript::disable_all_sprites(){ + RefVector sprites = this->get_components_by_tag(this->tag); + for(Sprite & sprite : sprites){ + sprite.active = false; + } +} + +void IFloatingWindowScript::enable_all_sprites(){ + RefVector sprites = this->get_components_by_tag(this->tag); + for(Sprite & sprite : sprites){ + sprite.active = true; + } +} diff --git a/game/menus/IFloatingWindowScript.h b/game/menus/IFloatingWindowScript.h new file mode 100644 index 0000000..9775726 --- /dev/null +++ b/game/menus/IFloatingWindowScript.h @@ -0,0 +1,15 @@ +#pragma once + +#include +#include + +class IFloatingWindowScript : public virtual crepe::Script { +public: + virtual void init(); + void disable_all_sprites(); + void enable_all_sprites(); +protected: + std::string tag = ""; +}; + + diff --git a/game/menus/endgame/EndGameSubScene.cpp b/game/menus/endgame/EndGameSubScene.cpp index 8d785ed..41556af 100644 --- a/game/menus/endgame/EndGameSubScene.cpp +++ b/game/menus/endgame/EndGameSubScene.cpp @@ -5,6 +5,8 @@ #include #include #include +#include +#include "EndGameSubScript.h" #include "types.h" #include "../../Config.h" @@ -13,10 +15,14 @@ using namespace std; void EndGameSubScene::create(Scene & scn){ + const std::string TAG = "end_game_tag"; + GameObject script = scn.new_object("script"); + script.add_component().set_script(TAG); + // Window FloatingWindowSubScene window; window.create(scn, FloatingWindowSubScene::Data{ - .group_tag = "end_game_window", + .group_tag = TAG, .width = 500, .offset = {0,-50}, .width_middle_offset = -2, @@ -24,7 +30,7 @@ void EndGameSubScene::create(Scene & scn){ // Titel const string TITEL_STRING = "GAME OVER"; - GameObject titel = scn.new_object("titel"); + GameObject titel = scn.new_object("titel",TAG); crepe::vec2 size = {200,(200.0f/TITEL_STRING.size())*2}; titel.add_component(size, FONT,Text::Data{ .world_space = false, @@ -43,6 +49,7 @@ void EndGameSubScene::create(Scene & scn){ .button_type = ButtonSubScene::ButtonSelect::NEXT, .scale = 0.6, .worldspace = false, + .tag = TAG, .sorting_layer_offset = 20, }); @@ -50,10 +57,11 @@ 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::MAINMENU, .button_type = ButtonSubScene::ButtonSelect::BACK, .scale = 0.6, .worldspace = false, + .tag = TAG, .sorting_layer_offset = 20, }); diff --git a/game/menus/endgame/EndGameSubScript.cpp b/game/menus/endgame/EndGameSubScript.cpp new file mode 100644 index 0000000..2be6931 --- /dev/null +++ b/game/menus/endgame/EndGameSubScript.cpp @@ -0,0 +1,51 @@ +#include "EndGameSubScript.h" +#include "../IFloatingWindowScript.h" +#include "api/Button.h" +#include "api/Sprite.h" +#include "api/Text.h" +#include "types.h" +#include "../../Events.h" +#include + +using namespace crepe; + +EndGameSubScript::EndGameSubScript(const std::string & tag){ + this->tag = tag; +} + +void EndGameSubScript::init(){ + this->disable_all(); + this->subscribe([this](const EndGameEvent e) { return this->enable_all(); }); + this->subscribe([this](const EndGameEvent e) { return this->reset_timescale(); }); +} + +bool EndGameSubScript::disable_all(){ + IFloatingWindowScript::disable_all_sprites(); + RefVector