Browse Source

Lesson 5.4

Godzil 3 years ago
parent
commit
f682a8c22d
1 changed files with 4 additions and 2 deletions
  1. 4 2
      source/Game.cpp

+ 4 - 2
source/Game.cpp

@@ -92,7 +92,7 @@ glm::vec2 playerVelocity;
 void Game::Setup()
 {
     playerPostion = glm::vec2(10, 20);
-    playerVelocity = glm::vec2(1, 0);
+    playerVelocity = glm::vec2(100, 5);
 }
 
 void Game::Update()
@@ -102,10 +102,12 @@ void Game::Update()
     {
         SDL_Delay(timeToWait);
     }
+    double deltaTime = (SDL_GetTicks() - this->millisecsPerviousFrame) / 1000.0;
 
     this->millisecsPerviousFrame = SDL_GetTicks();
 
-    playerPostion += playerVelocity;
+    playerPostion.x += (playerVelocity.x * deltaTime);
+    playerPostion.y += (playerVelocity.y * deltaTime);
 }
 
 void Game::ProcessInput()