diff options
Diffstat (limited to 'src/gameScreen.c')
-rw-r--r-- | src/gameScreen.c | 100 |
1 files changed, 99 insertions, 1 deletions
diff --git a/src/gameScreen.c b/src/gameScreen.c index c38b06d..a446f69 100644 --- a/src/gameScreen.c +++ b/src/gameScreen.c @@ -4,6 +4,46 @@ #include "bullets.h" #include <raylib.h> +void initGameScreenGui(GameScreen * gameScreen) { + float width = GetScreenWidth(); + float height = GetScreenHeight(); + + // It is kind of terrible but works. + gameScreen->infoText = (Vector2){0.0, height / 1.5}; + gameScreen->gyroscopePosition = (Vector2){ + (width / 2.0) - (GYROSCOPE_TEXTURE_SIZE / 2.0), + height / 1.8 + + }; +} + +void initGameScreen(GameScreen * gameScreen) { + initGameScreenGui(gameScreen); + + // The gyroscope is rendered is 3d but not in the main scene. + gameScreen->gyroscopeCamaera = (Camera3D){ + .fovy = 45, + .projection = CAMERA_PERSPECTIVE, + .position = (Vector3){0.0, 0.0, -5.0}, + .target = Vector3Zero(), + .up = (Vector3){0.0, 1.0, 0.0} + }; + + gameScreen->gyroscopeTexture = LoadRenderTexture( + GYROSCOPE_TEXTURE_SIZE, + GYROSCOPE_TEXTURE_SIZE + ); + + // Load model. + Mesh mesh = GenMeshSphere(1.0, 4, 4); + gameScreen->gyroscopeModel = LoadModelFromMesh(mesh); +} + +void freeGameScreen(GameScreen * gameScreen) { + UnloadRenderTexture(gameScreen->gyroscopeTexture); + UnloadModel(gameScreen->gyroscopeModel); +} + void drawCrossHair(float size, float thick, Color color) { Vector3 center = (Vector3){GetScreenWidth() / 2.0, GetScreenHeight() / 2.0}; @@ -24,12 +64,70 @@ void drawCrossHair(float size, float thick, Color color) { ); } -void updateGameScreen(Game * game) { +void drawGyroscope(Game * game) { + GameScreen * gameScreen = &game->gameScreen; + Entity * player = getEntityFromWorld(game->world, 0); + + // Draw this mother fucker. + BeginTextureMode(gameScreen->gyroscopeTexture); ClearBackground(BLACK); + BeginMode3D(gameScreen->gyroscopeCamaera); + + DrawSphereWires(Vector3Zero(), 1.0, 8, 8, GREEN); + + EndMode3D(); + EndTextureMode(); + + DrawTexture( + gameScreen->gyroscopeTexture.texture, + gameScreen->gyroscopePosition.x, + gameScreen->gyroscopePosition.y, + WHITE + ); +} + +void drawGameScreenGui(Game * game) { + GameScreen * gameScreen = &game->gameScreen; + Entity * player = getEntityFromWorld(game->world, 0); + + // Hello reader. I fucking hate you! + size_t bufSize = 255; + char buf[bufSize]; // Draw cross hair. drawCrossHair(10.0, 2.0, BLUE); + Vector3 position = player->position; + Vector3 velocity = player->velocity.velocity; + + // Format text. + snprintf( + buf, + bufSize, + "X %.2f\nY %.2f\nZ %.2f\n\nSpeed %.2f", + position.x, + position.y, + position.z, + Vector3Length(velocity) + ); + + // Draw info text. + DrawText( + buf, + gameScreen->infoText.x, + gameScreen->infoText.y, + GAME_SCREEN_TEXT_SIZE, + GREEN + ); + + drawGyroscope(game); +} + +void updateGameScreen(Game * game) { + ClearBackground(BLACK); + + drawGameScreenGui(game); + // Update world. updateWorld(&game->world, game); |