aboutsummaryrefslogtreecommitdiff
path: root/src/gameScreen.c
diff options
context:
space:
mode:
authornathansmithsmith <nathansmith7@mailfence.com>2023-11-04 21:25:01 -0600
committernathansmithsmith <nathansmith7@mailfence.com>2023-11-04 21:25:01 -0600
commitf45d32ca36a0ae85410b3eee61120fa97bf9bd25 (patch)
treed2b199bb12e9e9fe967dca415bf1b7270382774a /src/gameScreen.c
parent5627fd8128957710c6f16330b2bc1bc3251c5355 (diff)
Game play feeling great
Diffstat (limited to 'src/gameScreen.c')
-rw-r--r--src/gameScreen.c81
1 files changed, 72 insertions, 9 deletions
diff --git a/src/gameScreen.c b/src/gameScreen.c
index 2d42284..8cb9424 100644
--- a/src/gameScreen.c
+++ b/src/gameScreen.c
@@ -17,6 +17,8 @@ void initGameScreenGui(GameScreen * gameScreen) {
height / 3.0
};
+ gameScreen->zoomViewPosition = (Vector2){width - GAME_SCREEN_ZOOM_VIEW_UI_SIZE - 20.0, 10.0};
+
// Gyroscope indeed
initGyroscope(&gameScreen->gyroscope);
@@ -30,12 +32,16 @@ void initGameScreenGui(GameScreen * gameScreen) {
void initGameScreen(Game * game, GameScreen * gameScreen) {
initGameScreenGui(gameScreen);
+ // World render.
if (game->settings.useWorldRenderTexture) {
gameScreen->worldRender = LoadRenderTexture(game->settings.renderWidth, game->settings.renderHeight);
gameScreen->usingWorldRenderTexture = true;
} else {
gameScreen->usingWorldRenderTexture = false;
}
+
+ // Zoom view.
+ gameScreen->zoomViewTexture = LoadRenderTexture(GAME_SCREEN_ZOOM_VIEW_SIZE, GAME_SCREEN_ZOOM_VIEW_SIZE);
}
void freeGameScreen(GameScreen * gameScreen) {
@@ -44,28 +50,33 @@ void freeGameScreen(GameScreen * gameScreen) {
if (gameScreen->usingWorldRenderTexture)
UnloadRenderTexture(gameScreen->worldRender);
-}
-void drawCrossHair(float size, float thick, Color color) {
- Vector3 center = (Vector3){GetScreenWidth() / 2.0, GetScreenHeight() / 2.0};
+ UnloadRenderTexture(gameScreen->zoomViewTexture);
+}
+void drawCrossHairPosition(Vector2 position, float size, float thick, Color color) {
// Left to right.
DrawLineEx(
- (Vector2){center.x - size, center.y},
- (Vector2){center.x + size, center.y},
+ (Vector2){position.x - size, position.y},
+ (Vector2){position.x + size, position.y},
thick,
color
);
// Top to bottom.
DrawLineEx(
- (Vector2){center.x, center.y - size},
- (Vector2){center.x, center.y + size},
+ (Vector2){position.x, position.y - size},
+ (Vector2){position.x, position.y + size},
thick,
color
);
}
+void drawCrossHair(float size, float thick, Color color) {
+ Vector2 center = (Vector2){GetScreenWidth() / 2.0, GetScreenHeight() / 2.0};
+ drawCrossHairPosition(center, size, thick, color);
+}
+
void drawGameScreenInfoText(Game * game, GameScreen * gameScreen) {
Entity * player = getEntityFromWorld(game->world, 0);
@@ -173,6 +184,9 @@ void handleGameScreenInput(Game * game, GameScreen * gameScreen) {
gameScreen->mainCamera = THIRD_PERSON_CAMERA;
break;
case KEY_THREE:
+ gameScreen->mainCamera = ZOOM_CAMERA;
+ break;
+ case KEY_FOUR:
gameScreen->mainCamera = DEBUG_CAMERA;
break;
default:
@@ -232,14 +246,61 @@ void gameScreenHandleLevels(Game * game, GameScreen * gameScreen) {
void renderWorldGameScreen(Game * game, GameScreen * gameScreen) {
BeginMode3D(game->cameras[gameScreen->mainCamera]);
- //DrawGrid(50, 25.0);
-
// Draw world.
drawWorld(&game->world, game);
EndMode3D();
}
+void drawZoomViewGameScreen(Game * game, GameScreen * gameScreen) {
+ // Update camera.
+ runCameraUpdate(game, game->cameras, ZOOM_CAMERA);
+
+ // Render onto texture.
+ BeginTextureMode(gameScreen->zoomViewTexture);
+ ClearBackground(BLACK);
+
+ BeginMode3D(game->cameras[ZOOM_CAMERA]);
+ drawWorld(&game->world, game);
+ EndMode3D();
+
+ EndTextureMode();
+
+ // Draw texture.
+ DrawTexturePro(
+ gameScreen->zoomViewTexture.texture,
+ (Rectangle){0.0, 0.0, GAME_SCREEN_ZOOM_VIEW_SIZE, -GAME_SCREEN_ZOOM_VIEW_SIZE},
+ (Rectangle){
+ gameScreen->zoomViewPosition.x,
+ gameScreen->zoomViewPosition.y,
+ GAME_SCREEN_ZOOM_VIEW_UI_SIZE,
+ GAME_SCREEN_ZOOM_VIEW_UI_SIZE,
+ },
+ (Vector2){0.0, 0.0},
+ 0.0,
+ WHITE
+ );
+
+ // Draw cross hair.
+ float halfSize = GAME_SCREEN_ZOOM_VIEW_UI_SIZE / 2.0;
+ Vector2 crossHairPosition = Vector2Add(gameScreen->zoomViewPosition, (Vector2){halfSize, halfSize});
+
+ Entity * player = getEntityFromWorld(game->world, 0);
+ AntifaShip * data = (AntifaShip*)player->data;
+ Color color = data->isOnTarget ? RED : BLUE;
+
+ drawCrossHairPosition(crossHairPosition, 4.0, 2.0, color);
+
+ // Draw outline.
+ DrawRectangleLines(
+ gameScreen->zoomViewPosition.x,
+ gameScreen->zoomViewPosition.y,
+ GAME_SCREEN_ZOOM_VIEW_UI_SIZE,
+ GAME_SCREEN_ZOOM_VIEW_UI_SIZE,
+ GREEN
+ );
+}
+
void updateGameScreen(Game * game) {
GameScreen * gameScreen = &game->gameScreen;
@@ -278,6 +339,8 @@ void updateGameScreen(Game * game) {
renderWorldGameScreen(game, gameScreen);
}
+ drawZoomViewGameScreen(game, gameScreen);
+
// GUI.
drawGameScreenGui(game);
}