aboutsummaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorsalaaad2 <arthurdurant263@gmail.com>2022-01-04 17:43:53 +0100
committersalaaad2 <arthurdurant263@gmail.com>2022-01-04 17:43:53 +0100
commit22383a6efdb3cfe49cd1081c648d95719b1e2eed (patch)
tree1d28f74a8f7f29202b7939973d6817f05c8d9897 /src
parentmap read from file (diff)
downloadthreshold-22383a6efdb3cfe49cd1081c648d95719b1e2eed.tar.gz
threshold-22383a6efdb3cfe49cd1081c648d95719b1e2eed.tar.bz2
threshold-22383a6efdb3cfe49cd1081c648d95719b1e2eed.tar.xz
threshold-22383a6efdb3cfe49cd1081c648d95719b1e2eed.tar.zst
threshold-22383a6efdb3cfe49cd1081c648d95719b1e2eed.zip
dumb pellet implementation
Diffstat (limited to 'src')
-rw-r--r--src/entity.cpp1
-rw-r--r--src/entity.hpp1
-rw-r--r--src/gameplay.cpp30
-rw-r--r--src/powerup.hpp10
4 files changed, 31 insertions, 11 deletions
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_