aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJAROWMR <jarorutjes07@gmail.com>2024-12-28 12:15:39 +0100
committerJAROWMR <jarorutjes07@gmail.com>2024-12-28 12:15:39 +0100
commitdeb1cd4732fb3a880cd10ce677e62fc2aac974a0 (patch)
tree28f02f1f4d88687688e9670c85f409c90bfc041d
parentf91eff6285f651f5c3e310927026f419e67657ab (diff)
interface scripts added
-rw-r--r--game/CMakeLists.txt10
-rw-r--r--game/mainmenu/ButtonScript.h11
-rw-r--r--game/mainmenu/ButtonSubScene.cpp4
-rw-r--r--game/mainmenu/IButtonScript.cpp (renamed from game/mainmenu/ButtonScript.cpp)22
-rw-r--r--game/mainmenu/IButtonScript.h12
-rw-r--r--game/mainmenu/IShowScript.cpp (renamed from game/mainmenu/ShowScript.cpp)4
-rw-r--r--game/mainmenu/IShowScript.h (renamed from game/mainmenu/ShowScript.h)2
-rw-r--r--game/mainmenu/MainMenuConfig.h4
-rw-r--r--game/mainmenu/MainMenuScene.cpp10
-rw-r--r--game/mainmenu/SetShopScript.cpp19
-rw-r--r--game/mainmenu/SetShopScript.h14
-rw-r--r--game/mainmenu/ShowPreviewScript.cpp13
-rw-r--r--game/mainmenu/ShowPreviewScript.h7
-rw-r--r--game/mainmenu/ShowStartScript.h4
14 files changed, 82 insertions, 54 deletions
diff --git a/game/CMakeLists.txt b/game/CMakeLists.txt
index d33290e..2fc5e41 100644
--- a/game/CMakeLists.txt
+++ b/game/CMakeLists.txt
@@ -22,14 +22,15 @@ set(SOURCES
StartGameScript.cpp
StartSubScene.cpp
main.cpp
- mainmenu/ButtonScript.cpp
+ mainmenu/IButtonScript.cpp
mainmenu/ButtonSubScene.cpp
mainmenu/MainMenuScene.cpp
- mainmenu/ShowScript.cpp
+ mainmenu/IShowScript.cpp
mainmenu/ShowStartScript.cpp
mainmenu/ShowPreviewScript.cpp
mainmenu/ShopMenuScene.cpp
mainmenu/BannerSubScene.cpp
+ mainmenu/SetShopScript.cpp
)
set(HEADERS
@@ -44,15 +45,16 @@ set(HEADERS
PlayerSubScene.h
StartGameScript.h
StartSubScene.h
- mainmenu/ButtonScript.h
+ mainmenu/IButtonScript.h
mainmenu/ButtonSubScene.h
mainmenu/MainMenuScene.h
mainmenu/MainMenuConfig.h
- mainmenu/ShowScript.h
+ mainmenu/IShowScript.h
mainmenu/ShowStartScript.h
mainmenu/ShowPreviewScript.h
mainmenu/ShopMenuScene.h
mainmenu/BannerSubScene.h
+ mainmenu/SetShopScript.h
)
add_executable(main ${SOURCES} ${HEADERS})
diff --git a/game/mainmenu/ButtonScript.h b/game/mainmenu/ButtonScript.h
deleted file mode 100644
index 96f52f4..0000000
--- a/game/mainmenu/ButtonScript.h
+++ /dev/null
@@ -1,11 +0,0 @@
-#pragma once
-
-#include <crepe/api/Script.h>
-
-class ButtonScript : public crepe::Script {
-public:
- bool on_button_press(const crepe::ButtonPressEvent& e);
- bool on_button_enter(const crepe::ButtonEnterEvent& e);
- bool on_button_exit(const crepe::ButtonExitEvent& e);
- void init();
-};
diff --git a/game/mainmenu/ButtonSubScene.cpp b/game/mainmenu/ButtonSubScene.cpp
index b415f74..d110aaa 100644
--- a/game/mainmenu/ButtonSubScene.cpp
+++ b/game/mainmenu/ButtonSubScene.cpp
@@ -1,7 +1,6 @@
#include "ButtonSubScene.h"
-#include "ButtonScript.h"
+#include "SetShopScript.h"
#include "ShowPreviewScript.h"
-#include "ShowStartScript.h"
#include "MainMenuConfig.h"
#include <crepe/api/BehaviorScript.h>
@@ -55,6 +54,7 @@ void ButtonSubScene::set_script(crepe::GameObject & button_object,ScriptSelect s
button_object.add_component<BehaviorScript>().set_script<ShowPreviewScript>();
break;
case ScriptSelect::SHOP:
+ button_object.add_component<BehaviorScript>().set_script<SetShopScript>();
case ScriptSelect::NONE:
break;
}
diff --git a/game/mainmenu/ButtonScript.cpp b/game/mainmenu/IButtonScript.cpp
index 44ba381..6cd42fb 100644
--- a/game/mainmenu/ButtonScript.cpp
+++ b/game/mainmenu/IButtonScript.cpp
@@ -1,26 +1,22 @@
-#include "ButtonScript.h"
+#include "IButtonScript.h"
#include "iostream"
+#include "system/InputSystem.h"
using namespace crepe;
using namespace std;
-bool ButtonScript::on_button_press(const ButtonPressEvent& e){
+void IButtonScript::init(){
+ cout << "script init" << endl;
+ this->subscribe<ButtonExitEvent>([this](const ButtonExitEvent& e) { return this->on_button_exit(e); });
+ this->subscribe<ButtonEnterEvent>([this](const ButtonEnterEvent& e) { return this->on_button_enter(e); });
+}
+bool IButtonScript::on_button_exit(const ButtonExitEvent& e){
cout << "button triggered:" << e.metadata.game_object_id << std::endl;
return false;
}
-bool ButtonScript::on_button_enter(const ButtonEnterEvent& e){
+bool IButtonScript::on_button_enter(const ButtonEnterEvent& e){
cout << "button Enter:" << e.metadata.game_object_id << std::endl;
return false;
}
-bool ButtonScript::on_button_exit(const ButtonExitEvent& e){
- cout << "button Exit:" << e.metadata.game_object_id << std::endl;
- return false;
-}
-void ButtonScript::init(){
- cout << "script init" << endl;
- this->subscribe<ButtonPressEvent>([this](const ButtonPressEvent& e) { return this->on_button_press(e); });
- this->subscribe<ButtonEnterEvent>([this](const ButtonEnterEvent& e) { return this->on_button_enter(e); });
- this->subscribe<ButtonExitEvent>([this](const ButtonExitEvent& e) { return this->on_button_exit(e); });
-}
diff --git a/game/mainmenu/IButtonScript.h b/game/mainmenu/IButtonScript.h
new file mode 100644
index 0000000..10b57bf
--- /dev/null
+++ b/game/mainmenu/IButtonScript.h
@@ -0,0 +1,12 @@
+#pragma once
+
+#include <crepe/api/Script.h>
+
+class IButtonScript : public virtual crepe::Script {
+public:
+ virtual void init();
+ virtual bool on_button_exit(const crepe::ButtonExitEvent& e);
+ virtual bool on_button_enter(const crepe::ButtonEnterEvent& e);
+};
+
+
diff --git a/game/mainmenu/ShowScript.cpp b/game/mainmenu/IShowScript.cpp
index dbd638e..adb6e89 100644
--- a/game/mainmenu/ShowScript.cpp
+++ b/game/mainmenu/IShowScript.cpp
@@ -1,4 +1,4 @@
-#include "ShowScript.h"
+#include "IShowScript.h"
#include "api/Rigidbody.h"
#include "api/Transform.h"
#include "iostream"
@@ -8,7 +8,7 @@
using namespace crepe;
using namespace std;
-void ShowScript::frame_update(crepe::duration_t delta_time){
+void IShowScript::frame_update(crepe::duration_t delta_time){
if(this->transition)
{
cout << "transition:" << velocity << std::endl;
diff --git a/game/mainmenu/ShowScript.h b/game/mainmenu/IShowScript.h
index 5bfabcc..e1e645a 100644
--- a/game/mainmenu/ShowScript.h
+++ b/game/mainmenu/IShowScript.h
@@ -2,7 +2,7 @@
#include <crepe/api/Script.h>
-class ShowScript : public crepe::Script {
+class IShowScript : public virtual crepe::Script {
public:
void frame_update(crepe::duration_t delta_time) override;
virtual const char* get_scene_name() const = 0;
diff --git a/game/mainmenu/MainMenuConfig.h b/game/mainmenu/MainMenuConfig.h
index fe325bd..e2ace30 100644
--- a/game/mainmenu/MainMenuConfig.h
+++ b/game/mainmenu/MainMenuConfig.h
@@ -11,9 +11,11 @@ struct MainMenuConfig {
static constexpr crepe::vec2 MENU_OFFSET = {-400,-200};
static constexpr float MENU_BUTTON_SPACING = 10;
static constexpr crepe::vec2 MENU_OFFSET_BACKGROUND = {0,200};
- // Moving to new scene (Start and Preview)
+ //Scene names
static constexpr const char* START_SCENE = "scene1";
static constexpr const char* PREVIEW_SCENE = "scene1";
+ static constexpr const char* SHOP_SCENE = "shopmenu";
+ //Moving to new scene (Start and Preview)
static constexpr float SLOW_DOWN = 200;
static constexpr float END = 300;
static constexpr float VELOCITY_MAX = 200;
diff --git a/game/mainmenu/MainMenuScene.cpp b/game/mainmenu/MainMenuScene.cpp
index 85437db..42d0eca 100644
--- a/game/mainmenu/MainMenuScene.cpp
+++ b/game/mainmenu/MainMenuScene.cpp
@@ -41,8 +41,14 @@ void MainMenuScene::load_scene(){
});
//Shop btn
- // pos.y += MainMenuConfig::MENU_BUTTON_SPACING + MainMenuConfig::LARGE_OVERLAY_SIZE.y;
- // button.create(*this,"SHOP",vec2{0,0},vec2{200,80},pos);
+ pos.y += MainMenuConfig::MENU_BUTTON_SPACING + MainMenuConfig::LARGE_OVERLAY_SIZE.y;
+ button.create(*this,ButtonSubScene::Data{
+ .text = "SHOP",
+ .text_size = vec2{200,80},
+ .position = pos,
+ .script = ButtonSubScene::ScriptSelect::SHOP,
+ });
+
//Start of map
StartSubScene start;
diff --git a/game/mainmenu/SetShopScript.cpp b/game/mainmenu/SetShopScript.cpp
new file mode 100644
index 0000000..427445b
--- /dev/null
+++ b/game/mainmenu/SetShopScript.cpp
@@ -0,0 +1,19 @@
+#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<ButtonPressEvent>([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
new file mode 100644
index 0000000..0705e57
--- /dev/null
+++ b/game/mainmenu/SetShopScript.h
@@ -0,0 +1,14 @@
+#pragma once
+
+#include "IButtonScript.h"
+#include <crepe/api/Script.h>
+
+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
index d015827..978a9c6 100644
--- a/game/mainmenu/ShowPreviewScript.cpp
+++ b/game/mainmenu/ShowPreviewScript.cpp
@@ -8,9 +8,8 @@ using namespace std;
void ShowPreviewScript::init(){
cout << "script init" << endl;
+ IButtonScript::init();
this->subscribe<ButtonPressEvent>([this](const ButtonPressEvent& e) { return this->on_button_press(e); });
- this->subscribe<ButtonEnterEvent>([this](const ButtonEnterEvent& e) { return this->on_button_enter(e); });
- this->subscribe<ButtonExitEvent>([this](const ButtonExitEvent& e) { return this->on_button_exit(e); });
}
bool ShowPreviewScript::on_button_press(const ButtonPressEvent& e){
@@ -18,16 +17,6 @@ bool ShowPreviewScript::on_button_press(const ButtonPressEvent& e){
cout << "Start triggered:" << e.metadata.game_object_id << std::endl;
return false;
}
-bool ShowPreviewScript::on_button_enter(const ButtonEnterEvent& e){
-
- cout << "Start Enter:" << e.metadata.game_object_id << std::endl;
- return false;
-}
-bool ShowPreviewScript::on_button_exit(const ButtonExitEvent& e){
-
- cout << "Start Exit:" << e.metadata.game_object_id << std::endl;
- return false;
-}
const char* ShowPreviewScript::get_scene_name() const {
// Provide the next scene defined in MainMenuConfig
diff --git a/game/mainmenu/ShowPreviewScript.h b/game/mainmenu/ShowPreviewScript.h
index 9612ca5..28fe95b 100644
--- a/game/mainmenu/ShowPreviewScript.h
+++ b/game/mainmenu/ShowPreviewScript.h
@@ -1,12 +1,11 @@
#pragma once
-#include "ShowScript.h"
+#include "IButtonScript.h"
+#include "IShowScript.h"
-class ShowPreviewScript : public ShowScript {
+class ShowPreviewScript : public IShowScript, public IButtonScript {
public:
void init() override;
bool on_button_press(const crepe::ButtonPressEvent& e);
- bool on_button_enter(const crepe::ButtonEnterEvent& e);
- bool on_button_exit(const crepe::ButtonExitEvent& e);
const char* get_scene_name() const override;
};
diff --git a/game/mainmenu/ShowStartScript.h b/game/mainmenu/ShowStartScript.h
index 4d8d894..27d9404 100644
--- a/game/mainmenu/ShowStartScript.h
+++ b/game/mainmenu/ShowStartScript.h
@@ -1,8 +1,8 @@
#pragma once
-#include "ShowScript.h"
+#include "IShowScript.h"
-class ShowStartScript : public ShowScript {
+class ShowStartScript : public IShowScript {
public:
void init() override;
void fixed_update(crepe::duration_t dt) override;