diff options
-rw-r--r-- | meta/maps/stage_1_boss.bfm | 2 | ||||
-rw-r--r-- | meta/maps/stage_1_start.bfm | 2 | ||||
-rw-r--r-- | src/entity.cpp | 1 | ||||
-rw-r--r-- | src/entity.hpp | 1 | ||||
-rw-r--r-- | src/gameplay.cpp | 30 | ||||
-rw-r--r-- | src/powerup.hpp | 10 |
6 files changed, 33 insertions, 13 deletions
diff --git a/meta/maps/stage_1_boss.bfm b/meta/maps/stage_1_boss.bfm index 5765667..9f4e6bc 100644 --- a/meta/maps/stage_1_boss.bfm +++ b/meta/maps/stage_1_boss.bfm @@ -1,2 +1,2 @@ -E 1: +E 1 100 S 10 diff --git a/meta/maps/stage_1_start.bfm b/meta/maps/stage_1_start.bfm index dcc2753..bfc81b6 100644 --- a/meta/maps/stage_1_start.bfm +++ b/meta/maps/stage_1_start.bfm @@ -1,2 +1,2 @@ -E 40 +E 10 20 S 1 diff --git a/src/entity.cpp b/src/entity.cpp index 69bec00..75e900a 100644 --- a/src/entity.cpp +++ b/src/entity.cpp @@ -17,6 +17,7 @@ Entity::Entity(void) : hp(1) } else { direction = (Vector2){-posX / 100, posY / 100}; } + radius = 10; } Entity::~Entity() {} diff --git a/src/entity.hpp b/src/entity.hpp index 190df40..39ca07e 100644 --- a/src/entity.hpp +++ b/src/entity.hpp @@ -16,6 +16,7 @@ class Entity { public: int hp; + int radius; float posX; float posY; Vector2 direction; diff --git a/src/gameplay.cpp b/src/gameplay.cpp index b424229..f04d2ef 100644 --- a/src/gameplay.cpp +++ b/src/gameplay.cpp @@ -15,6 +15,7 @@ Game::Game(std::string const & path) { std::ifstream ifs(path); std::string tok; + auto radius = 10; std::cout << "Init: reading map file [" << path << "]" << std::endl; while (ifs >> tok) @@ -22,16 +23,23 @@ Game::Game(std::string const & path) if (tok == "E") { ifs >> tok; - std::cout << "will spawn " << tok << " enemies" << std::endl; + std::cout << "will spawn " << tok << " enemies"; nEnemies = std::atoi(tok.c_str()); + ifs >> tok; + radius = std::atoi(tok.c_str()); } } enemies = new std::vector<Entity>(nEnemies); + for (auto en = enemies->begin(); en != enemies->end(); en++) { + en->radius = radius; + } player = new Entity; player->posX = SCREENWIDTH / 2; player->posY = SCREENHEIGHT / 2; player->direction.x = 100; player->direction.y = 100; + player->radius = 10; + ifs.close(); } Game::~Game() @@ -51,7 +59,7 @@ void Game::draw() const auto left = std::to_string(nEnemies); for (auto & en : *enemies) { - DrawCircleV((Vector2){en.posX, en.posY}, 10, RED); + DrawCircleV((Vector2){en.posX, en.posY}, en.radius, RED); } DrawCircleV((Vector2){player->posX, player->posY}, 10, GREEN); DrawText("Enemies left : ", 10, 10, 20, GREEN); @@ -112,7 +120,8 @@ int Game::getKeys() const if (IsKeyPressed(KEY_SPACE)) { for (auto en = enemies->begin(); en != enemies->end(); en++) { - if (CheckCollisionPointLine((Vector2){en->posX, en->posY}, (Vector2){player->posX, player->posY}, Vector2Add((Vector2){player->posX, player->posY}, player->direction), 20)) + if (CheckCollisionPointLine((Vector2){en->posX, en->posY}, + (Vector2){player->posX, player->posY}, Vector2Add((Vector2){player->posX, player->posY}, player->direction), (en->radius * 2))) { std::cout << "hit enemy at " << en->posX << "|" << en->posY << std::endl; @@ -120,15 +129,14 @@ int Game::getKeys() const return (0); } } - DrawLineEx((Vector2){player->posX, player->posY}, Vector2Add((Vector2){player->posX, player->posY}, player->direction), 20, RED); - + DrawLineEx((Vector2){player->posX, player->posY}, Vector2Add((Vector2){player->posX, player->posY}, (Vector2){player->direction.x + 15, player->direction.y + 15}), 10, ORANGE); + DrawLineEx((Vector2){player->posX, player->posY}, Vector2Add((Vector2){player->posX, player->posY}, (Vector2){player->direction.x + 7, player->direction.y + 7}), 10, ORANGE); + DrawLineEx((Vector2){player->posX, player->posY}, Vector2Add((Vector2){player->posX, player->posY}, player->direction), 10, ORANGE); + DrawLineEx((Vector2){player->posX, player->posY}, Vector2Add((Vector2){player->posX, player->posY}, (Vector2){player->direction.x - 7, player->direction.y - 7}), 10, ORANGE); + DrawLineEx((Vector2){player->posX, player->posY}, Vector2Add((Vector2){player->posX, player->posY}, (Vector2){player->direction.x - 15, player->direction.y - 15}), 10, ORANGE); } - if (oldX != player->posX || - oldY != player->posY) - { - if (this->tick()) { - return (1); - } + if (this->tick()) { + return (1); } aimer.x = (player->direction.x / 3); aimer.y = (player->direction.y / 3); diff --git a/src/powerup.hpp b/src/powerup.hpp new file mode 100644 index 0000000..ce14997 --- /dev/null +++ b/src/powerup.hpp @@ -0,0 +1,10 @@ +#ifndef POWERUP_H_ +#define POWERUP_H_ + +class Powerup { + public: + Powerup(); + virtual ~Powerup(); +}; + +#endif // POWERUP_H_ |