#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; // 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); // Skybox. game->skybox = LoadModelFromMesh(GenMeshCube(1.0, 1.0, 1.0)); game->skybox.materials[0].shader = game->assets.shaders[SKYBOX_SHADER]; game->skybox.materials[0].maps[MATERIAL_MAP_CUBEMAP].texture = LoadTextureCubemap(game->assets.images[SKYBOX_IMAGE], CUBEMAP_LAYOUT_AUTO_DETECT); // World. game->world = createWorld(345893, &game->assets); // Player. game->player = createPlayer(); game->player.position = Vector3Scale(game->world.size, 0.5); // DisableCursor(); } 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. rlDisableBackfaceCulling(); rlDisableDepthMask(); DrawModel(game->skybox, Vector3Zero(), 1.0, WHITE); rlEnableBackfaceCulling(); rlEnableDepthMask(); updatePlayer(&game->player, 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: updateMainMenuScene(game); break; case GAME_SCENE: updateGameScene(game); break; default: break; } DrawFPS(0, 0); EndDrawing(); } 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); CloseWindow(); }