aboutsummaryrefslogtreecommitdiffstats
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
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
-rw-r--r--meta/maps/stage_1_start.bfm4
-rw-r--r--src/entity.cpp42
-rw-r--r--src/gameplay.cpp22
-rw-r--r--src/weapon.cpp4
4 files changed, 57 insertions, 15 deletions
diff --git a/meta/maps/stage_1_start.bfm b/meta/maps/stage_1_start.bfm
index 88ee2e6..d850579 100644
--- a/meta/maps/stage_1_start.bfm
+++ b/meta/maps/stage_1_start.bfm
@@ -1,2 +1,2 @@
-E 20 20
-N stage_1_boss.bfm
+ENEMIES 20 20
+NEXT stage_1_boss.bfm
diff --git a/src/entity.cpp b/src/entity.cpp
index 2714eef..c68ff10 100644
--- a/src/entity.cpp
+++ b/src/entity.cpp
@@ -10,14 +10,42 @@
Entity::Entity(void) : hp(1)
{
- posX = GetRandomValue(0, SCREENWIDTH);
- posY = GetRandomValue(0, SCREENHEIGHT);
- if (static_cast<int>(posX) & 1) {
- direction = (Vector2){posX / 100, -posY / 100};
- } else {
- direction = (Vector2){-posX / 100, posY / 100};
+ auto dir = GetRandomValue(0, 3);
+
+ switch (dir)
+ {
+ case (0):
+ {
+ posX = GetRandomValue((SCREENWIDTH / 2) - 30, (SCREENWIDTH / 2) + 30);
+ posY = 0;
+ break;
+ }
+ case (1):
+ {
+ posX = SCREENWIDTH;
+ posY = GetRandomValue((SCREENHEIGHT / 2) - 30, (SCREENHEIGHT / 2) + 30);
+ break;
+ }
+ case (2):
+ {
+ posX = GetRandomValue((SCREENWIDTH / 2) - 30, (SCREENWIDTH / 2) + 30);
+ posY = SCREENHEIGHT;
+ break;
+ }
+ case (3):
+ {
+ posX = SCREENWIDTH;
+ posY = GetRandomValue((SCREENHEIGHT / 2), (SCREENHEIGHT / 2) + 10);
+ break;
+ }
}
- radius = 10;
+
+ // if (static_cast<int>(posX) & 1) {
+ direction = (Vector2){0.1f, 0.1f};
+ // } else {
+ // direction = (Vector2){-posX / 100, posY / 100};
+ // } // old pseudo-random path finder. now reworking so that they go towards the player
+ radius = 10; // default radius. this is changed later
threshold = false;
}
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();
}
diff --git a/src/weapon.cpp b/src/weapon.cpp
index a516fdc..3f5dcec 100644
--- a/src/weapon.cpp
+++ b/src/weapon.cpp
@@ -16,7 +16,7 @@ Weapon::Weapon(float const & rg, unsigned int const & dmg, const char *s, const
reload = LoadSound(r);
SetSoundVolume(shot, 0.3f);
SetSoundVolume(reload, 0.3f);
- max = barrel = 20;
+ max = barrel = 200;
}
Weapon::~Weapon() {}
@@ -31,8 +31,10 @@ int Weapon::bang()
if (barrel == 0)
{
refill();
+ return (1);
} else {
barrel--;
PlaySound(shot);
+ return (0);
}
}