aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authornathansmithsmith <nathansmith7@mailfence.com>2023-09-25 21:35:26 -0600
committernathansmithsmith <nathansmith7@mailfence.com>2023-09-25 21:35:26 -0600
commit6f7b9d89c4e65e99196a751e4c43711a573e9eb4 (patch)
tree6b53e06686efdefa00f3b244bdfaa93553c49ac8
parent8a5dfe2ad57757a38444f736da115c5def870ec5 (diff)
Now switching cameras in game
-rw-r--r--src/cameras.c24
-rw-r--r--src/cameras.h10
-rw-r--r--src/entities/mussolini.h2
-rw-r--r--src/gameScreen.c18
4 files changed, 46 insertions, 8 deletions
diff --git a/src/cameras.c b/src/cameras.c
index 6a960f5..1cf6cee 100644
--- a/src/cameras.c
+++ b/src/cameras.c
@@ -14,18 +14,36 @@ void updateFirstPersonCamera(Game * game, Camera3D * camera) {
Entity * player = getEntityFromWorld(game->world, 0);
Vector3 direction = Vector3RotateByQuaternion((Vector3){0.0, 0.0, 1.0}, player->rotation);
- camera->position = Vector3Add(player->position, Vector3Scale(direction, CAMERA_DIS));
+ camera->position = Vector3Add(player->position, Vector3Scale(direction, FIRST_PERSON_CAMERA_DISTANCE));
camera->target = Vector3Add(camera->position, direction);
camera->up = Vector3RotateByQuaternion((Vector3){0.0, 1.0, 0.0}, player->rotation);
}
+void initThirdPersonCamera(Game * game, Camera3D * camera) {
+ *camera = (Camera3D){
+ .fovy = 90.0,
+ .projection = CAMERA_PERSPECTIVE
+ };
+}
+
+void updateThirdPersonCamera(Game * game, Camera3D * camera) {
+ Entity * player = getEntityFromWorld(game->world, 0);
+ Vector3 direction = Vector3RotateByQuaternion(THIRD_PERSON_CAMERA_DISTANCE, player->rotation);
+
+ camera->position = Vector3Add(player->position, direction);
+ camera->target = player->position;
+ camera->up = Vector3RotateByQuaternion((Vector3){0.0, 1.0, 0.0}, player->rotation);
+}
+
// Callbacks indeed.
const CameraInitCb cameraInitCallbacks[CAMERA_COUNT] = {
- initFirstPersonCamera
+ initFirstPersonCamera,
+ initThirdPersonCamera
};
const CameraCb cameraCallbacks[CAMERA_COUNT] = {
- updateFirstPersonCamera
+ updateFirstPersonCamera,
+ updateThirdPersonCamera
};
void initCameras(Game * game, Cameras cameras) {
diff --git a/src/cameras.h b/src/cameras.h
index c892ee1..debd658 100644
--- a/src/cameras.h
+++ b/src/cameras.h
@@ -3,8 +3,11 @@
#ifndef CAMERAS_H
#define CAMERAS_H
-#define CAMERA_DIS 5.0
-#define CAMERA_COUNT 1
+#define FIRST_PERSON_CAMERA_DISTANCE 5.0
+
+#define THIRD_PERSON_CAMERA_DISTANCE (Vector3){0.0, 10.0, -20.0}
+
+#define CAMERA_COUNT 2
// Each camera has a game loop callback and a init callback.
typedef void (*CameraInitCb)(Game * game, Camera3D * camera);
@@ -14,7 +17,8 @@ extern const CameraInitCb cameraInitCallbacks[CAMERA_COUNT];
extern const CameraCb cameraCallbacks[CAMERA_COUNT];
typedef enum CameraId {
- FIRST_PERSON_CAMERA
+ FIRST_PERSON_CAMERA,
+ THIRD_PERSON_CAMERA
} CameraId;
// A array of the cameras.
diff --git a/src/entities/mussolini.h b/src/entities/mussolini.h
index 625df3c..33968da 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 100.0
+#define MUSSOLINI_MISSILE_DOWN_COOL 0.5
typedef struct Mussolini {
double timeSinceLastMissile;
diff --git a/src/gameScreen.c b/src/gameScreen.c
index 9b14c00..35e495d 100644
--- a/src/gameScreen.c
+++ b/src/gameScreen.c
@@ -58,7 +58,8 @@ void drawGameScreenGui(Game * game) {
char buf[bufSize];
// Draw cross hair.
- drawCrossHair(10.0, 2.0, BLUE);
+ if (gameScreen->mainCamera == FIRST_PERSON_CAMERA)
+ drawCrossHair(10.0, 2.0, BLUE);
Vector3 position = player->position;
Vector3 velocity = player->velocity.velocity;
@@ -88,9 +89,24 @@ void drawGameScreenGui(Game * game) {
drawRadar(game, &gameScreen->radar);
}
+void handleGameScreenInput(Game * game, GameScreen * gameScreen) {
+ switch(GetKeyPressed()) {
+ case KEY_ONE:
+ gameScreen->mainCamera = FIRST_PERSON_CAMERA;
+ break;
+ case KEY_TWO:
+ gameScreen->mainCamera = THIRD_PERSON_CAMERA;
+ break;
+ default:
+ break;
+ }
+}
+
void updateGameScreen(Game * game) {
GameScreen * gameScreen = &game->gameScreen;
+ handleGameScreenInput(game, gameScreen);
+
ClearBackground(BLACK);
drawGameScreenGui(game);