diff options
Diffstat (limited to 'game/mainmenu')
-rw-r--r-- | game/mainmenu/ButtonScript.cpp | 26 | ||||
-rw-r--r-- | game/mainmenu/ButtonScript.h | 11 | ||||
-rw-r--r-- | game/mainmenu/ButtonSubScene.cpp | 20 | ||||
-rw-r--r-- | game/mainmenu/ButtonSubScene.h | 10 | ||||
-rw-r--r-- | game/mainmenu/MainMenuScene.cpp | 17 | ||||
-rw-r--r-- | game/mainmenu/MainMenuScene.h | 11 |
6 files changed, 95 insertions, 0 deletions
diff --git a/game/mainmenu/ButtonScript.cpp b/game/mainmenu/ButtonScript.cpp new file mode 100644 index 0000000..44ba381 --- /dev/null +++ b/game/mainmenu/ButtonScript.cpp @@ -0,0 +1,26 @@ +#include "ButtonScript.h" +#include "iostream" +using namespace crepe; +using namespace std; + +bool ButtonScript::on_button_press(const ButtonPressEvent& e){ + + cout << "button triggered:" << e.metadata.game_object_id << std::endl; + return false; +} +bool ButtonScript::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/ButtonScript.h b/game/mainmenu/ButtonScript.h new file mode 100644 index 0000000..96f52f4 --- /dev/null +++ b/game/mainmenu/ButtonScript.h @@ -0,0 +1,11 @@ +#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 new file mode 100644 index 0000000..168b387 --- /dev/null +++ b/game/mainmenu/ButtonSubScene.cpp @@ -0,0 +1,20 @@ +#include "ButtonSubScene.h" +#include "ButtonScript.h" + +#include <crepe/api/BehaviorScript.h> +#include <crepe/api/Sprite.h> +#include <crepe/api/Scene.h> +#include <crepe/api/Button.h> + +using namespace crepe; +using namespace std; + +void ButtonSubScene::create(Scene & scn){ + GameObject button_object = scn.new_object("button"); + button_object.add_component<Button>(vec2{100,100},vec2{0,0}); + button_object.add_component<Sprite>(Asset("asset/coin/coin_64.png"),Sprite::Data{ + .size = vec2{100,100}, + }); + button_object.add_component<BehaviorScript>().set_script<ButtonScript>(); +} + diff --git a/game/mainmenu/ButtonSubScene.h b/game/mainmenu/ButtonSubScene.h new file mode 100644 index 0000000..20e6bbc --- /dev/null +++ b/game/mainmenu/ButtonSubScene.h @@ -0,0 +1,10 @@ +#pragma once + +namespace crepe { +class Scene; +} + +class ButtonSubScene { +public: + void create(crepe::Scene & scn); +}; diff --git a/game/mainmenu/MainMenuScene.cpp b/game/mainmenu/MainMenuScene.cpp new file mode 100644 index 0000000..013eb2b --- /dev/null +++ b/game/mainmenu/MainMenuScene.cpp @@ -0,0 +1,17 @@ + +#include "MainMenuScene.h" +#include "ButtonSubScene.h" +#include "api/Camera.h" + +using namespace crepe; +using namespace std; + +void MainMenuScene::load_scene(){ + GameObject camera_object = this->new_object("camera"); + camera_object.add_component<Camera>(ivec2{500,500},vec2{500,500},Camera::Data{}); + + ButtonSubScene button; + button.create(*this); +} + +string MainMenuScene::get_name() const { return "mainmenu"; } diff --git a/game/mainmenu/MainMenuScene.h b/game/mainmenu/MainMenuScene.h new file mode 100644 index 0000000..f7319cb --- /dev/null +++ b/game/mainmenu/MainMenuScene.h @@ -0,0 +1,11 @@ +#pragma once + +#include <crepe/api/Scene.h> +#include <string> + +class MainMenuScene : public crepe::Scene { +public: + void load_scene(); + + std::string get_name() const; +}; |