From 6a3063e6012bae44457b668ce48c48b8af90a95d Mon Sep 17 00:00:00 2001 From: JAROWMR Date: Sat, 28 Dec 2024 12:36:26 +0100 Subject: improved naming --- game/CMakeLists.txt | 16 +++++++-------- game/coins/coinSubScene.cpp | 0 game/coins/coinSubScene.h | 0 game/mainmenu/ButtonSetShopScript.cpp | 19 ++++++++++++++++++ game/mainmenu/ButtonSetShopScript.h | 14 +++++++++++++ game/mainmenu/ButtonSubScene.cpp | 8 ++++---- game/mainmenu/ButtonTransitionPreviewScript.cpp | 24 +++++++++++++++++++++++ game/mainmenu/ButtonTransitionPreviewScript.h | 11 +++++++++++ game/mainmenu/IShowScript.cpp | 26 ------------------------- game/mainmenu/IShowScript.h | 13 ------------- game/mainmenu/ITransitionScript.cpp | 26 +++++++++++++++++++++++++ game/mainmenu/ITransitionScript.h | 13 +++++++++++++ game/mainmenu/MainMenuScene.cpp | 4 ++-- game/mainmenu/SetShopScript.cpp | 19 ------------------ game/mainmenu/SetShopScript.h | 14 ------------- game/mainmenu/ShowPreviewScript.cpp | 24 ----------------------- game/mainmenu/ShowPreviewScript.h | 11 ----------- game/mainmenu/ShowStartScript.cpp | 21 -------------------- game/mainmenu/ShowStartScript.h | 10 ---------- game/mainmenu/TransitionStartScript.cpp | 21 ++++++++++++++++++++ game/mainmenu/TransitionStartScript.h | 10 ++++++++++ 21 files changed, 152 insertions(+), 152 deletions(-) create mode 100644 game/coins/coinSubScene.cpp create mode 100644 game/coins/coinSubScene.h create mode 100644 game/mainmenu/ButtonSetShopScript.cpp create mode 100644 game/mainmenu/ButtonSetShopScript.h create mode 100644 game/mainmenu/ButtonTransitionPreviewScript.cpp create mode 100644 game/mainmenu/ButtonTransitionPreviewScript.h delete mode 100644 game/mainmenu/IShowScript.cpp delete mode 100644 game/mainmenu/IShowScript.h create mode 100644 game/mainmenu/ITransitionScript.cpp create mode 100644 game/mainmenu/ITransitionScript.h delete mode 100644 game/mainmenu/SetShopScript.cpp delete mode 100644 game/mainmenu/SetShopScript.h delete mode 100644 game/mainmenu/ShowPreviewScript.cpp delete mode 100644 game/mainmenu/ShowPreviewScript.h delete mode 100644 game/mainmenu/ShowStartScript.cpp delete mode 100644 game/mainmenu/ShowStartScript.h create mode 100644 game/mainmenu/TransitionStartScript.cpp create mode 100644 game/mainmenu/TransitionStartScript.h diff --git a/game/CMakeLists.txt b/game/CMakeLists.txt index 2fc5e41..60ac8e6 100644 --- a/game/CMakeLists.txt +++ b/game/CMakeLists.txt @@ -25,12 +25,12 @@ set(SOURCES mainmenu/IButtonScript.cpp mainmenu/ButtonSubScene.cpp mainmenu/MainMenuScene.cpp - mainmenu/IShowScript.cpp - mainmenu/ShowStartScript.cpp - mainmenu/ShowPreviewScript.cpp + mainmenu/ITransitionScript.cpp + mainmenu/TransitionStartScript.cpp + mainmenu/ButtonTransitionPreviewScript.cpp mainmenu/ShopMenuScene.cpp mainmenu/BannerSubScene.cpp - mainmenu/SetShopScript.cpp + mainmenu/ButtonSetShopScript.cpp ) set(HEADERS @@ -49,12 +49,12 @@ set(HEADERS mainmenu/ButtonSubScene.h mainmenu/MainMenuScene.h mainmenu/MainMenuConfig.h - mainmenu/IShowScript.h - mainmenu/ShowStartScript.h - mainmenu/ShowPreviewScript.h + mainmenu/ITransitionScript.h + mainmenu/TransitionStartScript.h + mainmenu/ButtonTransitionPreviewScript.h mainmenu/ShopMenuScene.h mainmenu/BannerSubScene.h - mainmenu/SetShopScript.h + mainmenu/ButtonSetShopScript.h ) add_executable(main ${SOURCES} ${HEADERS}) diff --git a/game/coins/coinSubScene.cpp b/game/coins/coinSubScene.cpp new file mode 100644 index 0000000..e69de29 diff --git a/game/coins/coinSubScene.h b/game/coins/coinSubScene.h new file mode 100644 index 0000000..e69de29 diff --git a/game/mainmenu/ButtonSetShopScript.cpp b/game/mainmenu/ButtonSetShopScript.cpp new file mode 100644 index 0000000..0c855ec --- /dev/null +++ b/game/mainmenu/ButtonSetShopScript.cpp @@ -0,0 +1,19 @@ +#include "ButtonSetShopScript.h" +#include "MainMenuConfig.h" +#include "iostream" + +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(MainMenuConfig::SHOP_SCENE); + cout << "Start triggered:" << e.metadata.game_object_id << std::endl; + return false; +} + diff --git a/game/mainmenu/ButtonSetShopScript.h b/game/mainmenu/ButtonSetShopScript.h new file mode 100644 index 0000000..51db928 --- /dev/null +++ b/game/mainmenu/ButtonSetShopScript.h @@ -0,0 +1,14 @@ +#pragma once + +#include "IButtonScript.h" +#include + +class ButtonSetShopScript : public IButtonScript { +public: + void init() override; + bool on_button_press(const crepe::ButtonPressEvent& e); +private: + float velocity = 20; +protected: + bool transition = false; +}; diff --git a/game/mainmenu/ButtonSubScene.cpp b/game/mainmenu/ButtonSubScene.cpp index d110aaa..b4abe21 100644 --- a/game/mainmenu/ButtonSubScene.cpp +++ b/game/mainmenu/ButtonSubScene.cpp @@ -1,6 +1,6 @@ #include "ButtonSubScene.h" -#include "SetShopScript.h" -#include "ShowPreviewScript.h" +#include "ButtonSetShopScript.h" +#include "ButtonTransitionPreviewScript.h" #include "MainMenuConfig.h" #include @@ -51,10 +51,10 @@ void ButtonSubScene::btn_text_middle(crepe::GameObject & button_object,const std void ButtonSubScene::set_script(crepe::GameObject & button_object,ScriptSelect script){ switch (script) { case ScriptSelect::PREVIEW: - button_object.add_component().set_script(); + button_object.add_component().set_script(); break; case ScriptSelect::SHOP: - button_object.add_component().set_script(); + button_object.add_component().set_script(); case ScriptSelect::NONE: break; } diff --git a/game/mainmenu/ButtonTransitionPreviewScript.cpp b/game/mainmenu/ButtonTransitionPreviewScript.cpp new file mode 100644 index 0000000..d73c0f3 --- /dev/null +++ b/game/mainmenu/ButtonTransitionPreviewScript.cpp @@ -0,0 +1,24 @@ +#include "ButtonTransitionPreviewScript.h" +#include "MainMenuConfig.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 MainMenuConfig::PREVIEW_SCENE; +} diff --git a/game/mainmenu/ButtonTransitionPreviewScript.h b/game/mainmenu/ButtonTransitionPreviewScript.h new file mode 100644 index 0000000..4e5e6c9 --- /dev/null +++ b/game/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/mainmenu/IShowScript.cpp b/game/mainmenu/IShowScript.cpp deleted file mode 100644 index adb6e89..0000000 --- a/game/mainmenu/IShowScript.cpp +++ /dev/null @@ -1,26 +0,0 @@ -#include "IShowScript.h" -#include "api/Rigidbody.h" -#include "api/Transform.h" -#include "iostream" -#include -#include "MainMenuConfig.h" - -using namespace crepe; -using namespace std; - -void IShowScript::frame_update(crepe::duration_t delta_time){ - if(this->transition) - { - cout << "transition:" << velocity << std::endl; - Transform & cam = this->get_components_by_name(MainMenuConfig::CAMERA_NAME).front(); - if(velocity < MainMenuConfig::VELOCITY_MAX && cam.position.x < MainMenuConfig::SLOW_DOWN) velocity += MainMenuConfig::VELOCITY_STEP * delta_time.count(); - else if(velocity > 20) velocity -= MainMenuConfig::VELOCITY_STEP * delta_time.count(); - if(cam.position.x < MainMenuConfig::END) cam.position.x += (velocity * delta_time.count()); - if(cam.position.x >= MainMenuConfig::END) - { - this->set_next_scene(this->get_scene_name()); - } - - } -} - diff --git a/game/mainmenu/IShowScript.h b/game/mainmenu/IShowScript.h deleted file mode 100644 index e1e645a..0000000 --- a/game/mainmenu/IShowScript.h +++ /dev/null @@ -1,13 +0,0 @@ -#pragma once - -#include - -class IShowScript : 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/mainmenu/ITransitionScript.cpp b/game/mainmenu/ITransitionScript.cpp new file mode 100644 index 0000000..a7f5a0d --- /dev/null +++ b/game/mainmenu/ITransitionScript.cpp @@ -0,0 +1,26 @@ +#include "ITransitionScript.h" +#include "api/Rigidbody.h" +#include "api/Transform.h" +#include "iostream" +#include +#include "MainMenuConfig.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(MainMenuConfig::CAMERA_NAME).front(); + if(velocity < MainMenuConfig::VELOCITY_MAX && cam.position.x < MainMenuConfig::SLOW_DOWN) velocity += MainMenuConfig::VELOCITY_STEP * delta_time.count(); + else if(velocity > 20) velocity -= MainMenuConfig::VELOCITY_STEP * delta_time.count(); + if(cam.position.x < MainMenuConfig::END) cam.position.x += (velocity * delta_time.count()); + if(cam.position.x >= MainMenuConfig::END) + { + this->set_next_scene(this->get_scene_name()); + } + + } +} + diff --git a/game/mainmenu/ITransitionScript.h b/game/mainmenu/ITransitionScript.h new file mode 100644 index 0000000..78f1016 --- /dev/null +++ b/game/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/mainmenu/MainMenuScene.cpp b/game/mainmenu/MainMenuScene.cpp index 42d0eca..8ffea70 100644 --- a/game/mainmenu/MainMenuScene.cpp +++ b/game/mainmenu/MainMenuScene.cpp @@ -1,7 +1,7 @@ #include "MainMenuScene.h" #include "ButtonSubScene.h" -#include "ShowStartScript.h" +#include "TransitionStartScript.h" #include "api/BehaviorScript.h" #include "api/Camera.h" #include "../StartSubScene.h" @@ -27,7 +27,7 @@ void MainMenuScene::load_scene(){ .sorting_in_layer = MainMenuConfig::STARTING_SORTING_IN_LAYER+0, .size = {300,860}, }); - menu.add_component().set_script(); + menu.add_component().set_script(); ButtonSubScene button; vec2 pos = MainMenuConfig::MENU_OFFSET; diff --git a/game/mainmenu/SetShopScript.cpp b/game/mainmenu/SetShopScript.cpp deleted file mode 100644 index 427445b..0000000 --- a/game/mainmenu/SetShopScript.cpp +++ /dev/null @@ -1,19 +0,0 @@ -#include "SetShopScript.h" -#include "MainMenuConfig.h" -#include "iostream" - -using namespace crepe; -using namespace std; - -void SetShopScript::init(){ - cout << "script init" << endl; - IButtonScript::init(); - this->subscribe([this](const ButtonPressEvent& e) { return this->on_button_press(e); }); -} - -bool SetShopScript::on_button_press(const ButtonPressEvent& e){ - this->set_next_scene(MainMenuConfig::SHOP_SCENE); - cout << "Start triggered:" << e.metadata.game_object_id << std::endl; - return false; -} - diff --git a/game/mainmenu/SetShopScript.h b/game/mainmenu/SetShopScript.h deleted file mode 100644 index 0705e57..0000000 --- a/game/mainmenu/SetShopScript.h +++ /dev/null @@ -1,14 +0,0 @@ -#pragma once - -#include "IButtonScript.h" -#include - -class SetShopScript : public IButtonScript { -public: - void init() override; - bool on_button_press(const crepe::ButtonPressEvent& e); -private: - float velocity = 20; -protected: - bool transition = false; -}; diff --git a/game/mainmenu/ShowPreviewScript.cpp b/game/mainmenu/ShowPreviewScript.cpp deleted file mode 100644 index 978a9c6..0000000 --- a/game/mainmenu/ShowPreviewScript.cpp +++ /dev/null @@ -1,24 +0,0 @@ -#include "ShowPreviewScript.h" -#include "MainMenuConfig.h" -#include "iostream" - -using namespace crepe; -using namespace std; - - -void ShowPreviewScript::init(){ - cout << "script init" << endl; - IButtonScript::init(); - this->subscribe([this](const ButtonPressEvent& e) { return this->on_button_press(e); }); -} - -bool ShowPreviewScript::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* ShowPreviewScript::get_scene_name() const { - // Provide the next scene defined in MainMenuConfig - return MainMenuConfig::PREVIEW_SCENE; -} diff --git a/game/mainmenu/ShowPreviewScript.h b/game/mainmenu/ShowPreviewScript.h deleted file mode 100644 index 28fe95b..0000000 --- a/game/mainmenu/ShowPreviewScript.h +++ /dev/null @@ -1,11 +0,0 @@ -#pragma once - -#include "IButtonScript.h" -#include "IShowScript.h" - -class ShowPreviewScript : public IShowScript, 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/mainmenu/ShowStartScript.cpp b/game/mainmenu/ShowStartScript.cpp deleted file mode 100644 index 7179038..0000000 --- a/game/mainmenu/ShowStartScript.cpp +++ /dev/null @@ -1,21 +0,0 @@ -#include "ShowStartScript.h" -#include "MainMenuConfig.h" -#include "api/Event.h" -#include "iostream" - -using namespace crepe; -using namespace std; - - -void ShowStartScript::init(){ - cout << "script init" << endl; -} - -void ShowStartScript::fixed_update(crepe::duration_t dt){ - if(this->get_key_state(Keycode::ENTER) && this->transition == false) this->transition = true; -} - -const char* ShowStartScript::get_scene_name() const { - // Provide the next scene defined in MainMenuConfig - return MainMenuConfig::START_SCENE; -} diff --git a/game/mainmenu/ShowStartScript.h b/game/mainmenu/ShowStartScript.h deleted file mode 100644 index 27d9404..0000000 --- a/game/mainmenu/ShowStartScript.h +++ /dev/null @@ -1,10 +0,0 @@ -#pragma once - -#include "IShowScript.h" - -class ShowStartScript : public IShowScript { -public: - void init() override; - void fixed_update(crepe::duration_t dt) override; - const char* get_scene_name() const override; -}; diff --git a/game/mainmenu/TransitionStartScript.cpp b/game/mainmenu/TransitionStartScript.cpp new file mode 100644 index 0000000..5528bf9 --- /dev/null +++ b/game/mainmenu/TransitionStartScript.cpp @@ -0,0 +1,21 @@ +#include "TransitionStartScript.h" +#include "MainMenuConfig.h" +#include "api/Event.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 MainMenuConfig::START_SCENE; +} diff --git a/game/mainmenu/TransitionStartScript.h b/game/mainmenu/TransitionStartScript.h new file mode 100644 index 0000000..76f532e --- /dev/null +++ b/game/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