diff options
author | salaaad2 <arthurdurant263@gmail.com> | 2022-01-06 19:29:58 +0100 |
---|---|---|
committer | salaaad2 <arthurdurant263@gmail.com> | 2022-01-06 19:29:58 +0100 |
commit | d4ccc92a516372e614fde95bbcb69f41e2bb2f11 (patch) | |
tree | 5fac05bb6d86f3b95983d4c8cdedb42f2f44be89 /src/gameplay.cpp | |
parent | longer shotty range, add hit function which does not work (diff) | |
download | threshold-d4ccc92a516372e614fde95bbcb69f41e2bb2f11.tar.gz threshold-d4ccc92a516372e614fde95bbcb69f41e2bb2f11.tar.bz2 threshold-d4ccc92a516372e614fde95bbcb69f41e2bb2f11.tar.xz threshold-d4ccc92a516372e614fde95bbcb69f41e2bb2f11.tar.zst threshold-d4ccc92a516372e614fde95bbcb69f41e2bb2f11.zip |
more dynamic and faster enemy movement
Diffstat (limited to 'src/gameplay.cpp')
-rw-r--r-- | src/gameplay.cpp | 50 |
1 files changed, 27 insertions, 23 deletions
diff --git a/src/gameplay.cpp b/src/gameplay.cpp index 1a4a9e4..bce787b 100644 --- a/src/gameplay.cpp +++ b/src/gameplay.cpp @@ -44,7 +44,7 @@ Game::Game(std::string const & path) } player = new Entity; player->posX = 0; - player->posY = SCREENHEIGHT / 2; + player->posY = SCREENHEIGHT / 2.0f; player->direction.x = 100; player->direction.y = 100; player->radius = 10; @@ -109,25 +109,29 @@ int Game::tick() const 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; - } - if (en->posY >= SCREENHEIGHT || en->posY <= 0) { - en->direction.y = -en->direction.y; - } - if (en->posX >= player->posX) { - en->direction.x -= 0.1f; - } - if (en->posY >= player->posY) { - en->direction.y -= 0.1f; - } - if (en->posX <= player->posX) { - en->direction.x += 0.1f; - } - if (en->posY <= player->posY) { - en->direction.y += 0.1f; - } + { + if (en->posX >= SCREENWIDTH || en->posX <= 0) { + en->direction.x = -en->direction.x; + } + if (en->posY >= SCREENHEIGHT || en->posY <= 0) { + en->direction.y = -en->direction.y; + } + if (en->posX >= player->posX) { + en->posX -= 2.1f; + en->direction.x -= 0.1f; + } + if (en->posY >= player->posY) { + en->posY -= 2.1f; + en->direction.y -= 0.1f; + } + if (en->posX <= player->posX) { + en->posX += 2.1f; + en->direction.x += 0.1f; + } + if (en->posY <= player->posY) { + en->posY += 2.1f; + en->direction.y += 0.1f; + } } else { if (en->posX >= SCREENWIDTH || en->posX <= 0 || en->posY >= SCREENHEIGHT ) { enemies->erase(en); @@ -135,7 +139,7 @@ int Game::tick() const } } - en->posX += en->direction.x; + 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, @@ -246,8 +250,8 @@ Game::shoot() const CheckCollisionPointLine((Vector2){en->posX, en->posY}, (Vector2){player->posX, player->posY}, add2, (en->radius * 2))) { // enemy hit en->hp = 0; - en->direction.x = (player->direction.x / 2); - en->direction.y = (player->direction.y / 2); + en->direction.x = player->direction.x; + en->direction.y = player->direction.y; player->victims++; player->fury++; DrawLineEx((Vector2){player->posX, player->posY}, add1, 10, |