aboutsummaryrefslogtreecommitdiffstats
path: root/src/gameplay.cpp
diff options
context:
space:
mode:
authorsalaaad2 <arthurdurant263@gmail.com>2022-01-05 13:52:40 +0100
committersalaaad2 <arthurdurant263@gmail.com>2022-01-05 13:52:40 +0100
commite41533ee946f35facf984f264b9e3a050895f8ab (patch)
treed89ee411b26c5d7cc0f1be64431dfb62c1259b56 /src/gameplay.cpp
parentadd fury, bang sound, colors and more (diff)
downloadthreshold-e41533ee946f35facf984f264b9e3a050895f8ab.tar.gz
threshold-e41533ee946f35facf984f264b9e3a050895f8ab.tar.bz2
threshold-e41533ee946f35facf984f264b9e3a050895f8ab.tar.xz
threshold-e41533ee946f35facf984f264b9e3a050895f8ab.tar.zst
threshold-e41533ee946f35facf984f264b9e3a050895f8ab.zip
spawn not random anymore. this got a whole bunch harder
Diffstat (limited to 'src/gameplay.cpp')
-rw-r--r--src/gameplay.cpp22
1 files changed, 17 insertions, 5 deletions
diff --git a/src/gameplay.cpp b/src/gameplay.cpp
index 2706cb7..04facc2 100644
--- a/src/gameplay.cpp
+++ b/src/gameplay.cpp
@@ -22,7 +22,7 @@ Game::Game(std::string const & path)
std::cout << "Init: reading map file [" << path << "]" << std::endl;
while (ifs >> tok)
{
- if (tok == "E")
+ if (tok == "ENEMIES")
{
ifs >> tok;
std::cout << "will spawn " << tok << " enemies";
@@ -30,7 +30,7 @@ Game::Game(std::string const & path)
ifs >> tok;
radius = std::atoi(tok.c_str());
}
- if (tok == "N")
+ if (tok == "NEXT")
{
ifs >> tok;
next = tok;
@@ -86,6 +86,7 @@ void Game::draw() const
// progress the game & check for player death
+// NEW: go towards player NEXT: spawn at different times
int Game::tick() const
{
for (auto & en : *enemies)
@@ -96,11 +97,22 @@ int Game::tick() const
if (en.posY >= SCREENHEIGHT || en.posY <= 0) {
en.direction.y = -en.direction.y;
}
+ if (en.posX >= player->posX) {
+ en.direction.x -= 0.1f;
+ }
+ if (en.posY >= player->posY) {
+ en.direction.y -= 0.1f;
+ }
+ if (en.posX <= player->posX) {
+ en.direction.x += 0.1f;
+ }
+ if (en.posY <= player->posY) {
+ en.direction.y += 0.1f;
+ }
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;
+ (Vector2){en.posX, en.posY}, 10)) { // check for player death (one shot one kill)
return (1);
}
}
@@ -188,7 +200,7 @@ Game::shoot() const
auto add2 = Vector2Add((Vector2){player->posX, player->posY}, rot2);
if (player->wp->bang() == 1) {
- return ;
+ return (0);
} else {
player->wp->bang();
}