aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorsalaaad2 <arthurdurant263@gmail.com>2022-01-04 23:52:04 +0100
committersalaaad2 <arthurdurant263@gmail.com>2022-01-04 23:52:04 +0100
commitb75a02c8f5c616eff6f21197c3e13056eefcb873 (patch)
treebee47f568de6d48a22d78043e05de198d5bec611
parentshotty makes a sound (diff)
downloadthreshold-b75a02c8f5c616eff6f21197c3e13056eefcb873.tar.gz
threshold-b75a02c8f5c616eff6f21197c3e13056eefcb873.tar.bz2
threshold-b75a02c8f5c616eff6f21197c3e13056eefcb873.tar.xz
threshold-b75a02c8f5c616eff6f21197c3e13056eefcb873.tar.zst
threshold-b75a02c8f5c616eff6f21197c3e13056eefcb873.zip
add fury, bang sound, colors and more
-rw-r--r--meta/maps/stage_1_start.bfm2
-rw-r--r--src/entity.hpp2
-rw-r--r--src/gameplay.cpp37
-rw-r--r--src/gameplay.hpp9
-rw-r--r--src/main.cpp10
-rw-r--r--src/weapon.cpp16
-rw-r--r--src/weapon.hpp6
7 files changed, 62 insertions, 20 deletions
diff --git a/meta/maps/stage_1_start.bfm b/meta/maps/stage_1_start.bfm
index 1678c3a..88ee2e6 100644
--- a/meta/maps/stage_1_start.bfm
+++ b/meta/maps/stage_1_start.bfm
@@ -1,2 +1,2 @@
-E 2 20
+E 20 20
N stage_1_boss.bfm
diff --git a/src/entity.hpp b/src/entity.hpp
index fe0d66b..0b170ab 100644
--- a/src/entity.hpp
+++ b/src/entity.hpp
@@ -18,9 +18,11 @@ class Entity {
int hp;
int radius;
int victims;
+ int fury;
bool threshold;
float posX;
float posY;
+ double time;
Vector2 direction;
Weapon * wp;
Entity();
diff --git a/src/gameplay.cpp b/src/gameplay.cpp
index de8dd88..2706cb7 100644
--- a/src/gameplay.cpp
+++ b/src/gameplay.cpp
@@ -43,12 +43,13 @@ Game::Game(std::string const & path)
en->radius = radius;
}
player = new Entity;
- player->posX = SCREENWIDTH / 2;
+ player->posX = 0;
player->posY = SCREENHEIGHT / 2;
player->direction.x = 100;
player->direction.y = 100;
player->radius = 10;
player->victims = 0;
+ player->fury = 0;
player->wp = new Weapon(10, 10,
"../meta/media/mp3/shotty_shoot.mp3",
"../meta/media/mp3/shotty_reload.mp3");
@@ -66,22 +67,25 @@ void Game::start() const
std::cout << "Gameplay: " << nEnemies << "enemies need to be spawned" << std::endl;
}
+// draw bad boys and player
void Game::draw() const
{
auto left = std::to_string(enemies->size());
+ ClearBackground(COOLPURPLE);
for (auto & en : *enemies)
{
- DrawCircleV((Vector2){en.posX, en.posY}, en.radius, RED);
+ DrawCircleV((Vector2){en.posX, en.posY}, en.radius, DARKBLUE);
}
DrawCircleV((Vector2){player->posX, player->posY}, 10, GREEN);
DrawText("Enemies left : ", 10, 10, 20, GREEN);
- DrawText(left.c_str(), 150, 10, 20,RED);
- if (player->victims >= 5) {
- DrawText("[E] FURY", SCREENWIDTH - 150, 10, 50, RED);
+ DrawText(left.c_str(), 150, 10, 20, RED);
+ if (player->fury >= 5) {
+ DrawText("[E] FURY", SCREENWIDTH - 300, 10, 50, RED);
}
}
+// progress the game & check for player death
int Game::tick() const
{
for (auto & en : *enemies)
@@ -105,8 +109,9 @@ int Game::tick() const
int Game::getKeys() const
{
- auto oldX = 0, oldY = 0;
- auto aimer = player->direction;
+ auto oldX = 0, oldY = 0; // get position before processing keys to check for player movement
+ // in threshold mode
+ auto aimer = player->direction; // duplicate player direction before making changes to it. this becomes the reticle
oldX = player->posX;
oldY = player->posY;
@@ -126,8 +131,12 @@ int Game::getKeys() const
player->posX += 4;
player->posY += 0;
}
- if (player->victims >= 5 && IsKeyDown(KEY_E)) {
+ if (player->fury >= 5 &&
+ IsKeyDown(KEY_E)) {
+ player->time = GetTime();
+
player->threshold = true;
+ player->fury = 0;
}
if (IsKeyDown(KEY_LEFT)) {
player->direction = Vector2Rotate(player->direction, -0.1f); // left
@@ -145,6 +154,11 @@ int Game::getKeys() const
}
if (player->threshold)
{
+ if (GetTime() >= (player->time + 5))
+ {
+ player->fury = 0;
+ player->threshold = false;
+ }
if (oldX != player->posX ||
oldY != player->posY)
{
@@ -173,7 +187,11 @@ Game::shoot() const
auto add1 = Vector2Add((Vector2){player->posX, player->posY}, rot1);
auto add2 = Vector2Add((Vector2){player->posX, player->posY}, rot2);
- player->wp->bang();
+ if (player->wp->bang() == 1) {
+ return ;
+ } else {
+ player->wp->bang();
+ }
for (auto en = enemies->begin(); en != enemies->end(); en++)
{
if (CheckCollisionPointLine((Vector2){en->posX, en->posY}, (Vector2){player->posX, player->posY}, add1, (en->radius * 2)) ||
@@ -184,6 +202,7 @@ Game::shoot() const
<< std::endl;
enemies->erase(en);
player->victims++;
+ player->fury++;
DrawLineEx((Vector2){player->posX, player->posY}, add1, 10,
ORANGE);
DrawLineEx((Vector2){player->posX, player->posY},
diff --git a/src/gameplay.hpp b/src/gameplay.hpp
index ccedb0e..168a83a 100644
--- a/src/gameplay.hpp
+++ b/src/gameplay.hpp
@@ -15,14 +15,17 @@
#include <vector>
#include <iostream>
+
+#define COOLPURPLE CLITERAL(Color){ 170, 153, 255, 255 } // cool Purple
+//rgb(170,153,255)
class Game {
- int nEnemies;
+ int nEnemies; // number of enemies on given level
std::vector<Entity> * enemies;
Entity * player;
- std::string next;
+ std::string next; // next level
public:
Game(std::string const & path);
@@ -34,7 +37,7 @@ class Game {
int getKeys() const ;
int shoot() const ;
- std::string const & getNext() const ;
+ std::string const & getNext() const ; // returns next level's string
};
#endif // GAMEPLAY_H_
diff --git a/src/main.cpp b/src/main.cpp
index d30878a..48a24f8 100644
--- a/src/main.cpp
+++ b/src/main.cpp
@@ -58,6 +58,7 @@ int main(void) {
gs = TITLE;
auto next = game->getNext();
delete game;
+ CloseAudioDevice();
if (next != "0") {
game = new Game("../meta/maps/stage_1_start.bfm");
}
@@ -67,13 +68,14 @@ int main(void) {
}
BeginDrawing();
- ClearBackground(RAYWHITE);
+ ClearBackground(COOLPURPLE);
switch (gs) {
case (TITLE):
{
- DrawText("THRESHOLD", (SCREENWIDTH / 2) - 150, SCREENHEIGHT / 2, 40, RED);
- DrawText("PRESS ENTER", (SCREENWIDTH / 2) - 150, (SCREENHEIGHT / 2) + 50, 40, MAROON);
+ DrawCircle(SCREENWIDTH / 2, SCREENHEIGHT / 2, 200, BLACK);
+ DrawText("THRESHOLD", (SCREENWIDTH / 2) - 140, SCREENHEIGHT / 2, 40, RED);
+ DrawText("PRESS ENTER", (SCREENWIDTH / 2) - 140, (SCREENHEIGHT / 2) + 50, 40, MAROON);
break ;
}
case (GAMEPLAY):
@@ -89,7 +91,7 @@ int main(void) {
}
case (NEXT):
{
- ClearBackground(RAYWHITE);
+ ClearBackground(COOLPURPLE);
break ;
}
case (ENDING):
diff --git a/src/weapon.cpp b/src/weapon.cpp
index a774676..a516fdc 100644
--- a/src/weapon.cpp
+++ b/src/weapon.cpp
@@ -16,11 +16,23 @@ 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;
}
Weapon::~Weapon() {}
-void Weapon::bang() const
+void Weapon::refill()
{
- PlaySound(shot);
+ auto time = GetTime();
+}
+
+int Weapon::bang()
+{
+ if (barrel == 0)
+ {
+ refill();
+ } else {
+ barrel--;
+ PlaySound(shot);
+ }
}
diff --git a/src/weapon.hpp b/src/weapon.hpp
index 1b6b57a..61d3ace 100644
--- a/src/weapon.hpp
+++ b/src/weapon.hpp
@@ -15,6 +15,9 @@ class Weapon {
Sound shot;
Sound reload;
+ unsigned int barrel;
+ unsigned int max;
+
float const &range;
unsigned int const &damage;
@@ -22,7 +25,8 @@ public:
Weapon(float const &rg, unsigned int const &dmg, const char *s, const char *r);
~Weapon();
- void bang() const ;
+ int bang();
+ void refill();
};
#endif // WEAPON_H_