From 0c083ab2d3fd8151e6fd4238cf2159b56b96a708 Mon Sep 17 00:00:00 2001
From: salaaad2 <arthurdurant263@gmail.com>
Date: Mon, 3 Jan 2022 23:05:41 +0100
Subject: treschaud

---
 src/gameplay.cpp | 40 ++++++++++++++++++++++++----------------
 src/main.cpp     |  1 -
 2 files changed, 24 insertions(+), 17 deletions(-)

(limited to 'src')

diff --git a/src/gameplay.cpp b/src/gameplay.cpp
index 3cbc17f..fafe4a5 100644
--- a/src/gameplay.cpp
+++ b/src/gameplay.cpp
@@ -13,13 +13,13 @@ Game::Game(void)
 {
     // nEnemies = GetRandomValue(5, 15);
 
-    enemies = 3;
+    nEnemies = 4;
 
     enemies = new std::vector<Entity>(nEnemies);
     player = new Entity;
     player->posX = SCREENWIDTH / 2;
     player->posY = SCREENHEIGHT / 2;
-    player->direction.x = 1;
+    player->direction.x = 0;
     player->direction.y = 0;
 }
 
@@ -54,26 +54,34 @@ void Game::tick() const
         en.posX += en.direction.x;
         en.posY += en.direction.y;
     }
-    player->posX += player->direction.x;
-    player->posY += player->direction.y;
+    // player->posX += player->direction.x;
+    // player->posY += player->direction.y;
 }
 
 void Game::getKeys() const
 {
-    if (IsKeyPressed(KEY_UP)) {
-        player->direction.x = 0;
-        player->direction.y = -2;
+    auto oldX = 0, oldY = 0;
+
+    oldX = player->posX;
+    oldY = player->posY;
+    if (IsKeyDown(KEY_UP)) {
+        player->posX += 0;
+        player->posY += -4;
+    }
+    if (IsKeyDown(KEY_DOWN)) {
+        player->posX += 0;
+        player->posY += 4;
     }
-    if (IsKeyPressed(KEY_DOWN)) {
-        player->direction.x = 0;
-        player->direction.y = 2;
+    if (IsKeyDown(KEY_LEFT)) {
+        player->posX += -4;
+        player->posY += 0;
     }
-    if (IsKeyPressed(KEY_LEFT)) {
-        player->direction.x = -2;
-        player->direction.y = 0;
+    if (IsKeyDown(KEY_RIGHT)) {
+        player->posX += 4;
+        player->posY += 0;
     }
-    if (IsKeyPressed(KEY_RIGHT)) {
-        player->direction.x = 2;
-        player->direction.y = 0;
+    if (oldX != player->posX || oldY != player->posY)
+    {
+        this->tick();
     }
 }
diff --git a/src/main.cpp b/src/main.cpp
index 283390a..20a6cdc 100644
--- a/src/main.cpp
+++ b/src/main.cpp
@@ -24,7 +24,6 @@ int main(void) {
         }
         case (GAMEPLAY):
         {
-            game->tick();
             break ;
         }
         case (ENDING):
-- 
cgit v1.2.3