From 22383a6efdb3cfe49cd1081c648d95719b1e2eed Mon Sep 17 00:00:00 2001
From: salaaad2 <arthurdurant263@gmail.com>
Date: Tue, 4 Jan 2022 17:43:53 +0100
Subject: dumb pellet implementation

---
 src/entity.cpp   |  1 +
 src/entity.hpp   |  1 +
 src/gameplay.cpp | 30 +++++++++++++++++++-----------
 src/powerup.hpp  | 10 ++++++++++
 4 files changed, 31 insertions(+), 11 deletions(-)
 create mode 100644 src/powerup.hpp

(limited to 'src')

diff --git a/src/entity.cpp b/src/entity.cpp
index 69bec00..75e900a 100644
--- a/src/entity.cpp
+++ b/src/entity.cpp
@@ -17,6 +17,7 @@ Entity::Entity(void) : hp(1)
     } else {
         direction = (Vector2){-posX / 100, posY / 100};
     }
+    radius = 10;
 }
 
 Entity::~Entity() {}
diff --git a/src/entity.hpp b/src/entity.hpp
index 190df40..39ca07e 100644
--- a/src/entity.hpp
+++ b/src/entity.hpp
@@ -16,6 +16,7 @@
 class Entity {
     public:
         int hp;
+        int radius;
         float posX;
         float posY;
         Vector2 direction;
diff --git a/src/gameplay.cpp b/src/gameplay.cpp
index b424229..f04d2ef 100644
--- a/src/gameplay.cpp
+++ b/src/gameplay.cpp
@@ -15,6 +15,7 @@ Game::Game(std::string const & path)
 {
     std::ifstream ifs(path);
     std::string tok;
+    auto radius = 10;
 
     std::cout << "Init: reading map file [" << path << "]" << std::endl;
     while (ifs >> tok)
@@ -22,16 +23,23 @@ Game::Game(std::string const & path)
         if (tok == "E")
         {
             ifs >> tok;
-            std::cout << "will spawn " << tok << " enemies" << std::endl;
+            std::cout << "will spawn " << tok << " enemies";
             nEnemies = std::atoi(tok.c_str());
+            ifs >> tok;
+            radius = std::atoi(tok.c_str());
         }
     }
     enemies = new std::vector<Entity>(nEnemies);
+    for (auto en = enemies->begin(); en != enemies->end(); en++) {
+        en->radius = radius;
+    }
     player = new Entity;
     player->posX = SCREENWIDTH / 2;
     player->posY = SCREENHEIGHT / 2;
     player->direction.x = 100;
     player->direction.y = 100;
+    player->radius = 10;
+    ifs.close();
 }
 
 Game::~Game()
@@ -51,7 +59,7 @@ void Game::draw() const
     auto left = std::to_string(nEnemies);
     for (auto & en : *enemies)
     {
-        DrawCircleV((Vector2){en.posX, en.posY}, 10, RED);
+        DrawCircleV((Vector2){en.posX, en.posY}, en.radius, RED);
     }
     DrawCircleV((Vector2){player->posX, player->posY}, 10, GREEN);
     DrawText("Enemies left : ", 10, 10, 20, GREEN);
@@ -112,7 +120,8 @@ int Game::getKeys() const
     if (IsKeyPressed(KEY_SPACE)) {
         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}, player->direction), 20))
+            if (CheckCollisionPointLine((Vector2){en->posX, en->posY},
+                                        (Vector2){player->posX, player->posY}, Vector2Add((Vector2){player->posX, player->posY}, player->direction), (en->radius * 2)))
             {
               std::cout << "hit enemy at " << en->posX << "|" << en->posY
                         << std::endl;
@@ -120,15 +129,14 @@ int Game::getKeys() const
               return (0);
             }
         }
-        DrawLineEx((Vector2){player->posX, player->posY}, Vector2Add((Vector2){player->posX, player->posY}, player->direction), 20, RED);
-
+        DrawLineEx((Vector2){player->posX, player->posY}, Vector2Add((Vector2){player->posX, player->posY}, (Vector2){player->direction.x + 15, player->direction.y + 15}), 10, ORANGE);
+        DrawLineEx((Vector2){player->posX, player->posY}, Vector2Add((Vector2){player->posX, player->posY}, (Vector2){player->direction.x + 7, player->direction.y + 7}), 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}, (Vector2){player->direction.x - 7, player->direction.y - 7}), 10, ORANGE);
+        DrawLineEx((Vector2){player->posX, player->posY}, Vector2Add((Vector2){player->posX, player->posY}, (Vector2){player->direction.x - 15, player->direction.y - 15}), 10, ORANGE);
     }
-    if (oldX != player->posX ||
-        oldY != player->posY)
-    {
-        if (this->tick()) {
-            return (1);
-        }
+    if (this->tick()) {
+        return (1);
     }
     aimer.x = (player->direction.x / 3);
     aimer.y = (player->direction.y / 3);
diff --git a/src/powerup.hpp b/src/powerup.hpp
new file mode 100644
index 0000000..ce14997
--- /dev/null
+++ b/src/powerup.hpp
@@ -0,0 +1,10 @@
+#ifndef POWERUP_H_
+#define POWERUP_H_
+
+class Powerup {
+    public:
+        Powerup();
+        virtual ~Powerup();
+};
+
+#endif // POWERUP_H_
-- 
cgit v1.2.3