diff options
author | salaaad2 <arthurdurant263@gmail.com> | 2022-01-14 14:12:14 +0100 |
---|---|---|
committer | salaaad2 <arthurdurant263@gmail.com> | 2022-01-14 14:12:14 +0100 |
commit | f3b2fcb95f0eb21d3b1e5977659c6447ccffeb82 (patch) | |
tree | 6899f16faabe3210989792de92c8b021f112d78a | |
parent | boss has the correct textures (diff) | |
download | threshold-f3b2fcb95f0eb21d3b1e5977659c6447ccffeb82.tar.gz threshold-f3b2fcb95f0eb21d3b1e5977659c6447ccffeb82.tar.bz2 threshold-f3b2fcb95f0eb21d3b1e5977659c6447ccffeb82.tar.xz threshold-f3b2fcb95f0eb21d3b1e5977659c6447ccffeb82.tar.zst threshold-f3b2fcb95f0eb21d3b1e5977659c6447ccffeb82.zip |
strange behavior... I WILL find out whats going on !
-rw-r--r-- | meta/maps/savestate | 0 | ||||
-rw-r--r-- | meta/maps/stage_2_start.bfm | 8 | ||||
-rw-r--r-- | src/entity.cpp | 8 | ||||
-rw-r--r-- | src/gameplay.cpp | 50 | ||||
-rw-r--r-- | src/gameplay.hpp | 17 | ||||
-rw-r--r-- | src/main.cpp | 13 | ||||
-rw-r--r-- | src/projectile.cpp | 12 | ||||
-rw-r--r-- | src/projectile.hpp | 15 | ||||
-rw-r--r-- | src/weapon.cpp | 5 | ||||
-rw-r--r-- | src/weapon.hpp | 15 | ||||
-rw-r--r-- | src/wp_assaultrifle.cpp | 2 | ||||
-rw-r--r-- | src/wp_enemyslingshot.cpp | 10 | ||||
-rw-r--r-- | src/wp_shotty.cpp | 2 |
13 files changed, 95 insertions, 62 deletions
diff --git a/meta/maps/savestate b/meta/maps/savestate new file mode 100644 index 0000000..e69de29 --- /dev/null +++ b/meta/maps/savestate diff --git a/meta/maps/stage_2_start.bfm b/meta/maps/stage_2_start.bfm index ca380e2..c5af193 100644 --- a/meta/maps/stage_2_start.bfm +++ b/meta/maps/stage_2_start.bfm @@ -1,3 +1,5 @@ -BOSS 0 0 -ENEMIES 10 20 -NEXT stage_1_1.bfm +BOSS 1 10 +ENEMIES 2 100 +WAVES 1 2 +NEXT stage_1_boss.bfm +BACKGROUND ../meta/media/sprites/stage_1_bossbg.png diff --git a/src/entity.cpp b/src/entity.cpp index 9892b0b..05dc270 100644 --- a/src/entity.cpp +++ b/src/entity.cpp @@ -15,8 +15,8 @@ Entity::Entity(int const& h) : hp(h) { switch (dir) { case (0): { - posX = - GetRandomValue((SCREENWIDTH / 2) - 300, (SCREENWIDTH / 2) + 300); + posX = GetRandomValue((SCREENWIDTH / 2) - 300, + (SCREENWIDTH / 2) + 300); posY = GetRandomValue(0, 40); break; } @@ -27,8 +27,8 @@ Entity::Entity(int const& h) : hp(h) { break; } case (2): { - posX = - GetRandomValue((SCREENWIDTH / 2) - 300, (SCREENWIDTH / 2) + 300); + posX = GetRandomValue((SCREENWIDTH / 2) - 300, + (SCREENWIDTH / 2) + 300); posY = GetRandomValue(SCREENHEIGHT - 200, SCREENHEIGHT + 200); break; } diff --git a/src/gameplay.cpp b/src/gameplay.cpp index 983afa0..44987c9 100644 --- a/src/gameplay.cpp +++ b/src/gameplay.cpp @@ -17,8 +17,8 @@ #include "weapon.hpp" #include "window.hpp" #include "wp_assaultrifle.hpp" -#include "wp_shotty.hpp" #include "wp_enemyslingshot.hpp" +#include "wp_shotty.hpp" Game::Game(std::string const& path) : current(path) { std::ifstream ifs(path); @@ -63,15 +63,11 @@ Game::Game(std::string const& path) : current(path) { enemies = new std::vector<Entity>; InitAudioDevice(); - AWeapon* shotty = new wp_shotty(SHOTTY_BANG, - SHOTTY_RELOAD - ); + AWeapon* shotty = new wp_shotty(SHOTTY_BANG, SHOTTY_RELOAD); AWeapon* ar = new wp_assaultrifle(AR_BANG, - SHOTTY_RELOAD // TODO: get sound - ); - AWeapon* sling = new wp_enemysling(SHOTTY_BANG, - SHOTTY_RELOAD + SHOTTY_RELOAD ); + AWeapon* sling = new wp_enemysling(SHOTTY_BANG, SHOTTY_RELOAD); for (auto i = 0; i < nPerWave; i++) { if (ehp == 1) { @@ -79,12 +75,12 @@ Game::Game(std::string const& path) : current(path) { en.radius = radius; en.idleTex = LoadTexture(SBIRE_TEX_IDLE); en.hurtTex = LoadTexture(SBIRE_TEX_HURT); - enemies->push_back(en); en.currentWeapon = nullptr; + enemies->push_back(en); } else { Entity en(ehp); en.radius = radius; - en.wp[0] = shotty; + en.wp[0] = sling; en.currentWeapon = en.wp[0]; en.idleTex = LoadTexture(BOSS_TEX_IDLE); en.hurtTex = LoadTexture(BOSS_TEX_HURT); @@ -108,7 +104,6 @@ Game::Game(std::string const& path) : current(path) { player->idleTex = LoadTexture(MUCHACHO_TEX); } - Game::~Game() { delete enemies; delete player; @@ -130,13 +125,14 @@ void Game::start() { void Game::draw() { auto left = std::to_string(enemies->size()); - for (auto& en : *enemies) { if (en.hp == 0) - DrawTextureEx(en.hurtTex, (Vector2){en.posX - en.radius, en.posY - en.radius}, + DrawTextureEx(en.hurtTex, + (Vector2){en.posX - en.radius, en.posY - en.radius}, 1.0f, 0.6f, WHITE); else { - DrawTextureEx(en.idleTex, (Vector2){en.posX - en.radius, en.posY - en.radius}, + DrawTextureEx(en.idleTex, + (Vector2){en.posX - en.radius, en.posY - en.radius}, 1.0f, 0.6f, WHITE); } } @@ -155,13 +151,14 @@ void Game::draw() { if (player->fury >= 5) { DrawText("[E] FURY", SCREENWIDTH - 300, 10, 50, RED); } - for (auto i = 0; i < player->currentWeapon->barrel; i++) { + for (auto i = 0; i < player->currentWeapon->barrel; i++) { // draw weapon ammo DrawRectangle(40 + (i * 20), SCREENHEIGHT - 60, 10, 30, RED); } - if (enemies->at(0).hp >= 2) { + if (enemies->at(0).hp >= 2) { // draw hp in boss stages for (auto i = 0; i < enemies->size(); i++) { for (auto j = 0; j < enemies->at(i).hp; j++) { - DrawRectangle(400 + (j * 40), 80 + (i * 40), 40, 30, COOLPURPLE); + DrawRectangle(400 + (j * 40), 80 + (i * 40), 40, 30, + COOLPURPLE); } } } @@ -183,11 +180,12 @@ int Game::tick() { if (player->victims == nPerWave && nWaves > 1) { nWaves--; - for (int i = 0 ; i < nPerWave; i++) { + for (int i = 0; i < nPerWave; i++) { Entity en(1); en.radius = 20; en.idleTex = LoadTexture(SBIRE_TEX_IDLE); en.hurtTex = LoadTexture(SBIRE_TEX_HURT); + en.currentWeapon = nullptr; enemies->push_back(en); } } @@ -216,10 +214,11 @@ int Game::tick() { en->posY += 2.1f; en->direction.y += 0.1f; } - // if ((GetRandomValue(0, 100) == 50) && (en->currentWeapon != nullptr)) { - // std::cout << "spawn enemy" << std::endl; - // en->currentWeapon->bang(enemies, &(*en)); - // } + if ((GetRandomValue(0, 100) == 50) && (en->currentWeapon != + nullptr)) { + std::cout << "spawn enemy" << std::endl; + en->currentWeapon->bang(enemies, &(*en)); + } } else { if (en->posX >= SCREENWIDTH || en->posX <= 0 || en->posY >= SCREENHEIGHT) { @@ -240,8 +239,9 @@ int Game::tick() { } int Game::getKeys() { - auto oldX = 0, oldY = 0, speed = 7; // get position before processing keys to check - // for player movement in threshold mode + auto oldX = 0, oldY = 0, + speed = 7; // get position before processing keys to check + // for player movement in threshold mode oldX = player->posX; oldY = player->posY; if (IsKeyDown(KEY_W)) { @@ -259,7 +259,7 @@ int Game::getKeys() { player->posY += speed; } if (IsKeyDown(KEY_A)) { - if ((player->posX - speed) < 0) // avoid leaving the map + if ((player->posX - speed) < 0) // avoid leaving the map player->posX = 0; else player->posX += -speed; diff --git a/src/gameplay.hpp b/src/gameplay.hpp index 5d02e4c..f82121d 100644 --- a/src/gameplay.hpp +++ b/src/gameplay.hpp @@ -42,7 +42,7 @@ // #define COOLPURPLE \ // CLITERAL(Color) { 170, 153, 255, 255 } // cool Purple #define COOLPURPLE \ - CLITERAL(Color) { 153, 0, 0, 255 } // cool Purple + CLITERAL(Color) { 153, 0, 0, 255 } // cool Purple class Game { int nEnemies; // number of enemies on given level @@ -57,8 +57,8 @@ class Game { Entity* player; - std::string next; // next level - std::string current; // next level + std::string next; // next level + std::string current; // next level std::string background; // next level int frameWidth; @@ -70,22 +70,21 @@ class Game { Texture2D crosshair; - public: Game(std::string const& path); ~Game(); void start(); void draw(); - int tick() ; - int getKeys() ; + int tick(); + int getKeys(); int shoot() const; int hit(Entity en, Vector2 add1, Vector2 add2) const; - std::string const& getNext() const; // returns next level's string - std::string const& getCurrent() const; // returns next level's string + std::string const& getNext() const; // returns next level's string + std::string const& getCurrent() const; // returns next level's string std::string const& getBackground() const; // returns next level's string - int const& getKills() const; // returns next level's string + int const& getKills() const; // returns next level's string }; #endif // GAMEPLAY_H_ diff --git a/src/main.cpp b/src/main.cpp index ab6e60c..40dae71 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -7,8 +7,8 @@ /*********************************/ #include <raylib.h> // basic libs -#include <iostream> #include <fstream> +#include <iostream> #include "gameplay.hpp" #include "window.hpp" @@ -27,7 +27,6 @@ int main(void) { Game* game = nullptr; std::ofstream ifs("../meta/maps/savestate"); - std::string path = "../meta/maps"; int i = 0; for (const auto& entry : @@ -83,7 +82,7 @@ int main(void) { if (IsKeyPressed(KEY_ENTER)) { std::string next("../meta/maps/"); next += game->getNext(); - ifs << game->getCurrent() ; + ifs << game->getCurrent(); delete game; CloseAudioDevice(); @@ -169,9 +168,11 @@ int main(void) { DrawText("THRESHOLD", 260, 160, 30, RAYWHITE); DrawText("CONGRATULATIONS\n", 350, 240, 30, COOLPURPLE); DrawText("KILLS :", 350, 280, 30, COOLPURPLE); - auto kills = std::to_string(game->getKills()).c_str(); - DrawText(kills, 460, 280, 30, RED); - DrawText("TIME\n", 350, 320, 30, COOLPURPLE); + auto kills = std::to_string(game->getKills()); + DrawText(kills.c_str(), 460, 280, 30, RED); + DrawText("NEXT LEVEL :\n", 350, 360, 30, COOLPURPLE); + auto next = game->getNext(); + DrawText(next.c_str(), 460, 400, 30, RED); break; } diff --git a/src/projectile.cpp b/src/projectile.cpp new file mode 100644 index 0000000..de7b10e --- /dev/null +++ b/src/projectile.cpp @@ -0,0 +1,12 @@ +#include "projectile.hpp" +#include <raylib.h> + +Projectile::Projectile(Vector2 const& dir, Vector2 const& pos) + : direction(dir), position(pos) {} + +Projectile::~Projectile() {} + +Projectile * +Projectile::getProjectile() { + return (this); +} diff --git a/src/projectile.hpp b/src/projectile.hpp new file mode 100644 index 0000000..e25e5f4 --- /dev/null +++ b/src/projectile.hpp @@ -0,0 +1,15 @@ +#ifndef PROJECTILE_H +#define PROJECTILE_H + +#include <raylib.h> + +class Projectile { + Vector2 const& direction; + Vector2 const& position; + + public: + Projectile(Vector2 const& direction, Vector2 const& position); + ~Projectile(); +}; + +#endif /* PROJECTILE_H */ diff --git a/src/weapon.cpp b/src/weapon.cpp index 6f52217..a8553e3 100644 --- a/src/weapon.cpp +++ b/src/weapon.cpp @@ -15,8 +15,9 @@ AWeapon::AWeapon(float const rg, unsigned int const& mag, double const& cd, const char* s, - const char* r) - : range(rg), damage(dmg), max(mag), cooldown(cd) { + const char* r, + std::string const & nm) + : range(rg), damage(dmg), max(mag), cooldown(cd), name(nm) { shot = LoadSound(s); reload = LoadSound(r); SetSoundVolume(shot, 0.3f); diff --git a/src/weapon.hpp b/src/weapon.hpp index 0120928..ad63344 100644 --- a/src/weapon.hpp +++ b/src/weapon.hpp @@ -12,6 +12,7 @@ #include "raylib.h" #include <vector> +#include <iostream> class Entity; @@ -27,14 +28,16 @@ class AWeapon { float const range; unsigned int const& damage; + const std::string name; public: - AWeapon(float const rg, - unsigned int const& dmg, - unsigned int const& mag, - double const& cooldown, - const char* s, - const char* r); + AWeapon(float const rg, // range + unsigned int const& dmg, // damage + unsigned int const& mag, // mag capacity + double const& cooldown, // duh + const char* s, // shot sound path + const char* r, // reload sound path + std::string const & nm); // name ~AWeapon(); virtual int bang(std::vector<Entity>* enemies, Entity* player) = 0; diff --git a/src/wp_assaultrifle.cpp b/src/wp_assaultrifle.cpp index e12b440..41a3c91 100644 --- a/src/wp_assaultrifle.cpp +++ b/src/wp_assaultrifle.cpp @@ -7,7 +7,7 @@ #include "entity.hpp" wp_assaultrifle::wp_assaultrifle(const char* s, const char* r) - : AWeapon(300.0f, 10, 30, 0.0, s, r) {} + : AWeapon(300.0f, 10, 30, 0.0, s, r, "ar") {} int wp_assaultrifle::bang(std::vector<Entity>* enemies, Entity* player) { if (barrel == 0) { diff --git a/src/wp_enemyslingshot.cpp b/src/wp_enemyslingshot.cpp index 2a5b9fc..ad113e8 100644 --- a/src/wp_enemyslingshot.cpp +++ b/src/wp_enemyslingshot.cpp @@ -4,11 +4,11 @@ #include <raymath.h> #include <iostream> -#include "gameplay.hpp" #include "entity.hpp" +#include "gameplay.hpp" wp_enemysling::wp_enemysling(const char* s, const char* r) - : AWeapon(300.0f, 10, 2, 0.0, s, r) {} + : AWeapon(300.0f, 10, 1, 0.0, s, r, "sling") {} int wp_enemysling::bang(std::vector<Entity>* enemies, Entity* baddie) { if (barrel == 0) { @@ -21,9 +21,9 @@ int wp_enemysling::bang(std::vector<Entity>* enemies, Entity* baddie) { // it's a slingshot // Entity en(1); - en.posX = (baddie->posX += range); - en.posY = (baddie->posY += range); - en.direction = baddie->direction; + en.posX = 0; + en.posY = 0; + en.direction = (Vector2){1.0f, 1.0f}; en.radius = 20; en.currentWeapon = nullptr; en.idleTex = LoadTexture(SBIRE_TEX_IDLE); diff --git a/src/wp_shotty.cpp b/src/wp_shotty.cpp index 3ffceca..f2a5d22 100644 --- a/src/wp_shotty.cpp +++ b/src/wp_shotty.cpp @@ -7,7 +7,7 @@ #include "entity.hpp" wp_shotty::wp_shotty(const char* s, const char* r) - : AWeapon(100.0f, 10, 10, 0.5, s, r) {} + : AWeapon(100.0f, 10, 10, 0.5, s, r, "shotty") {} int wp_shotty::bang(std::vector<Entity>* enemies, Entity* player) { if (barrel == 0 || GetTime() < (t + cooldown)) { |