aboutsummaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorsalaaad2 <arthurdurant263@gmail.com>2022-01-04 14:19:47 +0100
committersalaaad2 <arthurdurant263@gmail.com>2022-01-04 14:19:47 +0100
commita4a467cf6ee8f30d7cba5f867981846275b0e22d (patch)
tree4a152c39d71647999506764dac48f3d7b88a0480 /src
parenttwo way control. Added reticle and smaller shots (diff)
downloadthreshold-a4a467cf6ee8f30d7cba5f867981846275b0e22d.tar.gz
threshold-a4a467cf6ee8f30d7cba5f867981846275b0e22d.tar.bz2
threshold-a4a467cf6ee8f30d7cba5f867981846275b0e22d.tar.xz
threshold-a4a467cf6ee8f30d7cba5f867981846275b0e22d.tar.zst
threshold-a4a467cf6ee8f30d7cba5f867981846275b0e22d.zip
shooting is fun hahahahahaha
Diffstat (limited to 'src')
-rw-r--r--src/entity.cpp2
-rw-r--r--src/entity.hpp1
-rw-r--r--src/gameplay.cpp25
3 files changed, 21 insertions, 7 deletions
diff --git a/src/entity.cpp b/src/entity.cpp
index 124ac02..9f3b35f 100644
--- a/src/entity.cpp
+++ b/src/entity.cpp
@@ -1,6 +1,6 @@
#include "entity.hpp"
-Entity::Entity(void)
+Entity::Entity(void) : hp(1)
{
posX = GetRandomValue(0, SCREENWIDTH);
posY = GetRandomValue(0, SCREENHEIGHT);
diff --git a/src/entity.hpp b/src/entity.hpp
index 49d98b6..995c0b4 100644
--- a/src/entity.hpp
+++ b/src/entity.hpp
@@ -5,6 +5,7 @@
class Entity {
public:
+ int hp;
float posX;
float posY;
Vector2 direction;
diff --git a/src/gameplay.cpp b/src/gameplay.cpp
index 038fb2f..2a208ee 100644
--- a/src/gameplay.cpp
+++ b/src/gameplay.cpp
@@ -32,11 +32,14 @@ void Game::start() const
void Game::draw() const
{
+ auto left = std::to_string(nEnemies);
for (auto & en : *enemies)
{
DrawCircleV((Vector2){en.posX, en.posY}, 10, RED);
}
DrawCircleV((Vector2){player->posX, player->posY}, 10, GREEN);
+ DrawText("Enemies left : ", 10, 10, 20, GREEN);
+ DrawText(left.c_str(), 150, 10, 20,RED);
}
@@ -44,16 +47,20 @@ void Game::tick() const
{
for (auto & en : *enemies)
{
- if (en.posX >= SCREENWIDTH || en.posX <= 0)
- {
- en.direction.x = -en.direction.x;
+ if (!en.hp)
+ { continue ; }
+ if (en.posX >= SCREENWIDTH || en.posX <= 0) {
+ en.direction.x = -en.direction.x;
}
- if (en.posY >= SCREENHEIGHT || en.posY <= 0)
- {
- en.direction.y = -en.direction.y;
+ if (en.posY >= SCREENHEIGHT || en.posY <= 0) {
+ en.direction.y = -en.direction.y;
}
en.posX += en.direction.x;
en.posY += en.direction.y;
+ if (CheckCollisionCircles((Vector2){player->posX, player->posY}, 10,
+ (Vector2){en.posX, en.posY}, 10)) {
+ std::cout << "you died" << std::endl;
+ }
}
}
@@ -87,7 +94,13 @@ void Game::getKeys() const
player->direction = Vector2Rotate(player->direction, 0.1f);
}
if (IsKeyPressed(KEY_SPACE)) {
+ for (auto & en : *enemies)
+ {
+ if (CheckCollisionPointLine((Vector2){en.posX, en.posY}, (Vector2){player->posX, player->posY}, Vector2Add((Vector2){player->posX, player->posY}, player->direction), 20))
+ std::cout << "hit enemy at " << en.posX << "|" << en.posY << std::endl;
+ }
DrawLineEx((Vector2){player->posX, player->posY}, Vector2Add((Vector2){player->posX, player->posY}, player->direction), 20, RED);
+
}
if (oldX != player->posX || oldY != player->posY)
{