diff options
Diffstat (limited to 'mwe/gameloop/versions')
-rw-r--r-- | mwe/gameloop/versions/delayBased.cpp | 49 |
1 files changed, 24 insertions, 25 deletions
diff --git a/mwe/gameloop/versions/delayBased.cpp b/mwe/gameloop/versions/delayBased.cpp index a8cad15..253a03a 100644 --- a/mwe/gameloop/versions/delayBased.cpp +++ b/mwe/gameloop/versions/delayBased.cpp @@ -1,57 +1,56 @@ #include "loopManager.h" #include "timer.h" -LoopManager::LoopManager(){ -} -void LoopManager::processInput(){ +LoopManager::LoopManager() {} +void LoopManager::processInput() { SDL_Event event; SDL_PollEvent(&event); - switch(event.type){ + switch (event.type) { case SDL_QUIT: gameRunning = false; break; case SDL_KEYDOWN: - if(event.key.keysym.sym == SDLK_ESCAPE){ + if (event.key.keysym.sym == SDLK_ESCAPE) { gameRunning = false; } - break; + break; } } -void LoopManager::loop(){ - fprintf(stderr,"loop. \n"); - while(gameRunning){ +void LoopManager::loop() { + fprintf(stderr, "loop. \n"); + while (gameRunning) { //Timer::getInstance().update(); - //deltaTime = Timer::getInstance().getDeltaTime(); + //deltaTime = Timer::getInstance().getDeltaTime(); processInput(); update(); render(); } window.destroyWindow(); } -void LoopManager::setup(){ +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); + + 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){ +void LoopManager::render() { + if (gameRunning) { window.render(objectList); } } void LoopManager::update() { - LoopTimer& timer = LoopTimer::getInstance(); - timer.enforceFrameRate(); - timer.update(); - float delta= timer.getDeltaTime(); + 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); - } + for (int i = 0; i < objectList.size(); i++) { + objectList[i]->setX(objectList[i]->getX() + 50 * delta); + objectList[i]->setY(objectList[i]->getY() + 50 * delta); + } } - |