aboutsummaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorsalaaad2 <arthurdurant263@gmail.com>2022-01-04 19:11:24 +0100
committersalaaad2 <arthurdurant263@gmail.com>2022-01-04 19:11:24 +0100
commit91ecc3578a0016d10d279f1d5761c97161ef341e (patch)
treec07751407ea46940403ba543049051d26151afef /src
parentcool fury ! (diff)
downloadthreshold-91ecc3578a0016d10d279f1d5761c97161ef341e.tar.gz
threshold-91ecc3578a0016d10d279f1d5761c97161ef341e.tar.bz2
threshold-91ecc3578a0016d10d279f1d5761c97161ef341e.tar.xz
threshold-91ecc3578a0016d10d279f1d5761c97161ef341e.tar.zst
threshold-91ecc3578a0016d10d279f1d5761c97161ef341e.zip
add readme and optimize shooting vectors
Diffstat (limited to '')
-rw-r--r--src/gameplay.cpp14
1 files changed, 9 insertions, 5 deletions
diff --git a/src/gameplay.cpp b/src/gameplay.cpp
index decbd74..f52f665 100644
--- a/src/gameplay.cpp
+++ b/src/gameplay.cpp
@@ -124,11 +124,16 @@ 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}, Vector2Add((Vector2){player->posX, player->posY}, Vector2Rotate(player->direction, -0.2f)), (en->radius * 2)) ||
+ 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}, Vector2Add((Vector2){player->posX, player->posY}, Vector2Rotate(player->direction, 0.2f)), (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;
@@ -137,9 +142,9 @@ int Game::getKeys() const
return (0);
}
}
- DrawLineEx((Vector2){player->posX, player->posY}, Vector2Add((Vector2){player->posX, player->posY}, Vector2Rotate(player->direction, -0.2f)), 10, ORANGE);
+ 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}, Vector2Add((Vector2){player->posX, player->posY}, Vector2Rotate(player->direction, 0.2f)), 10, ORANGE);
+ DrawLineEx((Vector2){player->posX, player->posY}, add2, 10, ORANGE);
}
if (player->threshold)
{
@@ -155,7 +160,6 @@ int Game::getKeys() const
return (1);
}
}
-
aimer.x = (player->direction.x / 3);
aimer.y = (player->direction.y / 3);
DrawLineEx((Vector2){player->posX, player->posY}, Vector2Add((Vector2){player->posX, player->posY}, aimer), 5, GREEN);