From a143a9e7b5ce7b47f4d2c56b250e089b88a888b5 Mon Sep 17 00:00:00 2001 From: nathansmithsmith Date: Sat, 28 Oct 2023 16:45:35 -0600 Subject: Things change color so you know when its on target --- src/entities/antifaShip.c | 22 ++++++++++++++++++---- src/entities/antifaShip.h | 1 + 2 files changed, 19 insertions(+), 4 deletions(-) (limited to 'src/entities') 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; -- cgit v1.2.3