aboutsummaryrefslogtreecommitdiff
path: root/mwe/events/versions
diff options
context:
space:
mode:
authorLoek Le Blansch <loek@pipeframe.xyz>2024-10-24 10:53:02 +0200
committerLoek Le Blansch <loek@pipeframe.xyz>2024-10-24 10:53:02 +0200
commita8a7ff90dfd626ea76dd9e9fe00c7854a7b9f31f (patch)
tree2724ddce9d181770e7ca745900af76ed64194451 /mwe/events/versions
parent39054829fa69bcfa2b468015dc3852a2f8deac9f (diff)
parentb5e83d076f356c6d01b7bbc1f033db4850356c0d (diff)
Merge branch 'wouter/events-poc' of github.com:lonkaars/crepe
Diffstat (limited to 'mwe/events/versions')
-rw-r--r--mwe/events/versions/delayBased.cpp56
1 files changed, 56 insertions, 0 deletions
diff --git a/mwe/events/versions/delayBased.cpp b/mwe/events/versions/delayBased.cpp
new file mode 100644
index 0000000..253a03a
--- /dev/null
+++ b/mwe/events/versions/delayBased.cpp
@@ -0,0 +1,56 @@
+#include "loopManager.h"
+#include "timer.h"
+LoopManager::LoopManager() {}
+void LoopManager::processInput() {
+ SDL_Event event;
+ SDL_PollEvent(&event);
+ switch (event.type) {
+ case SDL_QUIT:
+ gameRunning = false;
+ break;
+ case SDL_KEYDOWN:
+ if (event.key.keysym.sym == SDLK_ESCAPE) {
+ gameRunning = false;
+ }
+ break;
+ }
+}
+void LoopManager::loop() {
+ fprintf(stderr, "loop. \n");
+ while (gameRunning) {
+ //Timer::getInstance().update();
+ //deltaTime = Timer::getInstance().getDeltaTime();
+ processInput();
+ update();
+ render();
+ }
+ window.destroyWindow();
+}
+void LoopManager::setup() {
+ gameRunning = window.initWindow();
+ LoopTimer::getInstance().start();
+ LoopTimer::getInstance().setFPS(210);
+
+ for (int i = 0; i < 2; i++) {
+ GameObject * square2
+ = new GameObject("square2", i * 40, i * 40, 20, 20, 0, 0);
+ objectList.push_back(square2);
+ }
+}
+void LoopManager::render() {
+ if (gameRunning) {
+ window.render(objectList);
+ }
+}
+
+void LoopManager::update() {
+ LoopTimer & timer = LoopTimer::getInstance();
+ timer.enforceFrameRate();
+ timer.update();
+ float delta = timer.getDeltaTime();
+
+ for (int i = 0; i < objectList.size(); i++) {
+ objectList[i]->setX(objectList[i]->getX() + 50 * delta);
+ objectList[i]->setY(objectList[i]->getY() + 50 * delta);
+ }
+}