aboutsummaryrefslogtreecommitdiff
path: root/src/gameScreen.c
diff options
context:
space:
mode:
authornathansmithsmith <nathansmith7@mailfence.com>2023-11-05 00:07:55 -0600
committernathansmithsmith <nathansmith7@mailfence.com>2023-11-05 00:07:55 -0600
commit451887dabd71b6b9b8cdf2587fee31ec59c3675b (patch)
tree0129a76d755c222dd62cd418f184ed1c7254aa79 /src/gameScreen.c
parentf45d32ca36a0ae85410b3eee61120fa97bf9bd25 (diff)
Started working on cool stars
Diffstat (limited to 'src/gameScreen.c')
-rw-r--r--src/gameScreen.c63
1 files changed, 53 insertions, 10 deletions
diff --git a/src/gameScreen.c b/src/gameScreen.c
index 8cb9424..036107d 100644
--- a/src/gameScreen.c
+++ b/src/gameScreen.c
@@ -14,7 +14,7 @@ void initGameScreenGui(GameScreen * gameScreen) {
gameScreen->targetInfoPosition = (Vector2){
width - (GAME_SCREEN_TEXT_SIZE * (GAME_SCREEN_TARGET_INFO_MAX / 2.0)),
- height / 3.0
+ height - RADAR_TEXTURE_SIZE - (GAME_SCREEN_TEXT_SIZE * 4.0)
};
gameScreen->zoomViewPosition = (Vector2){width - GAME_SCREEN_ZOOM_VIEW_UI_SIZE - 20.0, 10.0};
@@ -160,7 +160,7 @@ void drawGameScreenGui(Game * game) {
GameScreen * gameScreen = &game->gameScreen;
// Draw cross hair.
- if (gameScreen->mainCamera == FIRST_PERSON_CAMERA) {
+ if (gameScreen->mainCamera == FIRST_PERSON_CAMERA || gameScreen->mainCamera == ZOOM_CAMERA) {
// Get color depending if on target or not.
Entity * player = getEntityFromWorld(game->world, 0);
AntifaShip * data = (AntifaShip*)player->data;
@@ -243,9 +243,41 @@ void gameScreenHandleLevels(Game * game, GameScreen * gameScreen) {
}
}
+void renderStars(Game * game) {
+ Entity * player = getEntityFromWorld(game->world, 0);
+
+ float starSpacing = 30.0;
+
+ Vector3 startPosition = player->position;
+ startPosition = Vector3Scale(startPosition, 1.0 / starSpacing);
+ startPosition = (Vector3){(int)startPosition.x, (int)startPosition.y, (int)startPosition.z};
+ startPosition = Vector3Scale(startPosition, starSpacing);
+
+ Vector3 endAt = Vector3Subtract(player->position, startPosition);
+ endAt = Vector3Zero();
+ endAt = Vector3AddValue(endAt, 200.0);
+
+ for (float z = -endAt.z; z < endAt.z; z += starSpacing) {
+ for (float y = -endAt.y; y < endAt.y; y += starSpacing) {
+ for (float x = -endAt.x; x < endAt.x; x += starSpacing) {
+ Vector3 starPosition = Vector3Add((Vector3){x, y, z}, startPosition);
+ float starDistance = Vector3Distance(player->position, starPosition);
+
+ if (starDistance < 100.0)
+ continue;
+
+ DrawPoint3D(starPosition, (Color){0xff, 0xff, 0xff, 0xff - (starDistance * 10.0)});
+ }
+ }
+ }
+}
+
void renderWorldGameScreen(Game * game, GameScreen * gameScreen) {
BeginMode3D(game->cameras[gameScreen->mainCamera]);
+ //DrawModel(game->assets.models[SKY_ASSET], Vector3Zero(), 500.0, WHITE);
+ renderStars(game);
+
// Draw world.
drawWorld(&game->world, game);
@@ -253,14 +285,19 @@ void renderWorldGameScreen(Game * game, GameScreen * gameScreen) {
}
void drawZoomViewGameScreen(Game * game, GameScreen * gameScreen) {
+ CameraId cameraId = ZOOM_CAMERA;
+
+ if (gameScreen->mainCamera == ZOOM_CAMERA)
+ cameraId = THIRD_PERSON_CAMERA;
+
// Update camera.
- runCameraUpdate(game, game->cameras, ZOOM_CAMERA);
+ runCameraUpdate(game, game->cameras, cameraId);
// Render onto texture.
BeginTextureMode(gameScreen->zoomViewTexture);
ClearBackground(BLACK);
- BeginMode3D(game->cameras[ZOOM_CAMERA]);
+ BeginMode3D(game->cameras[cameraId]);
drawWorld(&game->world, game);
EndMode3D();
@@ -282,14 +319,16 @@ void drawZoomViewGameScreen(Game * game, GameScreen * gameScreen) {
);
// Draw cross hair.
- float halfSize = GAME_SCREEN_ZOOM_VIEW_UI_SIZE / 2.0;
- Vector2 crossHairPosition = Vector2Add(gameScreen->zoomViewPosition, (Vector2){halfSize, halfSize});
+ if (cameraId == ZOOM_CAMERA) {
+ 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;
+ Entity * player = getEntityFromWorld(game->world, 0);
+ AntifaShip * data = (AntifaShip*)player->data;
+ Color color = data->isOnTarget ? RED : BLUE;
- drawCrossHairPosition(crossHairPosition, 4.0, 2.0, color);
+ drawCrossHairPosition(crossHairPosition, 4.0, 2.0, color);
+ }
// Draw outline.
DrawRectangleLines(
@@ -345,6 +384,10 @@ void updateGameScreen(Game * game) {
drawGameScreenGui(game);
}
+void resizeGameScreen(Game * game, GameScreen * gameScreen) {
+ initGameScreenGui(gameScreen);
+}
+
void openGameScreen(Game * game) {
game->screenId = SCREEN_GAME;