From 91ecc3578a0016d10d279f1d5761c97161ef341e Mon Sep 17 00:00:00 2001
From: salaaad2 <arthurdurant263@gmail.com>
Date: Tue, 4 Jan 2022 19:11:24 +0100
Subject: add readme and optimize shooting vectors

---
 src/gameplay.cpp | 14 +++++++++-----
 1 file changed, 9 insertions(+), 5 deletions(-)

(limited to 'src')

diff --git a/src/gameplay.cpp b/src/gameplay.cpp
index decbd74..f52f665 100644
--- a/src/gameplay.cpp
+++ b/src/gameplay.cpp
@@ -124,11 +124,16 @@ int Game::getKeys() const
         player->direction = Vector2Rotate(player->direction, 0.1f);
     }
     if (IsKeyPressed(KEY_SPACE)) {
+        auto rot1 = Vector2Rotate(player->direction, -0.2f);
+        auto rot2 = Vector2Rotate(player->direction, 0.2f);
+
+        auto add1 = Vector2Add((Vector2){player->posX, player->posY}, rot1);
+        auto add2 = Vector2Add((Vector2){player->posX, player->posY}, rot2);
         for (auto en = enemies->begin(); en != enemies->end(); en++)
         {
-            if (CheckCollisionPointLine((Vector2){en->posX, en->posY}, (Vector2){player->posX, player->posY}, Vector2Add((Vector2){player->posX, player->posY}, Vector2Rotate(player->direction, -0.2f)), (en->radius * 2)) ||
+            if (CheckCollisionPointLine((Vector2){en->posX, en->posY}, (Vector2){player->posX, player->posY}, add1, (en->radius * 2)) ||
                 CheckCollisionPointLine((Vector2){en->posX, en->posY}, (Vector2){player->posX, player->posY}, Vector2Add((Vector2){player->posX, player->posY}, Vector2Rotate(player->direction, 0.0f)), (en->radius * 2)) ||
-                CheckCollisionPointLine((Vector2){en->posX, en->posY}, (Vector2){player->posX, player->posY}, Vector2Add((Vector2){player->posX, player->posY}, Vector2Rotate(player->direction, 0.2f)), (en->radius * 2)))
+                CheckCollisionPointLine((Vector2){en->posX, en->posY}, (Vector2){player->posX, player->posY}, add2, (en->radius * 2)))
             {
               std::cout << "hit enemy at " << en->posX << "|" << en->posY
                         << std::endl;
@@ -137,9 +142,9 @@ int Game::getKeys() const
               return (0);
             }
         }
-        DrawLineEx((Vector2){player->posX, player->posY}, Vector2Add((Vector2){player->posX, player->posY}, Vector2Rotate(player->direction, -0.2f)), 10, ORANGE);
+        DrawLineEx((Vector2){player->posX, player->posY}, add1, 10, ORANGE);
         DrawLineEx((Vector2){player->posX, player->posY}, Vector2Add((Vector2){player->posX, player->posY}, player->direction), 10, ORANGE);
-        DrawLineEx((Vector2){player->posX, player->posY}, Vector2Add((Vector2){player->posX, player->posY}, Vector2Rotate(player->direction, 0.2f)), 10, ORANGE);
+        DrawLineEx((Vector2){player->posX, player->posY}, add2, 10, ORANGE);
     }
     if (player->threshold)
     {
@@ -155,7 +160,6 @@ int Game::getKeys() const
             return (1);
         }
     }
-
     aimer.x = (player->direction.x / 3);
     aimer.y = (player->direction.y / 3);
     DrawLineEx((Vector2){player->posX, player->posY}, Vector2Add((Vector2){player->posX, player->posY}, aimer), 5, GREEN);
-- 
cgit v1.2.3