diff options
author | WBoerenkamps <wrj.boerenkamps@student.avans.nl> | 2024-09-18 15:11:04 +0200 |
---|---|---|
committer | WBoerenkamps <wrj.boerenkamps@student.avans.nl> | 2024-09-18 15:11:04 +0200 |
commit | 61e382cedd71127033f91551298607e2e78c3809 (patch) | |
tree | db946bf0dac5cbb504ac7875fb323243d2a6db74 /gameloop/versions/delayBased.cpp | |
parent | 7eafe293868d5d3875d0bec147e22a266e4ec86c (diff) |
gameloop save
Diffstat (limited to 'gameloop/versions/delayBased.cpp')
-rw-r--r-- | gameloop/versions/delayBased.cpp | 57 |
1 files changed, 57 insertions, 0 deletions
diff --git a/gameloop/versions/delayBased.cpp b/gameloop/versions/delayBased.cpp new file mode 100644 index 0000000..a8cad15 --- /dev/null +++ b/gameloop/versions/delayBased.cpp @@ -0,0 +1,57 @@ +#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); + } +} + |