aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJAROWMR <jarorutjes07@gmail.com>2024-12-20 15:52:54 +0100
committerJAROWMR <jarorutjes07@gmail.com>2024-12-20 15:52:54 +0100
commit667ed9ac9b1e51ef87a5a0bca25566f39f087671 (patch)
tree1ead85a1eb1559d53ae2fac8d1f2a599c880b46f
parent0ba89eff9283d5f9f59fa763a19f4616f1c66d74 (diff)
updated cmake and added simple button
-rw-r--r--game/CMakeLists.txt25
-rw-r--r--game/main.cpp3
-rw-r--r--game/mainmenu/ButtonScript.cpp26
-rw-r--r--game/mainmenu/ButtonScript.h11
-rw-r--r--game/mainmenu/ButtonSubScene.cpp20
-rw-r--r--game/mainmenu/ButtonSubScene.h10
-rw-r--r--game/mainmenu/MainMenuScene.cpp17
-rw-r--r--game/mainmenu/MainMenuScene.h11
8 files changed, 121 insertions, 2 deletions
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 <crepe/api/Script.h>
#include "GameScene.h"
+#include "mainmenu/MainMenuScene.h"
using namespace crepe;
int main() {
Engine gameloop;
- gameloop.add_scene<GameScene>();
+ gameloop.add_scene<MainMenuScene>();
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<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;
+};