aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authornathansmithsmith <nathansmith7@mailfence.com>2023-10-28 16:45:35 -0600
committernathansmithsmith <nathansmith7@mailfence.com>2023-10-28 16:45:35 -0600
commita143a9e7b5ce7b47f4d2c56b250e089b88a888b5 (patch)
treed364daa65d9e3e0b6b415ab47174e237b899f8e4 /src
parent60fce38926856e1842aab7c14be99336f34b733f (diff)
Things change color so you know when its on target
Diffstat (limited to 'src')
-rw-r--r--src/entities/antifaShip.c22
-rw-r--r--src/entities/antifaShip.h1
-rw-r--r--src/gameScreen.c12
3 files changed, 28 insertions, 7 deletions
diff --git a/src/entities/antifaShip.c b/src/entities/antifaShip.c
index f2e885b..34d394b 100644
--- a/src/entities/antifaShip.c
+++ b/src/entities/antifaShip.c
@@ -33,6 +33,7 @@ void initAntifaShip(Entity * entity, Game * game) {
data->timeSinceLastBullet = GetTime();
data->doAutoTarget = false;
data->targetedEntityId = ENTITY_NONE;
+ data->isOnTarget = false;
}
// Go back to burger king you elon musking loving mother fucker!
@@ -111,7 +112,11 @@ void updateAntifaShipTarget(Game * game, Entity * entity) {
// Update target.
float speed = powf(ANTIFA_TARGETING_SPEED / aimDistance, 2.0);
data->gunTarget = Vector3Lerp(data->gunTarget, directionToTarget, speed * t);
+
+ // Is on target.
+ data->isOnTarget = traceRayToEntity(*targetEntity, (Ray){entity->position, data->gunTarget}).hit;
} else {
+ data->isOnTarget = false;
data->gunTarget = Vector3RotateByQuaternion((Vector3){0.0, 0.0, 1.0}, entity->rotation);
}
}
@@ -262,9 +267,17 @@ void drawAntifaShip(Game * game, Entity * entity) {
// Draw bullet.
AntifaShip * data = (AntifaShip*)entity->data;
- // Debug targetting.
- if (data->doAutoTarget)
- DrawLine3D(entity->position, Vector3Add(Vector3Scale(data->gunTarget, 100), entity->position), YELLOW);
+ // Auto target line.
+ if (data->doAutoTarget) {
+ Entity * targetedEntity = getEntityFromWorld(game->world, data->targetedEntityId);
+
+ if (targetedEntity != NULL)
+ DrawLine3D(
+ entity->position,
+ targetedEntity->position,
+ data->isOnTarget ? RED : BLUE
+ );
+ }
if (IsMouseButtonDown(MOUSE_RIGHT_BUTTON))
DrawCylinderWiresEx(
@@ -279,6 +292,7 @@ void drawAntifaShip(Game * game, Entity * entity) {
BLUE
);
+ // Draw bullet being shot.
if (GetTime() - data->timeSinceLastBullet <= ANTIFA_DRAW_BULLET_FOR)
- DrawRay(data->lastBulletShot.ray, BLUE);
+ DrawRay(data->lastBulletShot.ray, RED);
}
diff --git a/src/entities/antifaShip.h b/src/entities/antifaShip.h
index ce5c71f..50941ca 100644
--- a/src/entities/antifaShip.h
+++ b/src/entities/antifaShip.h
@@ -23,6 +23,7 @@ typedef struct AntifaShip {
Vector3 gunTarget;
bool doAutoTarget;
+ bool isOnTarget;
EntityId targetedEntityId;
EntityFingerprint targetedEntityFingerprint;
} AntifaShip;
diff --git a/src/gameScreen.c b/src/gameScreen.c
index ec26fee..61865bd 100644
--- a/src/gameScreen.c
+++ b/src/gameScreen.c
@@ -120,7 +120,7 @@ void drawGameScreenTargetInfo(Game * game, GameScreen * gameScreen) {
data->targetedEntityId,
data->targetedEntityFingerprint,
Vector3Distance(player->position, targetedEntity->position),
- traceRayToEntity(*targetedEntity, (Ray){player->position, data->gunTarget}).hit ? "Yes" : "No"
+ data->isOnTarget ? "Yes" : "No"
);
}
}
@@ -139,8 +139,14 @@ void drawGameScreenGui(Game * game) {
GameScreen * gameScreen = &game->gameScreen;
// Draw cross hair.
- if (gameScreen->mainCamera == FIRST_PERSON_CAMERA)
- drawCrossHair(10.0, 2.0, BLUE);
+ if (gameScreen->mainCamera == FIRST_PERSON_CAMERA) {
+ // Get color depending if on target or not.
+ Entity * player = getEntityFromWorld(game->world, 0);
+ AntifaShip * data = (AntifaShip*)player->data;
+ Color color = data->isOnTarget ? RED : BLUE;
+
+ drawCrossHair(10.0, 2.0, color);
+ }
drawGameScreenInfoText(game, gameScreen);
drawGameScreenTargetInfo(game, gameScreen);