diff options
author | salaaad2 <arthurdurant263@gmail.com> | 2022-01-11 17:06:20 +0100 |
---|---|---|
committer | salaaad2 <arthurdurant263@gmail.com> | 2022-01-11 17:06:20 +0100 |
commit | 59d902df725c2d6a1b7cad016326ca51316b937f (patch) | |
tree | eae43bbc5d3faf3799fe242f1648115e17a9df67 /src | |
parent | clang-format chromium test (diff) | |
download | threshold-59d902df725c2d6a1b7cad016326ca51316b937f.tar.gz threshold-59d902df725c2d6a1b7cad016326ca51316b937f.tar.bz2 threshold-59d902df725c2d6a1b7cad016326ca51316b937f.tar.xz threshold-59d902df725c2d6a1b7cad016326ca51316b937f.tar.zst threshold-59d902df725c2d6a1b7cad016326ca51316b937f.zip |
clang format blind letsgo !
Diffstat (limited to 'src')
-rw-r--r-- | src/entity.cpp | 30 | ||||
-rw-r--r-- | src/entity.hpp | 42 | ||||
-rw-r--r-- | src/gameplay.cpp | 154 | ||||
-rw-r--r-- | src/gameplay.hpp | 49 | ||||
-rw-r--r-- | src/main.cpp | 278 | ||||
-rw-r--r-- | src/powerup.hpp | 8 | ||||
-rw-r--r-- | src/terrain.cpp | 8 | ||||
-rw-r--r-- | src/terrain.hpp | 9 | ||||
-rw-r--r-- | src/weapon.cpp | 18 | ||||
-rw-r--r-- | src/weapon.hpp | 45 | ||||
-rw-r--r-- | src/window.cpp | 3 | ||||
-rw-r--r-- | src/window.hpp | 13 | ||||
-rw-r--r-- | src/wp_assaultrifle.cpp | 46 | ||||
-rw-r--r-- | src/wp_assaultrifle.hpp | 9 | ||||
-rw-r--r-- | src/wp_shotty.cpp | 45 | ||||
-rw-r--r-- | src/wp_shotty.hpp | 9 |
16 files changed, 356 insertions, 410 deletions
diff --git a/src/entity.cpp b/src/entity.cpp index eda350f..8427479 100644 --- a/src/entity.cpp +++ b/src/entity.cpp @@ -8,35 +8,31 @@ #include "entity.hpp" -Entity::Entity() -: Entity(1) {} +Entity::Entity() : Entity(1) {} -Entity::Entity(int const & h) : hp(h) -{ +Entity::Entity(int const& h) : hp(h) { auto dir = GetRandomValue(0, 3); - switch (dir) - { - case (0): - { - posX = GetRandomValue((SCREENWIDTH / 2) - 30, (SCREENWIDTH / 2) + 30); + switch (dir) { + case (0): { + posX = + GetRandomValue((SCREENWIDTH / 2) - 30, (SCREENWIDTH / 2) + 30); posY = GetRandomValue(0, 40); break; } - case (1): - { + case (1): { posX = GetRandomValue(SCREENWIDTH - 20, SCREENWIDTH + 20); - posY = GetRandomValue((SCREENHEIGHT / 2) - 30, (SCREENHEIGHT / 2) + 30); + posY = GetRandomValue((SCREENHEIGHT / 2) - 30, + (SCREENHEIGHT / 2) + 30); break; } - case (2): - { - posX = GetRandomValue((SCREENWIDTH / 2) - 30, (SCREENWIDTH / 2) + 30); + case (2): { + posX = + GetRandomValue((SCREENWIDTH / 2) - 30, (SCREENWIDTH / 2) + 30); posY = GetRandomValue(SCREENHEIGHT - 20, SCREENHEIGHT + 20); break; } - case (3): - { + case (3): { posX = GetRandomValue(SCREENWIDTH - 20, SCREENWIDTH + 20); posY = GetRandomValue((SCREENHEIGHT / 2), (SCREENHEIGHT / 2) + 10); break; diff --git a/src/entity.hpp b/src/entity.hpp index 40818ee..cd92ef9 100644 --- a/src/entity.hpp +++ b/src/entity.hpp @@ -11,30 +11,30 @@ #include "window.hpp" -#include "weapon.hpp" #include <map> +#include "weapon.hpp" class Entity { - public: - int hp; - int radius; - int victims; - int fury; - bool threshold; - float posX; - float posY; - double furyTime; - double reloadTime; - Vector2 direction; - std::map<int, AWeapon*> wp; - AWeapon * currentWeapon; - Image img; - Texture2D idleTex; - Texture2D hurtTex; + public: + int hp; + int radius; + int victims; + int fury; + bool threshold; + float posX; + float posY; + double furyTime; + double reloadTime; + Vector2 direction; + std::map<int, AWeapon*> wp; + AWeapon* currentWeapon; + Image img; + Texture2D idleTex; + Texture2D hurtTex; - Entity(); - Entity(int const & h); - ~Entity(); + Entity(); + Entity(int const& h); + ~Entity(); }; -#endif // ENEMY_H_ +#endif // ENEMY_H_ diff --git a/src/gameplay.cpp b/src/gameplay.cpp index 9017de0..54270e3 100644 --- a/src/gameplay.cpp +++ b/src/gameplay.cpp @@ -8,43 +8,38 @@ #include "gameplay.hpp" -#include "raymath.h" +#include <raylib.h> #include <fstream> #include <iostream> -#include <raylib.h> #include <string> +#include "raymath.h" #include "weapon.hpp" #include "window.hpp" #include "wp_assaultrifle.hpp" #include "wp_shotty.hpp" -Game::Game(std::string const & path) : current(path) -{ +Game::Game(std::string const& path) : current(path) { std::ifstream ifs(path); std::string tok; auto radius = 0; auto ehp = 0; std::cout << "Init: reading map file [" << path << "]" << std::endl; - while (ifs >> tok) - { - if (tok == "ENEMIES") - { + while (ifs >> tok) { + if (tok == "ENEMIES") { ifs >> tok; std::cout << "will spawn " << tok << " enemies"; nEnemies = std::atoi(tok.c_str()); ifs >> tok; radius = std::atoi(tok.c_str()); } - if (tok == "NEXT") - { + if (tok == "NEXT") { ifs >> tok; next = tok; std::cout << "next level is " << next; } - if (tok == "BOSS") - { + if (tok == "BOSS") { ifs >> tok; ehp = (tok == "0") ? 1 : 0; if (ehp == 0) { @@ -52,8 +47,7 @@ Game::Game(std::string const & path) : current(path) ehp = std::atoi(tok.c_str()); } } - if (tok == "WAVES") - { + if (tok == "WAVES") { ifs >> tok; nWaves = std::atoi(tok.c_str()); ifs >> tok; @@ -65,16 +59,16 @@ Game::Game(std::string const & path) : current(path) for (auto i = 0; i < nEnemies; i++) { if (ehp == 0) { Entity en(ehp); - en.radius = radius; + en.radius = radius; en.idleTex = LoadTexture(SBIRE_TEX_IDLE); en.hurtTex = LoadTexture(SBIRE_TEX_HURT); enemies->push_back(en); } else { Entity en(ehp); - en.radius = radius; + en.radius = radius; en.idleTex = LoadTexture(SBIRE_TEX_IDLE); en.hurtTex = LoadTexture(SBIRE_TEX_HURT); - enemies->push_back(en); // legacy code. TODO: remove + enemies->push_back(en); // legacy code. TODO: remove } } player = new Entity; @@ -91,13 +85,9 @@ Game::Game(std::string const & path) : current(path) cam.offset = (Vector2){SCREENWIDTH / 2.0f, SCREENHEIGHT / 2.0f}; cam.rotation = 0.0f; cam.zoom = 1.0f; - AWeapon * shotty = new wp_shotty( - SHOTTY_BANG, - SHOTTY_RELOAD - ); - AWeapon * ar = new wp_assaultrifle( - AR_BANG, - SHOTTY_RELOAD // TODO: get sound + AWeapon* shotty = new wp_shotty(SHOTTY_BANG, SHOTTY_RELOAD); + AWeapon* ar = new wp_assaultrifle(AR_BANG, + SHOTTY_RELOAD // TODO: get sound ); player->wp[0] = shotty; @@ -106,46 +96,49 @@ Game::Game(std::string const & path) : current(path) player->idleTex = LoadTexture(MUCHACHO_TEX); } -Game::~Game() -{ +Game::~Game() { delete enemies; delete player; } -void Game::start() -{ +void Game::start() { std::cout << "----- Gameplay: Start -----" << std::endl; - std::cout << "Gameplay: " << nEnemies << "enemies need to be spawned" << std::endl; + std::cout << "Gameplay: " << nEnemies << "enemies need to be spawned" + << std::endl; frameWidth = player->idleTex.width; frameHeight = player->idleTex.height; - sourceRec = { 0.0f, 0.0f, (float)frameWidth, (float)frameHeight }; + sourceRec = {0.0f, 0.0f, (float)frameWidth, (float)frameHeight}; - origin = { (float)frameWidth, (float)frameHeight }; + origin = {(float)frameWidth, (float)frameHeight}; } // draw bad boys and player -void Game::draw() -{ +void Game::draw() { auto left = std::to_string(enemies->size()); cam.target.x = player->posX; EndMode2D(); auto texSize = (enemies->at(0).radius / 40.0f); - for (auto & en : *enemies) - { + for (auto& en : *enemies) { DrawCircle(en.posX, en.posY, en.radius, GREEN); if (en.hp == 0) - DrawTextureEx(en.hurtTex, (Vector2){en.posX - 20, en.posY - 20}, 1.0f, 0.6f, WHITE); + DrawTextureEx(en.hurtTex, (Vector2){en.posX - 20, en.posY - 20}, + 1.0f, 0.6f, WHITE); else { - DrawTextureEx(en.idleTex, (Vector2){en.posX - 20, en.posY - 20}, 1.0f, 0.6f, WHITE); + DrawTextureEx(en.idleTex, (Vector2){en.posX - 20, en.posY - 20}, + 1.0f, 0.6f, WHITE); } } // Destination rectangle (screen rectangle where drawing part of texture) - Rectangle destRec = { player->posX, player->posY, frameWidth * 1.8f, frameHeight * 1.8f }; + Rectangle destRec = {player->posX, player->posY, frameWidth * 1.8f, + frameHeight * 1.8f}; - // Origin of the texture (rotation/scale point), it's relative to destination rectangle size - DrawTexturePro(player->idleTex, sourceRec, destRec, origin, Vector2Angle((Vector2){0.0f, 0.0f}, player->direction), WHITE); + // Origin of the texture (rotation/scale point), it's relative to + // destination rectangle size + DrawTexturePro(player->idleTex, sourceRec, destRec, origin, + Vector2Angle((Vector2){0.0f, 0.0f}, player->direction), + WHITE); DrawText("Enemies left : ", 10, 10, 20, GREEN); DrawText(left.c_str(), 150, 10, 20, RED); @@ -155,18 +148,15 @@ void Game::draw() for (auto i = 0; i < player->currentWeapon->barrel; i++) { DrawRectangle(40 + (i * 20), SCREENHEIGHT - 60, 10, 30, RED); } - } // progress the game & check for player death // NEW: go towards player NEXT: spawn at different furyTimes -int Game::tick() const -{ +int Game::tick() const { auto target = GetMousePosition(); DrawLine(player->posX, player->posY, target.x, target.y, RAYWHITE); - auto v2 = (Vector2){target.x - player->posX, target.y - player->posY}; DrawText(std::to_string(v2.x).c_str(), 1400, 10, 20, RED); @@ -174,10 +164,8 @@ int Game::tick() const player->direction = v2; - for (auto en = enemies->begin(); en != enemies->end(); en++) - { - if (en->hp > 0) - { + for (auto en = enemies->begin(); en != enemies->end(); en++) { + if (en->hp > 0) { if (en->posX >= SCREENWIDTH || en->posX <= 0) { en->direction.x = -en->direction.x; } @@ -200,28 +188,28 @@ int Game::tick() const en->posY += 2.1f; en->direction.y += 0.1f; } - } else { - if (en->posX >= SCREENWIDTH || en->posX <= 0 || en->posY >= SCREENHEIGHT ) { - enemies->erase(en); - return (0); + } else { + if (en->posX >= SCREENWIDTH || en->posX <= 0 || + en->posY >= SCREENHEIGHT) { + enemies->erase(en); + return (0); } } - en->posX += en->direction.x; // zoning better - en->posY += en->direction.y; - if (en->hp != 0 && // check for player death (one shot one kill) - CheckCollisionCircles((Vector2){player->posX, player->posY}, 10, - (Vector2){en->posX, en->posY}, 40)) { + en->posX += en->direction.x; // zoning better + en->posY += en->direction.y; + if (en->hp != 0 && // check for player death (one shot one kill) + CheckCollisionCircles((Vector2){player->posX, player->posY}, 10, + (Vector2){en->posX, en->posY}, 40)) { return (1); } } return (0); } -int Game::getKeys() const -{ - auto oldX = 0, oldY = 0; // get position before processing keys to check for player movement - // in threshold mode +int Game::getKeys() const { + auto oldX = 0, oldY = 0; // get position before processing keys to check + // for player movement in threshold mode oldX = player->posX; oldY = player->posY; if (IsKeyDown(KEY_W)) { @@ -240,8 +228,7 @@ int Game::getKeys() const player->posX += 7; player->posY += 0; } - if (player->fury >= 5 && - IsKeyDown(KEY_E)) { + if (player->fury >= 5 && IsKeyDown(KEY_E)) { player->furyTime = GetTime(); player->threshold = true; @@ -261,14 +248,12 @@ int Game::getKeys() const return (2); } } - if (player->threshold) - { + if (player->threshold) { if (GetTime() >= (player->furyTime + 5)) { player->fury = 0; player->threshold = false; } - if (oldX != player->posX || - oldY != player->posY) { + if (oldX != player->posX || oldY != player->posY) { if (this->tick()) { return (1); } @@ -279,8 +264,7 @@ int Game::getKeys() const } } if (player->currentWeapon->empty) { - if (GetTime() >= (player->reloadTime + 2)) - { + if (GetTime() >= (player->reloadTime + 2)) { player->currentWeapon->refill(); player->currentWeapon->empty = false; } @@ -288,25 +272,21 @@ int Game::getKeys() const return (0); } - -int -Game::shoot() const -{ - - if (player->currentWeapon->empty == true) { - return (0); - } - player->currentWeapon->bang(enemies, player); - if (player->currentWeapon->empty == true) { - player->reloadTime = GetTime(); - } +int Game::shoot() const { + if (player->currentWeapon->empty == true) { return (0); + } + player->currentWeapon->bang(enemies, player); + if (player->currentWeapon->empty == true) { + player->reloadTime = GetTime(); + } + return (0); } -std::string const & -Game::getNext() const -{return next;} +std::string const& Game::getNext() const { + return next; +} -std::string const & -Game::getCurrent() const -{return current;} +std::string const& Game::getCurrent() const { + return current; +} diff --git a/src/gameplay.hpp b/src/gameplay.hpp index b379332..3a4f4cb 100644 --- a/src/gameplay.hpp +++ b/src/gameplay.hpp @@ -9,21 +9,20 @@ #ifndef GAMEPLAY_H_ #define GAMEPLAY_H_ +#include "entity.hpp" #include "terrain.hpp" #include "window.hpp" -#include "entity.hpp" #include <raylib.h> -#include <vector> #include <iostream> +#include <vector> // sound defines -#define SHOTTY_BANG "../meta/media/mp3/shotty_shoot.mp3" -#define SHOTTY_RELOAD "../meta/media/mp3/shotty_reload.mp3" - -#define AR_BANG "../meta/media/mp3/ar_shoot.mp3" -#define AR_RELOAD "../meta/media/mp3/shotty_reload.mp3" +#define SHOTTY_BANG "../meta/media/mp3/shotty_shoot.mp3" +#define SHOTTY_RELOAD "../meta/media/mp3/shotty_reload.mp3" +#define AR_BANG "../meta/media/mp3/ar_shoot.mp3" +#define AR_RELOAD "../meta/media/mp3/shotty_reload.mp3" // player textures #define MUCHACHO_TEX "../meta/media/sprites/cowboy_idle.png" @@ -34,26 +33,26 @@ // TODO: boss textures -#define COOLPURPLE CLITERAL(Color){ 170, 153, 255, 255 } // cool Purple +#define COOLPURPLE \ + CLITERAL(Color) { 170, 153, 255, 255 } // cool Purple class Game { - int nEnemies; // number of enemies on given level - int nWaves; // number of waves in level - int nPerWave; // number of enemies per wave. + int nEnemies; // number of enemies on given level + int nWaves; // number of waves in level + int nPerWave; // number of enemies per wave. // NOTE : maps are assumed to be correct. therefore, no // checks are made to verify their integrity. // having wrong maps can (and probably will) result in a crash - std::vector<Entity> * enemies; - - std::vector<Terrain*> * terrain; + std::vector<Entity>* enemies; - Entity * player; + std::vector<Terrain*>* terrain; - std::string next; // next level - std::string current; // next level + Entity* player; + std::string next; // next level + std::string current; // next level int frameWidth; int frameHeight; @@ -62,21 +61,21 @@ class Game { Vector2 origin; - public: - Game(std::string const &path); + public: + Game(std::string const& path); ~Game(); Camera2D cam; - void start() ; - void draw() ; + void start(); + void draw(); int tick() const; int getKeys() const; int shoot() const; - int hit(Entity en, Vector2 add1, Vector2 add2) 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 }; -#endif // GAMEPLAY_H_ +#endif // GAMEPLAY_H_ diff --git a/src/main.cpp b/src/main.cpp index a2f616d..d277919 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -6,181 +6,171 @@ /* ()__)____________))))) :^} */ /*********************************/ - -#include "window.hpp" -#include "gameplay.hpp" +#include <raylib.h> // basic libs #include <iostream> -#include <raylib.h> // basic libs +#include "gameplay.hpp" +#include "window.hpp" +#include <filesystem> // additional libs #include <map> -#include <filesystem> // additional libs gameState gs = TITLE; std::map<int, std::string> pick; int main(void) { - initWindow(); - InitWindow(SCREENWIDTH, SCREENHEIGHT, "WIP -- muchashooter THRESHOLD"); - auto nPick = 0; + initWindow(); + InitWindow(SCREENWIDTH, SCREENHEIGHT, "WIP -- muchashooter THRESHOLD"); + auto nPick = 0; - Game* game = nullptr; + Game* game = nullptr; std::string path = "../meta/maps"; int i = 0; - for (const auto & entry : std::filesystem::directory_iterator(path)) { // c++17 lol - if (entry.path().filename().generic_string().find("start") != std::string::npos) - { + for (const auto& entry : + std::filesystem::directory_iterator(path)) { // c++17 lol + if (entry.path().filename().generic_string().find("start") != + std::string::npos) { pick[i] = entry.path().filename().generic_string(); i++; } } - // Main game loop - while (!WindowShouldClose()) /* Detect window close button or ESC key */ - { - switch (gs) { - case (TITLE): - { - if (IsKeyPressed(KEY_ENTER)) - { - gs = PICK; - } - break ; - } - case (PICK): - { - if (IsKeyPressed(KEY_ENTER)) - { - std::string s(path); - s += "/"; - s += pick[nPick]; - game = new Game(s); - gs = GAMEPLAY; - game->start(); - } - if (IsKeyPressed(KEY_DOWN) && nPick < (pick.size() - 1)) - { - nPick++; + // Main game loop + while (!WindowShouldClose()) /* Detect window close button or ESC key */ + { + switch (gs) { + case (TITLE): { + if (IsKeyPressed(KEY_ENTER)) { + gs = PICK; + } + break; } - if (IsKeyPressed(KEY_UP) && nPick > 0) - { - nPick--; + case (PICK): { + if (IsKeyPressed(KEY_ENTER)) { + std::string s(path); + s += "/"; + s += pick[nPick]; + game = new Game(s); + gs = GAMEPLAY; + game->start(); + } + if (IsKeyPressed(KEY_DOWN) && nPick < (pick.size() - 1)) { + nPick++; + } + if (IsKeyPressed(KEY_UP) && nPick > 0) { + nPick--; + } } - } - case (DEATH): - { - if (IsKeyPressed(KEY_ENTER)) { - auto current = game->getCurrent(); + case (DEATH): { + if (IsKeyPressed(KEY_ENTER)) { + auto current = game->getCurrent(); - delete game; - CloseAudioDevice(); - game = new Game(current); - gs = GAMEPLAY; + delete game; + CloseAudioDevice(); + game = new Game(current); + gs = GAMEPLAY; + } + break; } - break ; - } - case (GAMEPLAY): - { - break ; - } - case (NEXT): - { - if (IsKeyPressed(KEY_ENTER)) - { - std::string next("../meta/maps/"); - next += game->getNext(); + case (GAMEPLAY): { + break; + } + case (NEXT): { + if (IsKeyPressed(KEY_ENTER)) { + std::string next("../meta/maps/"); + next += game->getNext(); - delete game; - CloseAudioDevice(); - std::cout << "next level " << next << std::endl; - if (game->getNext() != "0") { - game = new Game(next); - gs = GAMEPLAY; + delete game; + CloseAudioDevice(); + std::cout << "next level " << next << std::endl; + if (game->getNext() != "0") { + game = new Game(next); + gs = GAMEPLAY; + } } + break; } - break ; - } - case (ENDING): - { - if (IsKeyPressed(KEY_ENTER)) - { - gs = TITLE; - auto current = game->getCurrent(); - delete game; - CloseAudioDevice(); - game = new Game(current); + case (ENDING): { + if (IsKeyPressed(KEY_ENTER)) { + gs = TITLE; + auto current = game->getCurrent(); + delete game; + CloseAudioDevice(); + game = new Game(current); + } + break; } - break ; } - } - BeginDrawing(); + BeginDrawing(); - ClearBackground(COOLPURPLE); + ClearBackground(COOLPURPLE); + switch (gs) { + case (TITLE): { + DrawRectangle(200, 100, 1200, 700, RAYWHITE); + DrawRectangle(250, 150, 1100, 600, COOLPURPLE); + DrawText("THRESHOLD", 260, 160, 30, RAYWHITE); + DrawRectangle(300, 200, 1000, 500, RAYWHITE); + DrawText("PRESS ENTER", (SCREENWIDTH / 2) - 140, + (SCREENHEIGHT / 2) + 50, 40, MAROON); + break; + } + case (PICK): { + DrawRectangle(200, 100, 1200, 700, RAYWHITE); + DrawRectangle(250, 150, 1100, 600, COOLPURPLE); + DrawRectangle(300, 200, 1000, 500, RAYWHITE); + DrawText("THRESHOLD", 260, 160, 30, RAYWHITE); - switch (gs) { - case (TITLE): - { - DrawRectangle(200, 100, 1200, 700, RAYWHITE); - DrawRectangle(250, 150, 1100, 600, COOLPURPLE); - DrawText("THRESHOLD", 260, 160, 30, RAYWHITE); - DrawRectangle(300, 200, 1000, 500, RAYWHITE); - DrawText("PRESS ENTER", (SCREENWIDTH / 2) - 140, (SCREENHEIGHT / 2) + 50, 40, MAROON); - break ; - } - case (PICK): - { - DrawRectangle(200, 100, 1200, 700, RAYWHITE); - DrawRectangle(250, 150, 1100, 600, COOLPURPLE); - DrawRectangle(300, 200, 1000, 500, RAYWHITE); - DrawText("THRESHOLD", 260, 160, 30, RAYWHITE); - - DrawRectangle(350, 240 + (nPick * 40), 900, 50, PURPLE); - for (auto n = 0 ; n < pick.size(); n++) - { - DrawText(pick[n].c_str(), 400, - 240 + (n * 40), 40, COOLPURPLE); + DrawRectangle(350, 240 + (nPick * 40), 900, 50, PURPLE); + for (auto n = 0; n < pick.size(); n++) { + DrawText(pick[n].c_str(), 400, 240 + (n * 40), 40, + COOLPURPLE); + } + break; } - break ; - } - case (DEATH): - { - DrawRectangle(250, 150, 1100, 600, COOLPURPLE); - ClearBackground(COOLPURPLE); - DrawCircle(SCREENWIDTH / 2, SCREENHEIGHT / 2, 200, BLACK); - DrawText("YOU DIED", (SCREENWIDTH / 2) - 200, (SCREENHEIGHT / 2) - 50, 40, WHITE); - DrawText(game->getCurrent().c_str(), (SCREENWIDTH / 2) - 100, (SCREENHEIGHT / 2) + 50, 40, WHITE); - break ; - } - case (GAMEPLAY): - { - if (auto code = game->getKeys()) { - if (code == 1) // death - {gs = DEATH;} - else if (code == 2) // level end - {gs = NEXT;} + case (DEATH): { + DrawRectangle(250, 150, 1100, 600, COOLPURPLE); + ClearBackground(COOLPURPLE); + DrawCircle(SCREENWIDTH / 2, SCREENHEIGHT / 2, 200, BLACK); + DrawText("YOU DIED", (SCREENWIDTH / 2) - 200, + (SCREENHEIGHT / 2) - 50, 40, WHITE); + DrawText(game->getCurrent().c_str(), (SCREENWIDTH / 2) - 100, + (SCREENHEIGHT / 2) + 50, 40, WHITE); + break; + } + case (GAMEPLAY): { + if (auto code = game->getKeys()) { + if (code == 1) // death + { + gs = DEATH; + } else if (code == 2) // level end + { + gs = NEXT; + } + } + BeginMode2D(game->cam); + game->draw(); + break; + } + case (NEXT): { + ClearBackground(COOLPURPLE); + DrawCircle(SCREENWIDTH / 2, SCREENHEIGHT / 2, 200, BLACK); + DrawText("STAGE CLEARED\nNEXT LEVEL :\n", + (SCREENWIDTH / 2) - 200, (SCREENHEIGHT / 2) - 50, 40, + WHITE); + DrawText(game->getNext().c_str(), (SCREENWIDTH / 2) - 100, + (SCREENHEIGHT / 2) + 60, 40, WHITE); + break; + } + case (ENDING): { + DrawCircle(SCREENWIDTH / 2, SCREENHEIGHT / 2, 200, BLACK); + DrawText("GOOD BYE", (SCREENWIDTH / 2) - 100, SCREENHEIGHT / 2, + 40, WHITE); + break; } - BeginMode2D(game->cam); - game->draw(); - break ; - } - case (NEXT): - { - ClearBackground(COOLPURPLE); - DrawCircle(SCREENWIDTH / 2, SCREENHEIGHT / 2, 200, BLACK); - DrawText("STAGE CLEARED\nNEXT LEVEL :\n", (SCREENWIDTH / 2) - 200, (SCREENHEIGHT / 2) - 50, 40, WHITE); - DrawText(game->getNext().c_str(), (SCREENWIDTH / 2) - 100, (SCREENHEIGHT / 2) + 60, 40, WHITE); - break ; - } - case (ENDING): - { - DrawCircle(SCREENWIDTH / 2, SCREENHEIGHT / 2, 200, BLACK); - DrawText("GOOD BYE", (SCREENWIDTH / 2) - 100, SCREENHEIGHT / 2, 40, WHITE); - break ; } + EndDrawing(); } - EndDrawing(); - } - CloseWindow(); - return 0; + CloseWindow(); + return 0; } diff --git a/src/powerup.hpp b/src/powerup.hpp index ce14997..a88a035 100644 --- a/src/powerup.hpp +++ b/src/powerup.hpp @@ -2,9 +2,9 @@ #define POWERUP_H_ class Powerup { - public: - Powerup(); - virtual ~Powerup(); + public: + Powerup(); + virtual ~Powerup(); }; -#endif // POWERUP_H_ +#endif // POWERUP_H_ diff --git a/src/terrain.cpp b/src/terrain.cpp index 42ee676..53aeac4 100644 --- a/src/terrain.cpp +++ b/src/terrain.cpp @@ -2,10 +2,6 @@ #include <iostream> +Terrain::Terrain(int const& x, int const& y, int const& thick) {} -Terrain::Terrain(int const & x, int const & y, int const & thick) -{ -} - -Terrain::~Terrain(void) { -} +Terrain::~Terrain(void) {} diff --git a/src/terrain.hpp b/src/terrain.hpp index 7c21460..798d997 100644 --- a/src/terrain.hpp +++ b/src/terrain.hpp @@ -2,10 +2,9 @@ #define TERRAIN_H_ class Terrain { - public: - Terrain(int const & x, int const & y, int const & thick); - ~Terrain(); - + public: + Terrain(int const& x, int const& y, int const& thick); + ~Terrain(); }; -#endif // TERRAIN_H_ +#endif // TERRAIN_H_ diff --git a/src/weapon.cpp b/src/weapon.cpp index b52d830..6f52217 100644 --- a/src/weapon.cpp +++ b/src/weapon.cpp @@ -10,14 +10,13 @@ #include <iostream> -AWeapon::AWeapon(float const rg, - unsigned int const & dmg, - unsigned int const & mag, - double const & cd, - const char *s, - const char *r) : - range(rg), damage(dmg), max(mag), cooldown(cd) -{ +AWeapon::AWeapon(float const rg, + unsigned int const& dmg, + unsigned int const& mag, + double const& cd, + const char* s, + const char* r) + : range(rg), damage(dmg), max(mag), cooldown(cd) { shot = LoadSound(s); reload = LoadSound(r); SetSoundVolume(shot, 0.3f); @@ -27,8 +26,7 @@ AWeapon::AWeapon(float const rg, AWeapon::~AWeapon() {} -void AWeapon::refill() -{ +void AWeapon::refill() { std::cout << "reload" << std::endl; PlaySound(reload); barrel = max; diff --git a/src/weapon.hpp b/src/weapon.hpp index b6e8c99..0120928 100644 --- a/src/weapon.hpp +++ b/src/weapon.hpp @@ -16,33 +16,32 @@ class Entity; class AWeapon { -protected: - Sound shot; - Sound reload; + protected: + Sound shot; + Sound reload; - unsigned int max; + unsigned int max; - double cooldown; - double t; + double cooldown; + double t; + float const range; + unsigned int const& damage; - float const range; - unsigned int const &damage; - -public: + public: AWeapon(float const rg, - unsigned int const &dmg, - unsigned int const & mag, - double const & cooldown, - const char *s, - const char *r); - ~AWeapon(); - - virtual int bang(std::vector<Entity> * enemies, Entity * player) = 0; - void refill(); - - bool empty; - unsigned int barrel; + unsigned int const& dmg, + unsigned int const& mag, + double const& cooldown, + const char* s, + const char* r); + ~AWeapon(); + + virtual int bang(std::vector<Entity>* enemies, Entity* player) = 0; + void refill(); + + bool empty; + unsigned int barrel; }; -#endif // WEAPON_H_ +#endif // WEAPON_H_ diff --git a/src/window.cpp b/src/window.cpp index bc78427..a85c12c 100644 --- a/src/window.cpp +++ b/src/window.cpp @@ -8,8 +8,7 @@ #include "window.hpp" -int -initWindow(void) { +int initWindow(void) { // Initialization SetTargetFPS(60); diff --git a/src/window.hpp b/src/window.hpp index ac018c0..b2f62c8 100644 --- a/src/window.hpp +++ b/src/window.hpp @@ -13,11 +13,16 @@ int initWindow(void); -#define SCREENWIDTH 1600 +#define SCREENWIDTH 1600 #define SCREENHEIGHT 900 typedef enum gameState { -TITLE = 0, PICK, DEATH, GAMEPLAY, NEXT, ENDING -} gameState ; + TITLE = 0, + PICK, + DEATH, + GAMEPLAY, + NEXT, + ENDING +} gameState; -#endif // WINDOW_H_ +#endif // WINDOW_H_ diff --git a/src/wp_assaultrifle.cpp b/src/wp_assaultrifle.cpp index 2d4ab0f..e12b440 100644 --- a/src/wp_assaultrifle.cpp +++ b/src/wp_assaultrifle.cpp @@ -1,21 +1,16 @@ #include "wp_assaultrifle.hpp" -#include <iostream> -#include <raymath.h> #include <raylib.h> +#include <raymath.h> +#include <iostream> #include "entity.hpp" -wp_assaultrifle::wp_assaultrifle(const char *s, const char *r) - : AWeapon(300.0f, 10, 30, 0.0, s, r) -{} - - +wp_assaultrifle::wp_assaultrifle(const char* s, const char* r) + : AWeapon(300.0f, 10, 30, 0.0, s, r) {} -int wp_assaultrifle::bang(std::vector<Entity> * enemies, Entity * player) -{ - if (barrel == 0) - { +int wp_assaultrifle::bang(std::vector<Entity>* enemies, Entity* player) { + if (barrel == 0) { return (1); } else { Vector2 playerDirection = Vector2Normalize(player->direction); @@ -37,36 +32,35 @@ int wp_assaultrifle::bang(std::vector<Entity> * enemies, Entity * player) r = playerDirection; r.x *= 2; r.y *= 2; - for (auto en = enemies->begin(); en != enemies->end(); en++) - { - if (CheckCollisionPointLine((Vector2){en->posX, en->posY}, playerPosition, add1, (en->radius * 2)) || - CheckCollisionPointLine((Vector2){en->posX, en->posY}, playerPosition, Vector2Add(playerPosition, r), (en->radius * 2)) || - CheckCollisionPointLine((Vector2){en->posX, en->posY}, playerPosition, add2, (en->radius * 2))) - { // enemy hit + for (auto en = enemies->begin(); en != enemies->end(); en++) { + if (CheckCollisionPointLine((Vector2){en->posX, en->posY}, + playerPosition, add1, + (en->radius * 2)) || + CheckCollisionPointLine( + (Vector2){en->posX, en->posY}, playerPosition, + Vector2Add(playerPosition, r), (en->radius * 2)) || + CheckCollisionPointLine((Vector2){en->posX, en->posY}, + playerPosition, add2, + (en->radius * 2))) { // enemy hit std::cout << "hit" << std::endl; en->hp--; - if (en->hp == 0) - { + if (en->hp == 0) { en->direction.x = (playerDirection.x / 2); en->direction.y = (playerDirection.y / 2); player->victims += 1; } player->fury += 1; - break ; + break; } } // assaultrifle cone DrawLineEx(playerPosition, add1, 10, ORANGE); - DrawLineEx(playerPosition, - Vector2Add(playerPosition, - r), - 10, ORANGE); + DrawLineEx(playerPosition, Vector2Add(playerPosition, r), 10, ORANGE); DrawLineEx(playerPosition, add2, 10, ORANGE); // // there - if (barrel == 0) - { + if (barrel == 0) { empty = true; } return (0); diff --git a/src/wp_assaultrifle.hpp b/src/wp_assaultrifle.hpp index c8016da..89ce8e6 100644 --- a/src/wp_assaultrifle.hpp +++ b/src/wp_assaultrifle.hpp @@ -12,12 +12,11 @@ #include "weapon.hpp" class wp_assaultrifle : public AWeapon { - public: - wp_assaultrifle(const char *s, const char *r); - ~wp_assaultrifle(); + public: + wp_assaultrifle(const char* s, const char* r); + ~wp_assaultrifle(); - int bang(std::vector<Entity> * enemies, Entity * player); + int bang(std::vector<Entity>* enemies, Entity* player); }; - #endif diff --git a/src/wp_shotty.cpp b/src/wp_shotty.cpp index e60e0aa..3ffceca 100644 --- a/src/wp_shotty.cpp +++ b/src/wp_shotty.cpp @@ -1,22 +1,16 @@ #include "wp_shotty.hpp" -#include <iostream> -#include <raymath.h> #include <raylib.h> +#include <raymath.h> +#include <iostream> #include "entity.hpp" -wp_shotty::wp_shotty(const char *s, const char *r) - : AWeapon(100.0f, 10, 10, 0.5, s, r) -{} - - +wp_shotty::wp_shotty(const char* s, const char* r) + : AWeapon(100.0f, 10, 10, 0.5, s, r) {} -int wp_shotty::bang(std::vector<Entity> * enemies, Entity * player) -{ - if (barrel == 0 || - GetTime() < (t + cooldown)) - { +int wp_shotty::bang(std::vector<Entity>* enemies, Entity* player) { + if (barrel == 0 || GetTime() < (t + cooldown)) { return (1); } else { Vector2 playerDirection = Vector2Normalize(player->direction); @@ -39,16 +33,19 @@ int wp_shotty::bang(std::vector<Entity> * enemies, Entity * player) r.x *= 2; r.y *= 2; - for (auto en = enemies->begin(); en != enemies->end(); en++) - { - if (CheckCollisionPointLine((Vector2){en->posX, en->posY}, playerPosition, add1, (en->radius * 2)) || - CheckCollisionPointLine((Vector2){en->posX, en->posY}, playerPosition, Vector2Add(playerPosition, r), (en->radius * 2)) || - CheckCollisionPointLine((Vector2){en->posX, en->posY}, playerPosition, add2, (en->radius * 2))) - { // enemy hit + for (auto en = enemies->begin(); en != enemies->end(); en++) { + if (CheckCollisionPointLine((Vector2){en->posX, en->posY}, + playerPosition, add1, + (en->radius * 2)) || + CheckCollisionPointLine( + (Vector2){en->posX, en->posY}, playerPosition, + Vector2Add(playerPosition, r), (en->radius * 2)) || + CheckCollisionPointLine((Vector2){en->posX, en->posY}, + playerPosition, add2, + (en->radius * 2))) { // enemy hit std::cout << "hit" << std::endl; en->hp--; - if (en->hp == 0) - { + if (en->hp == 0) { en->direction.x = (playerDirection.x / 2); en->direction.y = (playerDirection.y / 2); player->victims += 1; @@ -58,16 +55,12 @@ int wp_shotty::bang(std::vector<Entity> * enemies, Entity * player) } // shotty cone DrawLineEx(playerPosition, add1, 10, ORANGE); - DrawLineEx(playerPosition, - Vector2Add(playerPosition, - r), - 10, ORANGE); + DrawLineEx(playerPosition, Vector2Add(playerPosition, r), 10, ORANGE); DrawLineEx(playerPosition, add2, 10, ORANGE); // // there - if (barrel == 0) - { + if (barrel == 0) { empty = true; } return (0); diff --git a/src/wp_shotty.hpp b/src/wp_shotty.hpp index 48e443a..c7d4074 100644 --- a/src/wp_shotty.hpp +++ b/src/wp_shotty.hpp @@ -12,12 +12,11 @@ #include "weapon.hpp" class wp_shotty : public AWeapon { - public: - wp_shotty(const char *s, const char *r); - ~wp_shotty(); + public: + wp_shotty(const char* s, const char* r); + ~wp_shotty(); - int bang(std::vector<Entity> * enemies, Entity * player) ; + int bang(std::vector<Entity>* enemies, Entity* player); }; - #endif |