aboutsummaryrefslogtreecommitdiff
path: root/gameloop/src/loopManager.cpp
diff options
context:
space:
mode:
authorWBoerenkamps <wrj.boerenkamps@student.avans.nl>2024-09-18 15:11:04 +0200
committerWBoerenkamps <wrj.boerenkamps@student.avans.nl>2024-09-18 15:11:04 +0200
commit61e382cedd71127033f91551298607e2e78c3809 (patch)
treedb946bf0dac5cbb504ac7875fb323243d2a6db74 /gameloop/src/loopManager.cpp
parent7eafe293868d5d3875d0bec147e22a266e4ec86c (diff)
gameloop save
Diffstat (limited to 'gameloop/src/loopManager.cpp')
-rw-r--r--gameloop/src/loopManager.cpp41
1 files changed, 36 insertions, 5 deletions
diff --git a/gameloop/src/loopManager.cpp b/gameloop/src/loopManager.cpp
index ef2decf..c439a3e 100644
--- a/gameloop/src/loopManager.cpp
+++ b/gameloop/src/loopManager.cpp
@@ -1,4 +1,5 @@
#include "loopManager.h"
+#include "timer.h"
LoopManager::LoopManager(){
}
void LoopManager::processInput(){
@@ -15,23 +16,53 @@ void LoopManager::processInput(){
break;
}
}
+void LoopManager::fixedUpdate(){
+ fprintf(stderr,"fixed update\n");
+}
void LoopManager::loop(){
+ fprintf(stderr,"loop. \n");
+ LoopTimer& timer = LoopTimer::getInstance();
while(gameRunning){
- //processInput();
+ timer.update();
+ lag += timer.getDeltaTime();
+ processInput();
+ while (lag >= timer.getFixedDeltaTime())
+ {
+ fixedUpdate();
+ lag -= timer.getFixedDeltaTime();
+ }
//update();
- //render();
+ //timer.enforceFrameRate();
+ render();
}
window.destroyWindow();
}
void LoopManager::setup(){
gameRunning = window.initWindow();
+ LoopTimer::getInstance().start();
+ LoopTimer::getInstance().setFPS(50);
+
+ for(int i = 0; i < 2;i++){
+ GameObject* square = new GameObject("square2",i*40,i*40,20,20,0,0);
+ objectList.push_back(square);
+ }
}
void LoopManager::render(){
+ fprintf(stderr,"**********render********** \n");
if(gameRunning){
- SDL_SetRenderDrawColor(window.getRenderer(),255,0,0,255);
- SDL_RenderClear(window.getRenderer());
+ window.render(objectList);
}
}
-void LoopManager::update(){
+void LoopManager::update() {
+ fprintf(stderr,"**********normal update********** \n");
+ LoopTimer& timer = LoopTimer::getInstance();
+
+ 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);
+ }
}
+