From 667ed9ac9b1e51ef87a5a0bca25566f39f087671 Mon Sep 17 00:00:00 2001 From: JAROWMR Date: Fri, 20 Dec 2024 15:52:54 +0100 Subject: updated cmake and added simple button --- game/CMakeLists.txt | 25 ++++++++++++++++++++++++- game/main.cpp | 3 ++- game/mainmenu/ButtonScript.cpp | 26 ++++++++++++++++++++++++++ game/mainmenu/ButtonScript.h | 11 +++++++++++ game/mainmenu/ButtonSubScene.cpp | 20 ++++++++++++++++++++ game/mainmenu/ButtonSubScene.h | 10 ++++++++++ game/mainmenu/MainMenuScene.cpp | 17 +++++++++++++++++ game/mainmenu/MainMenuScene.h | 11 +++++++++++ 8 files changed, 121 insertions(+), 2 deletions(-) create mode 100644 game/mainmenu/ButtonScript.cpp create mode 100644 game/mainmenu/ButtonScript.h create mode 100644 game/mainmenu/ButtonSubScene.cpp create mode 100644 game/mainmenu/ButtonSubScene.h create mode 100644 game/mainmenu/MainMenuScene.cpp create mode 100644 game/mainmenu/MainMenuScene.h diff --git a/game/CMakeLists.txt b/game/CMakeLists.txt index dc55523..8fae19f 100644 --- a/game/CMakeLists.txt +++ b/game/CMakeLists.txt @@ -8,7 +8,8 @@ set(CMAKE_BUILD_TYPE Debug) project(game C CXX) add_subdirectory(../src crepe) -add_executable(main + +set(SOURCES AquariumSubScene.cpp BackgroundSubScene.cpp ForestParallaxScript.cpp @@ -21,7 +22,29 @@ add_executable(main StartGameScript.cpp StartSubScene.cpp main.cpp + mainmenu/ButtonScript.cpp + mainmenu/ButtonSubScene.cpp + mainmenu/MainMenuScene.cpp +) + +set(HEADERS + AquariumSubScene.h + BackgroundSubScene.h + ForestParallaxScript.h + ForestSubScene.h + GameScene.h + HallwaySubScene.h + MoveCameraManualyScript.h + PlayerScript.h + PlayerSubScene.h + StartGameScript.h + StartSubScene.h + mainmenu/ButtonScript.h + mainmenu/ButtonSubScene.h + mainmenu/MainMenuScene.h ) +add_executable(main ${SOURCES} ${HEADERS}) + target_link_libraries(main PUBLIC crepe) diff --git a/game/main.cpp b/game/main.cpp index 325b66d..9c9f9ee 100644 --- a/game/main.cpp +++ b/game/main.cpp @@ -2,12 +2,13 @@ #include #include "GameScene.h" +#include "mainmenu/MainMenuScene.h" using namespace crepe; int main() { Engine gameloop; - gameloop.add_scene(); + gameloop.add_scene(); return gameloop.main(); } 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([this](const ButtonPressEvent& e) { return this->on_button_press(e); }); + this->subscribe([this](const ButtonEnterEvent& e) { return this->on_button_enter(e); }); + this->subscribe([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 + +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 +#include +#include +#include + +using namespace crepe; +using namespace std; + +void ButtonSubScene::create(Scene & scn){ + GameObject button_object = scn.new_object("button"); + button_object.add_component