diff options
Diffstat (limited to 'src/game.c')
| -rw-r--r-- | src/game.c | 68 |
1 files changed, 67 insertions, 1 deletions
@@ -1,6 +1,37 @@ #include "game.h" #include "utils.h" +void resetScreenScale(Game* game) +{ + Texture texture = game->screen.render.texture; + + // Get screen size on window. + float renderWidth = GetRenderWidth(); + float renderHeight = GetRenderHeight(); + float scale; + + if (renderWidth > renderHeight) + { + scale = (float)renderHeight / texture.height; + } + else + { + scale = (float)renderWidth / texture.width; + } + + game->screen.scale = scale; + + float width = texture.width * scale; + float height = texture.height * scale; + + game->screen.destination = (Rectangle){ + renderWidth / 2.0 - width / 2.0, + renderHeight / 2.0 - height / 2.0, + width, + height + }; +} + void initGame(Game* game) { game->sceneId = GAME_SCENE; @@ -8,11 +39,17 @@ void initGame(Game* game) // Settings. game->settings = defaultSettings(); + // Window. InitWindow(game->settings.windowWidth, game->settings.windowHeight, "Find Things"); SetWindowState(FLAG_WINDOW_RESIZABLE); + // Screen. + game->screen.render = LoadRenderTexture(game->settings.screenWidth, + game->settings.screenHeight); + resetScreenScale(game); + // Assets. initAssets(&game->assets); @@ -30,7 +67,7 @@ void initGame(Game* game) game->player = createPlayer(); game->player.position = Vector3Scale(game->world.size, 0.5); - DisableCursor(); + // DisableCursor(); } void updateMainMenuScene(Game* game) @@ -38,10 +75,25 @@ void updateMainMenuScene(Game* game) ClearBackground(BLACK); } +void drawGameScreen(Game* game) +{ + Texture texture = game->screen.render.texture; + + DrawTexturePro( + texture, + (Rectangle){0.0, 0.0, texture.width, -texture.height}, + game->screen.destination, + (Vector2){0.0, 0.0}, + 0.0, + WHITE); +} + void updateGameScene(Game* game) { ClearBackground(BLACK); + BeginTextureMode(game->screen.render); + ClearBackground(BLACK); BeginMode3D(game->player.camera); // Render skybox. @@ -56,12 +108,25 @@ void updateGameScene(Game* game) updateWorld(&game->world, game); EndMode3D(); + EndTextureMode(); + + drawGameScreen(game); +} + +void handleGameResize(Game* game) +{ + resetScreenScale(game); } void updateGame(Game* game) { BeginDrawing(); + if (IsWindowResized()) + { + handleGameResize(game); + } + switch (game->sceneId) { case MAIN_MENU_SCENE: @@ -82,6 +147,7 @@ void updateGame(Game* game) void closeGame(Game* game) { closeAssets(&game->assets); + UnloadRenderTexture(game->screen.render); UnloadTexture(game->skybox.materials[0].maps[MATERIAL_MAP_CUBEMAP].texture); UnloadModel(game->skybox); freeWorld(game->world); |
