aboutsummaryrefslogtreecommitdiff
path: root/src/radar.c
diff options
context:
space:
mode:
authornathansmithsmith <nathansmith7@mailfence.com>2023-09-23 21:25:54 -0600
committernathansmithsmith <nathansmith7@mailfence.com>2023-09-23 21:25:54 -0600
commitc8132c56f0d1d712e4841a60f9f0f853e7177715 (patch)
treee770618d1d3acd7f2768c51ad497e318d1dbd286 /src/radar.c
parent6ba19e2332162de3225d60ae2a377a894ab7299f (diff)
Radar working
Diffstat (limited to 'src/radar.c')
-rw-r--r--src/radar.c106
1 files changed, 106 insertions, 0 deletions
diff --git a/src/radar.c b/src/radar.c
new file mode 100644
index 0000000..1aca7ca
--- /dev/null
+++ b/src/radar.c
@@ -0,0 +1,106 @@
+#include "radar.h"
+#include "game.h"
+#include "entity.h"
+#include "world.h"
+#include "assets.h"
+
+void initRadar(Radar * radar) {
+ resetRadarPosition(radar);
+
+ radar->camera = (Camera3D){
+ .fovy = 45.0,
+ .projection = CAMERA_PERSPECTIVE,
+ .target = Vector3Zero(),
+ .position = (Vector3){RADAR_CAMERA_DISTANCE, RADAR_CAMERA_DISTANCE, RADAR_CAMERA_DISTANCE},
+ .up = (Vector3){0.0, 1.0, 0.0}
+ };
+
+ radar->texture = LoadRenderTexture(RADAR_TEXTURE_SIZE, RADAR_TEXTURE_SIZE);
+}
+
+void closeRadar(Radar * radar) {
+ UnloadRenderTexture(radar->texture);
+}
+
+void resetRadarPosition(Radar * radar) {
+ float width = GetScreenWidth();
+ float height = GetScreenHeight();
+
+ radar->position = (Vector2){
+ width - RADAR_TEXTURE_SIZE,
+ height - RADAR_TEXTURE_SIZE
+ };
+}
+
+void drawRadar3DParts(Game * game, Radar * radar) {
+ int i;
+
+ World * world = &game->world;
+ Entity * player = getEntityFromWorld(*world, 0);
+
+ BeginTextureMode(radar->texture);
+ ClearBackground(RADAR_COLOR);
+ BeginMode3D(radar->camera);
+
+ // Draw entities on radar. Skip player.
+ for (i = 1; i < world->entitiesCount; ++i) {
+ Entity * entity = &world->entities[i];
+
+ // Too far.
+ if (Vector3Distance(player->position, entity->position) > RADAR_MAX_DISTANCE)
+ continue;
+
+ DrawSphere(
+ Vector3Scale(Vector3Subtract(entity->position, player->position), RADAR_WORLD_SCALE),
+ RADAR_POINT_SIZE,
+ BLACK
+ );
+ }
+
+ Vector3 direction = Vector3Scale(
+ Vector3RotateByQuaternion((Vector3){0.0, 0.0, 1.0}, player->rotation),
+ RADAR_POINT_SIZE * 2.0
+ );
+
+ // Draw player.
+ DrawCylinderWiresEx(
+ Vector3Scale(direction, -1.0),
+ direction,
+ RADAR_POINT_SIZE,
+ 0.0,
+ 8,
+ BLUE
+ );
+
+ EndMode3D();
+ EndTextureMode();
+
+ // Draw render texture.
+ DrawTextureV(radar->texture.texture, radar->position, WHITE);
+
+}
+
+void drawRadar(Game * game, Radar * radar) {
+ drawRadar3DParts(game, radar);
+
+ // Draw cross.
+ float halfWayPoint = RADAR_TEXTURE_SIZE / 2.0;
+
+ // Top to bottom.
+ // DrawLine(
+ // radar->position.x + halfWayPoint,
+ // radar->position.y,
+ // radar->position.x + halfWayPoint,
+ // radar->position.y + RADAR_TEXTURE_SIZE,
+ // RADAR_CROSS_COLOR
+ // );
+ //
+ // // Left to right.
+ // DrawLine(
+ // radar->position.x,
+ // radar->position.y + halfWayPoint,
+ // radar->position.x + RADAR_TEXTURE_SIZE,
+ // radar->position.y + halfWayPoint,
+ // RADAR_CROSS_COLOR
+ // );
+}