diff options
-rw-r--r-- | src/gameplay.cpp | 45 | ||||
-rw-r--r-- | src/main.cpp | 6 | ||||
-rw-r--r-- | src/weapon.hpp | 6 | ||||
-rw-r--r-- | src/wp_shotty.cpp | 54 | ||||
-rw-r--r-- | src/wp_shotty.hpp | 2 |
5 files changed, 64 insertions, 49 deletions
diff --git a/src/gameplay.cpp b/src/gameplay.cpp index effd26d..d60c5ca 100644 --- a/src/gameplay.cpp +++ b/src/gameplay.cpp @@ -253,55 +253,14 @@ int Game::getKeys() const 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); - - auto r = player->direction; - r.x *= 2; - r.y *= 2; if (player->wp->empty == true) { return (0); } - if (player->wp->bang() == 1) { - player->wp->empty = true; + player->wp->bang(enemies, player->direction, (Vector2){player->posX, player->posY}); + if (player->wp->empty == true) { player->reloadTime = GetTime(); - return (0); - } - 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}, r), (en->radius * 2)) || - CheckCollisionPointLine((Vector2){en->posX, en->posY}, (Vector2){player->posX, player->posY}, add2, (en->radius * 2))) - { // enemy hit - en->hp--; - if (en->hp == 0) - { - en->direction.x = (player->direction.x / 2); - en->direction.y = (player->direction.y / 2); - player->victims++; - } - player->fury++; - DrawLineEx((Vector2){player->posX, player->posY}, add1, 10, - ORANGE); - DrawLineEx((Vector2){player->posX, player->posY}, - Vector2Add((Vector2){player->posX, player->posY}, - r), - 10, ORANGE); - DrawLineEx((Vector2){player->posX, player->posY}, add2, 10, - ORANGE); - return (1); - } } - // shotty cone - DrawLineEx((Vector2){player->posX, player->posY}, add1, 10, ORANGE); - DrawLineEx((Vector2){player->posX, player->posY}, - Vector2Add((Vector2){player->posX, player->posY}, - r), - 10, ORANGE); - DrawLineEx((Vector2){player->posX, player->posY}, add2, 10, ORANGE); return (0); } diff --git a/src/main.cpp b/src/main.cpp index a24657d..8456928 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -19,7 +19,7 @@ int main(void) { // Main game loop InitWindow(SCREENWIDTH, SCREENHEIGHT, "WIP -- coolspace"); - Game* game = new Game("../meta/maps/stage_1_boss.bfm"); + Game* game = new Game("../meta/maps/stage_1_start.bfm"); while (!WindowShouldClose()) /* Detect window close button or ESC key */ { switch (gs) { @@ -80,9 +80,9 @@ int main(void) { case (GAMEPLAY): { if (auto code = game->getKeys()) { - if (code == 1) + if (code == 1) // death {gs = ENDING;} - else if (code == 2) + else if (code == 2) // level end {gs = NEXT;} } game->draw(); diff --git a/src/weapon.hpp b/src/weapon.hpp index e43b7da..a5099d2 100644 --- a/src/weapon.hpp +++ b/src/weapon.hpp @@ -11,6 +11,10 @@ #include "raylib.h" +#include <vector> + +class Entity; + class AWeapon { protected: Sound shot; @@ -26,7 +30,7 @@ public: AWeapon(float const &rg, unsigned int const &dmg, unsigned int const & mag, const char *s, const char *r); ~AWeapon(); - virtual int bang() = 0; + virtual int bang(std::vector<Entity> * enemies, Vector2 playerDirection, Vector2 playerPosition) = 0; void refill(); bool empty; diff --git a/src/wp_shotty.cpp b/src/wp_shotty.cpp index 13ab834..a0d5de4 100644 --- a/src/wp_shotty.cpp +++ b/src/wp_shotty.cpp @@ -1,6 +1,10 @@ #include "wp_shotty.hpp" #include <iostream> +#include <raymath.h> +#include <raylib.h> + +#include "entity.hpp" wp_shotty::wp_shotty(float const &rg, unsigned int const &dmg, unsigned int const & mag, const char *s, const char *r) : AWeapon(rg, dmg, mag, s, r) @@ -8,7 +12,7 @@ wp_shotty::wp_shotty(float const &rg, unsigned int const &dmg, unsigned int cons -int wp_shotty::bang() +int wp_shotty::bang(std::vector<Entity> * enemies, Vector2 playerDirection, Vector2 playerPosition) { if (barrel == 0) { @@ -17,6 +21,54 @@ int wp_shotty::bang() barrel--; std::cout << "BANG : " << barrel << "shots left" << std::endl; PlaySound(shot); + // here + // + auto rot1 = Vector2Rotate(playerDirection, -0.2f); + auto rot2 = Vector2Rotate(playerDirection, 0.2f); + + auto add1 = Vector2Add(playerPosition, rot1); + auto add2 = Vector2Add(playerPosition, rot2); + + auto r = playerDirection; + r.x *= 2; + r.y *= 2; + + std::cout << "before loop"; + if (enemies == NULL) + { + return (0); + } + for (auto en = enemies->begin(); en != enemies->end(); en++) + { + std::cout << "loop"; + 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 + en->hp--; + if (en->hp == 0) + { + en->direction.x = (playerDirection.x / 2); + en->direction.y = (playerDirection.y / 2); + // player->victims++; + } + } + } + // shotty cone + DrawLineEx(playerPosition, add1, 10, ORANGE); + DrawLineEx(playerPosition, + Vector2Add(playerPosition, + r), + 10, ORANGE); + DrawLineEx(playerPosition, add2, 10, ORANGE); + + // + // there + if (barrel == 0) + { + empty = true; + return (1); + } return (0); } } diff --git a/src/wp_shotty.hpp b/src/wp_shotty.hpp index a01891f..bbeb112 100644 --- a/src/wp_shotty.hpp +++ b/src/wp_shotty.hpp @@ -16,7 +16,7 @@ class wp_shotty : public AWeapon { wp_shotty(float const &rg, unsigned int const &dmg, unsigned int const & mag, const char *s, const char *r); ~wp_shotty(); - int bang() ; + int bang(std::vector<Entity> * enemies, Vector2 playerDirection, Vector2 playerPosition) ; }; |