diff options
-rw-r--r-- | meta/maps/stage_1_boss.bfm | 4 | ||||
-rw-r--r-- | meta/maps/stage_1_start.bfm | 4 | ||||
-rw-r--r-- | meta/media/mp3/shotty_reload.mp3 | bin | 0 -> 23584 bytes | |||
-rw-r--r-- | meta/media/mp3/shotty_shoot.mp3 | bin | 0 -> 24468 bytes | |||
-rw-r--r-- | src/gameplay.cpp | 77 | ||||
-rw-r--r-- | src/gameplay.hpp | 5 | ||||
-rw-r--r-- | src/main.cpp | 31 | ||||
-rw-r--r-- | src/window.hpp | 2 |
8 files changed, 94 insertions, 29 deletions
diff --git a/meta/maps/stage_1_boss.bfm b/meta/maps/stage_1_boss.bfm index 9f4e6bc..2987ef6 100644 --- a/meta/maps/stage_1_boss.bfm +++ b/meta/maps/stage_1_boss.bfm @@ -1,2 +1,2 @@ -E 1 100 - S 10 +E 2 100 +N 0 diff --git a/meta/maps/stage_1_start.bfm b/meta/maps/stage_1_start.bfm index bfc81b6..1678c3a 100644 --- a/meta/maps/stage_1_start.bfm +++ b/meta/maps/stage_1_start.bfm @@ -1,2 +1,2 @@ -E 10 20 - S 1 +E 2 20 +N stage_1_boss.bfm diff --git a/meta/media/mp3/shotty_reload.mp3 b/meta/media/mp3/shotty_reload.mp3 Binary files differnew file mode 100644 index 0000000..f60a67e --- /dev/null +++ b/meta/media/mp3/shotty_reload.mp3 diff --git a/meta/media/mp3/shotty_shoot.mp3 b/meta/media/mp3/shotty_shoot.mp3 Binary files differnew file mode 100644 index 0000000..e99498c --- /dev/null +++ b/meta/media/mp3/shotty_shoot.mp3 diff --git a/src/gameplay.cpp b/src/gameplay.cpp index f52f665..59ef73a 100644 --- a/src/gameplay.cpp +++ b/src/gameplay.cpp @@ -28,7 +28,14 @@ Game::Game(std::string const & path) ifs >> tok; radius = std::atoi(tok.c_str()); } + if (tok == "N") + { + ifs >> tok; + next = tok; + std::cout << "next level is " << next; + } } + ifs.close(); enemies = new std::vector<Entity>(nEnemies); for (auto en = enemies->begin(); en != enemies->end(); en++) { en->radius = radius; @@ -39,7 +46,7 @@ Game::Game(std::string const & path) player->direction.x = 100; player->direction.y = 100; player->radius = 10; - ifs.close(); + player->victims = 0; } Game::~Game() @@ -124,27 +131,12 @@ int Game::getKeys() const player->direction = Vector2Rotate(player->direction, 0.1f); } if (IsKeyPressed(KEY_SPACE)) { - auto rot1 = Vector2Rotate(player->direction, -0.2f); - auto rot2 = Vector2Rotate(player->direction, 0.2f); - - auto add1 = Vector2Add((Vector2){player->posX, player->posY}, rot1); - auto add2 = Vector2Add((Vector2){player->posX, player->posY}, rot2); - 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)) || - CheckCollisionPointLine((Vector2){en->posX, en->posY}, (Vector2){player->posX, player->posY}, Vector2Add((Vector2){player->posX, player->posY}, Vector2Rotate(player->direction, 0.0f)), (en->radius * 2)) || - CheckCollisionPointLine((Vector2){en->posX, en->posY}, (Vector2){player->posX, player->posY}, add2, (en->radius * 2))) - { - std::cout << "hit enemy at " << en->posX << "|" << en->posY - << std::endl; - enemies->erase(en); - player->victims++; - return (0); - } + if (shoot()) { + return (0); + } + if (player->victims == nEnemies) { + return (2); } - DrawLineEx((Vector2){player->posX, player->posY}, add1, 10, ORANGE); - DrawLineEx((Vector2){player->posX, player->posY}, Vector2Add((Vector2){player->posX, player->posY}, player->direction), 10, ORANGE); - DrawLineEx((Vector2){player->posX, player->posY}, add2, 10, ORANGE); } if (player->threshold) { @@ -165,3 +157,46 @@ int Game::getKeys() const DrawLineEx((Vector2){player->posX, player->posY}, Vector2Add((Vector2){player->posX, player->posY}, aimer), 5, GREEN); return (0); } + + +int +Game::shoot() const +{ + auto rot1 = Vector2Rotate(player->direction, -0.2f); + auto rot2 = Vector2Rotate(player->direction, 0.2f); + + auto add1 = Vector2Add((Vector2){player->posX, player->posY}, rot1); + auto add2 = Vector2Add((Vector2){player->posX, player->posY}, rot2); + 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)) || + CheckCollisionPointLine((Vector2){en->posX, en->posY}, (Vector2){player->posX, player->posY}, Vector2Add((Vector2){player->posX, player->posY}, Vector2Rotate(player->direction, 0.0f)), (en->radius * 2)) || + CheckCollisionPointLine((Vector2){en->posX, en->posY}, (Vector2){player->posX, player->posY}, add2, (en->radius * 2))) + { + std::cout << "hit enemy at " << en->posX << "|" << en->posY + << std::endl; + enemies->erase(en); + player->victims++; + DrawLineEx((Vector2){player->posX, player->posY}, add1, 10, + ORANGE); + DrawLineEx((Vector2){player->posX, player->posY}, + Vector2Add((Vector2){player->posX, player->posY}, + player->direction), + 10, ORANGE); + DrawLineEx((Vector2){player->posX, player->posY}, add2, 10, + ORANGE); + return (1); + } + } + DrawLineEx((Vector2){player->posX, player->posY}, add1, 10, ORANGE); + DrawLineEx((Vector2){player->posX, player->posY}, + Vector2Add((Vector2){player->posX, player->posY}, + player->direction), + 10, ORANGE); + DrawLineEx((Vector2){player->posX, player->posY}, add2, 10, ORANGE); + return (0); +} + +std::string const & +Game::getNext() const +{return next;} diff --git a/src/gameplay.hpp b/src/gameplay.hpp index 7097995..ccedb0e 100644 --- a/src/gameplay.hpp +++ b/src/gameplay.hpp @@ -22,6 +22,8 @@ class Game { Entity * player; + std::string next; + public: Game(std::string const & path); ~Game(); @@ -30,6 +32,9 @@ class Game { void draw() const ; int tick() const ; int getKeys() const ; + int shoot() const ; + + std::string const & getNext() const ; }; #endif // GAMEPLAY_H_ diff --git a/src/main.cpp b/src/main.cpp index 74b1adf..3136318 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -35,13 +35,31 @@ int main(void) { { break ; } + case (NEXT): + { + if (IsKeyPressed(KEY_ENTER)) + { + gs = TITLE; + std::string next("../meta/maps/"); + next += game->getNext(); + + delete game; + if (next != "0") { + game = new Game(next); + } + } + break ; + } case (ENDING): { if (IsKeyPressed(KEY_ENTER)) { gs = TITLE; + auto next = game->getNext(); delete game; - game = new Game("../meta/maps/stage_1_start.bfm"); + if (next != "0") { + game = new Game("../meta/maps/stage_1_start.bfm"); + } } break ; } @@ -59,12 +77,19 @@ int main(void) { } case (GAMEPLAY): { - if (game->getKeys()) { - gs = ENDING; + if (auto code = game->getKeys()) { + if (code == 1) + gs = ENDING; + else if (code == 2) + gs = NEXT; } game->draw(); break ; } + case (NEXT): + { + break ; + } case (ENDING): { DrawCircle(SCREENWIDTH / 2, SCREENHEIGHT / 2, 200, BLACK); diff --git a/src/window.hpp b/src/window.hpp index 6316bfa..bba7c07 100644 --- a/src/window.hpp +++ b/src/window.hpp @@ -17,7 +17,7 @@ int initWindow(void); #define SCREENHEIGHT 900 typedef enum gameState { -TITLE = 0, GAMEPLAY, ENDING +TITLE = 0, GAMEPLAY, NEXT, ENDING } gameState ; #endif // WINDOW_H_ |