aboutsummaryrefslogtreecommitdiff
path: root/src/example
diff options
context:
space:
mode:
Diffstat (limited to 'src/example')
-rw-r--r--src/example/events.cpp4
-rw-r--r--src/example/gameloop.cpp33
2 files changed, 35 insertions, 2 deletions
diff --git a/src/example/events.cpp b/src/example/events.cpp
index 6431c67..1b9ea45 100644
--- a/src/example/events.cpp
+++ b/src/example/events.cpp
@@ -56,12 +56,12 @@ public:
bool on_key_pressed(const KeyPressEvent & event) override {
std::cout << "TestKeyListener: Key Pressed - Code: " << static_cast<int>(event.key)
<< std::endl;
- return true; // Return true if the listener should remain active
+ return false;
}
bool on_key_released(const KeyReleaseEvent & event) override {
std::cout << "TestKeyListener: Key Released - Code: " << static_cast<int>(event.key)
<< std::endl;
- return true;
+ return false;
}
};
int main() {
diff --git a/src/example/gameloop.cpp b/src/example/gameloop.cpp
index a676f20..d45b3ce 100644
--- a/src/example/gameloop.cpp
+++ b/src/example/gameloop.cpp
@@ -1,7 +1,40 @@
+#include <iostream>
#include "crepe/api/LoopManager.h"
+#include <crepe/api/EventManager.h>
+#include <crepe/api/GameObject.h>
+#include <crepe/api/IKeyListener.h>
+#include <crepe/api/IMouseListener.h>
using namespace crepe;
+class TestKeyListener : public IKeyListener {
+public:
+ bool on_key_pressed(const KeyPressEvent & event) override {
+ std::cout << "TestKeyListener: Key Pressed - Code: " << static_cast<int>(event.key)
+ << std::endl;
+ if(event.key == Keycode::ESCAPE){
+
+ }
+ return false;
+ }
+ bool on_key_released(const KeyReleaseEvent & event) override {
+ std::cout << "TestKeyListener: Key Released - Code: " << static_cast<int>(event.key)
+ << std::endl;
+ return false;
+ }
+};
+bool on_key_pressed(const KeyPressEvent & event){
+ std::cout << "TestKeyListener: Key Pressed - Code: " << static_cast<int>(event.key)
+ << std::endl;
+ if(event.key == Keycode::ESCAPE){
+ return true;
+ }
+ return false;
+ }
int main() {
LoopManager gameloop;
+ TestKeyListener key_listener;
+ EventManager::get_instance().subscribe<KeyPressEvent>(on_key_pressed);
gameloop.start();
+
+
return 1;
}