diff options
| author | nathan <nathansmith@disroot.org> | 2026-01-31 10:25:27 +0000 |
|---|---|---|
| committer | nathan <nathansmith@disroot.org> | 2026-01-31 10:25:27 +0000 |
| commit | 966afc26c23fdda3ce279559f154899cb0e08b31 (patch) | |
| tree | 967e31feb371de03f69358f35fc2734fe5a1b715 | |
| parent | 0b35df87370fc8e4612a2c80fe4b7fb64e72f927 (diff) | |
| download | FindThings-966afc26c23fdda3ce279559f154899cb0e08b31.tar.gz FindThings-966afc26c23fdda3ce279559f154899cb0e08b31.tar.bz2 FindThings-966afc26c23fdda3ce279559f154899cb0e08b31.zip | |
General weirdness
| -rw-r--r-- | src/game.c | 125 | ||||
| -rw-r--r-- | src/game.h | 6 |
2 files changed, 102 insertions, 29 deletions
@@ -45,6 +45,22 @@ void resetScreenScale(Game* game) } } +void initMainMenu(Game* game) +{ + game->mainMenu.renderTexture = LoadRenderTexture(GetRenderWidth(), + GetRenderHeight()); + + game->mainMenu.camera = (Camera){ + .position = Vector3Zero(), + .target = (Vector3){0.0, 0.0, 1.0}, + .up = (Vector3){0.0, 1.0, 0.0}, + .fovy = 90.0, + .projection = CAMERA_PERSPECTIVE + }; + + game->mainMenu.sphere = LoadModelFromMesh(GenMeshSphere(1.0, 7, 14)); +} + void initGame(Game* game) { game->sceneId = MAIN_MENU_SCENE; @@ -100,18 +116,77 @@ void initGame(Game* game) // Inventory. initInventory(&game->inventory, &game->settings); + // Main menu. + initMainMenu(game); + // disableGameCursor(game); } +void mainMenuHandleWidgets(Game* game, Vector2 position) +{ + float buttonWidth = 150.0; + float buttonHeight = 50.0; + + // Start button. + position.x = GetRenderWidth() / 2.0 - buttonWidth / 2.0; + position.y = GetRenderHeight() / 2.0; + + if (GuiButton( + (Rectangle){position.x, + position.y, + buttonWidth, + buttonHeight}, + "Start")) + { + game->sceneId = GAME_SCENE; + disableGameCursor(game); + } + + // Exit button. + position.y += buttonHeight + 1.0; + + if (GuiButton( + (Rectangle){position.x, + position.y, + buttonWidth, + buttonHeight}, + "Exit")) + { + CloseWindow(); + } +} + +void updateMainMenuBouncy(Game* game) +{ + BeginMode3D(game->mainMenu.camera); + + game->mainMenu.sphere.materials[0].maps[MATERIAL_MAP_DIFFUSE].texture = + game->mainMenu.renderTexture.texture; + DrawModel(game->mainMenu.sphere, + (Vector3){Wrap(GetTime(), -10.0, 10.0), 0.0, 5.0}, + 1.0, + WHITE); + + EndMode3D(); +} + +// TODO: Use render texture instead of screenshot. void updateMainMenuScene(Game* game) { - ClearBackground(PINK); + Texture texture = game->mainMenu.renderTexture.texture; + + BeginTextureMode(game->mainMenu.renderTexture); + + DrawTexturePro(texture, + (Rectangle){0.0, 0.0, texture.width, -texture.height}, + (Rectangle){0.0, 0.0, texture.width, texture.height}, + (Vector2){0.0, 0.0}, + 0.0, + WHITE); + float renderWidth = GetRenderWidth(); float renderHeight = GetRenderHeight(); - float buttonWidth = 150.0; - float buttonHeight = 50.0; - int lineCount = 15; SetRandomSeed(GetTime() * 2.0); @@ -130,7 +205,7 @@ void updateMainMenuScene(Game* game) (Vector2){GetRandomValue(0, renderWidth), GetRandomValue(0, renderHeight)}, 2.0, - BLACK); + GREEN); } // Draw logo. @@ -153,33 +228,18 @@ void updateMainMenuScene(Game* game) logoScale, WHITE); - // Start button. - position.x = renderWidth / 2.0 - buttonWidth / 2.0; - position.y = renderHeight / 2.0; + mainMenuHandleWidgets(game, position); - if (GuiButton( - (Rectangle){position.x, - position.y, - buttonWidth, - buttonHeight}, - "Start")) - { - game->sceneId = GAME_SCENE; - disableGameCursor(game); - } + updateMainMenuBouncy(game); - // Exit button. - position.y += buttonHeight + 1.0; + EndTextureMode(); - if (GuiButton( - (Rectangle){position.x, - position.y, - buttonWidth, - buttonHeight}, - "Exit")) - { - CloseWindow(); - } + DrawTexturePro(texture, + (Rectangle){0.0, 0.0, texture.width, -texture.height}, + (Rectangle){0.0, 0.0, texture.width, texture.height}, + (Vector2){0.0, 0.0}, + 0.0, + WHITE); } void drawGameTexturedBackground(Texture texture) @@ -446,6 +506,12 @@ void updateGame(Game* game) EndDrawing(); } +void closeMainMenu(Game* game) +{ + UnloadRenderTexture(game->mainMenu.renderTexture); + UnloadModel(game->mainMenu.sphere); +} + void closeGame(Game* game) { closeAssets(&game->assets); @@ -454,6 +520,7 @@ void closeGame(Game* game) UnloadModel(game->skybox); freeWorld(game->world); closeMap(&game->map); + closeMainMenu(game); CloseWindow(); } @@ -44,6 +44,12 @@ struct Game { AssetId postprocesserShader; bool ultraWideMode; } screen; + + struct { + RenderTexture renderTexture; + Camera camera; + Model sphere; + } mainMenu; }; void initGame(Game* game); |
