#include "gameScreen.h" #include "game.h" #include "world.h" #include "bullets.h" #include "assets.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, 3.0}, .target = Vector3Zero(), .up = (Vector3){0.0, 1.0, 0.0} }; gameScreen->gyroscopeTexture = LoadRenderTexture( GYROSCOPE_TEXTURE_SIZE, GYROSCOPE_TEXTURE_SIZE ); } void freeGameScreen(GameScreen * gameScreen) { UnloadRenderTexture(gameScreen->gyroscopeTexture); } void drawCrossHair(float size, float thick, Color color) { Vector3 center = (Vector3){GetScreenWidth() / 2.0, GetScreenHeight() / 2.0}; // Left to right. DrawLineEx( (Vector2){center.x - size, center.y}, (Vector2){center.x + size, center.y}, thick, color ); // Top to bottom. DrawLineEx( (Vector2){center.x, center.y - size}, (Vector2){center.x, center.y + size}, thick, color ); } void drawGyroscope(Game * game) { GameScreen * gameScreen = &game->gameScreen; Entity * player = getEntityFromWorld(game->world, 0); Vector2 gyroscopePosition = gameScreen->gyroscopePosition; // Get texture and model. Texture2D texture = game->assets.textures[GYROSCOPE_TEXTURE_ASSET]; Model model = game->assets.models[GYROSCOPE_ASSET]; // Draw this mother fucker. BeginTextureMode(gameScreen->gyroscopeTexture); ClearBackground(BLACK); BeginMode3D(gameScreen->gyroscopeCamaera); // Set transform and draw. model.transform = QuaternionToMatrix(player->rotation); DrawModel(model, Vector3Zero(), 1, WHITE); EndMode3D(); EndTextureMode(); // Draw render texture. DrawTexture( gameScreen->gyroscopeTexture.texture, gyroscopePosition.x, gyroscopePosition.y, WHITE ); // Top to bottom. DrawLine( gyroscopePosition.x + (GYROSCOPE_TEXTURE_SIZE / 2.0), gyroscopePosition.y, gyroscopePosition.x + (GYROSCOPE_TEXTURE_SIZE / 2.0), gyroscopePosition.y + GYROSCOPE_TEXTURE_SIZE, RED ); DrawLine( gyroscopePosition.x, gyroscopePosition.y + (GYROSCOPE_TEXTURE_SIZE / 2.0), gyroscopePosition.x + GYROSCOPE_TEXTURE_SIZE, gyroscopePosition.y + (GYROSCOPE_TEXTURE_SIZE / 2.0), RED ); } 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); // Camera. updatePlayerCamera(&game->playerCamera, game); // Draw. BeginMode3D(game->playerCamera); DrawGrid(50, 25.0); // Draw world. drawWorld(&game->world, game); EndMode3D(); } void openGameScreen(Game * game) { game->screenId = SCREEN_GAME; if (game->settings.lockMouse) DisableCursor(); } void closeGameScreen(Game * game) { if (game->settings.lockMouse) EnableCursor(); }