aboutsummaryrefslogtreecommitdiff
path: root/src
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
parent6ba19e2332162de3225d60ae2a377a894ab7299f (diff)
Radar working
Diffstat (limited to 'src')
-rw-r--r--src/entities/mussolini.h2
-rw-r--r--src/gameScreen.c5
-rw-r--r--src/gameScreen.h2
-rw-r--r--src/gyroscope.c15
-rw-r--r--src/radar.c106
-rw-r--r--src/radar.h28
6 files changed, 146 insertions, 12 deletions
diff --git a/src/entities/mussolini.h b/src/entities/mussolini.h
index 33968da..625df3c 100644
--- a/src/entities/mussolini.h
+++ b/src/entities/mussolini.h
@@ -6,7 +6,7 @@
#define MUSSOLINI_H
#define MUSSOLINI_TURN_SPEED 1.0
-#define MUSSOLINI_MISSILE_DOWN_COOL 0.5
+#define MUSSOLINI_MISSILE_DOWN_COOL 100.0
typedef struct Mussolini {
double timeSinceLastMissile;
diff --git a/src/gameScreen.c b/src/gameScreen.c
index 24f34d1..0ba7a6a 100644
--- a/src/gameScreen.c
+++ b/src/gameScreen.c
@@ -13,6 +13,9 @@ void initGameScreenGui(GameScreen * gameScreen) {
// Gyroscope indeed
initGyroscope(&gameScreen->gyroscope);
+
+ // Radar indeed.
+ initRadar(&gameScreen->radar);
}
void initGameScreen(GameScreen * gameScreen) {
@@ -21,6 +24,7 @@ void initGameScreen(GameScreen * gameScreen) {
void freeGameScreen(GameScreen * gameScreen) {
closeGyroscope(&gameScreen->gyroscope);
+ closeRadar(&gameScreen->radar);
}
void drawCrossHair(float size, float thick, Color color) {
@@ -79,6 +83,7 @@ void drawGameScreenGui(Game * game) {
);
drawGyroscope(game, &gameScreen->gyroscope);
+ drawRadar(game, &gameScreen->radar);
}
void updateGameScreen(Game * game) {
diff --git a/src/gameScreen.h b/src/gameScreen.h
index 42591a4..9e0f99a 100644
--- a/src/gameScreen.h
+++ b/src/gameScreen.h
@@ -1,5 +1,6 @@
#include "gameCommon.h"
#include "gyroscope.h"
+#include "radar.h"
#ifndef GAME_SCREEN_H
#define GAME_SCREEN_H
@@ -10,6 +11,7 @@
typedef struct GameScreen {
Vector2 infoText;
Gyroscope gyroscope;
+ Radar radar;
} GameScreen;
void initGameScreen(GameScreen * gameScreen);
diff --git a/src/gyroscope.c b/src/gyroscope.c
index 980345c..7b6ee76 100644
--- a/src/gyroscope.c
+++ b/src/gyroscope.c
@@ -7,11 +7,9 @@ void initGyroscope(Gyroscope * gyroscope) {
resetGyroscopePosition(gyroscope);
gyroscope->camera = (Camera3D){
- .fovy = 45,
+ .fovy = 45.0,
.projection = CAMERA_PERSPECTIVE,
- .position = (Vector3){0.0, 0.0, 3.0},
.target = Vector3Zero(),
- .up = (Vector3){0.0, 1.0, 0.0}
};
gyroscope->texture = LoadRenderTexture(
@@ -36,7 +34,7 @@ void resetGyroscopePosition(Gyroscope * gyroscope) {
}
void updateGyroscopeRotation(Entity * player, Gyroscope * gyroscope) {
- // Instead of rotation the gyroscope ball we rotate the camera around it.
+ // Instead of rotating the gyroscope ball we rotate the camera around it.
gyroscope->camera.position = Vector3Scale(
Vector3RotateByQuaternion((Vector3){0.0, 0.0, 1.0}, player->rotation),
GYROSCOPE_CAMERA_DISTANCE
@@ -58,19 +56,14 @@ void drawGyroscope(Game * game, Gyroscope * gyroscope) {
ClearBackground(BLACK);
BeginMode3D(gyroscope->camera);
- // Set transform and draw.
+ // This this fucker!!!
DrawModel(model, Vector3Zero(), 1, WHITE);
EndMode3D();
EndTextureMode();
// Draw render texture.
- DrawTexture(
- gyroscope->texture.texture,
- gyroscope->position.x,
- gyroscope->position.y,
- WHITE
- );
+ DrawTextureV(gyroscope->texture.texture, gyroscope->position, WHITE);
// Top to bottom.
DrawLineEx(
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
+ // );
+}
diff --git a/src/radar.h b/src/radar.h
new file mode 100644
index 0000000..c250e28
--- /dev/null
+++ b/src/radar.h
@@ -0,0 +1,28 @@
+#include "gameCommon.h"
+
+#ifndef RADAR_H
+#define RADAR_H
+
+#define RADAR_TEXTURE_SIZE 200
+#define RADAR_WORLD_SCALE 0.005
+#define RADAR_POINT_SIZE 0.25
+#define RADAR_MAX_DISTANCE 1000.0
+#define RADAR_CAMERA_DISTANCE 6.0
+
+#define RADAR_COLOR (Color){255, 255, 255, 85}
+#define RADAR_CROSS_COLOR (Color){YELLOW.r, YELLOW.g, YELLOW.b, 127}
+
+typedef struct Radar {
+ Vector2 position;
+ Camera3D camera;
+ RenderTexture texture;
+} Radar;
+
+void initRadar(Radar * radar);
+void closeRadar(Radar * radar);
+
+void resetRadarPosition(Radar * radar);
+
+void drawRadar(Game * game, Radar * radar);
+
+#endif