From 6307feb53d978cbf7f50df26a7b0bc63252cfbd4 Mon Sep 17 00:00:00 2001 From: Mitja Felicijan Date: Thu, 30 Apr 2026 19:02:35 +0200 Subject: Title screen and direct map load with --map param --- game.c | 80 +++++++++++++++++++++++++++++++++++++++++++++++++----------------- 1 file changed, 60 insertions(+), 20 deletions(-) (limited to 'game.c') diff --git a/game.c b/game.c index 87fea13..19a1875 100644 --- a/game.c +++ b/game.c @@ -223,7 +223,7 @@ bool LoadMap(const char *filename) { return true; } -void InitGame(const char* map_path) { +void InitGame(void) { array_init(texture_cache); game.world_models = NULL; game.world_model_count = 0; @@ -238,7 +238,7 @@ void InitGame(const char* map_path) { game.font_ui = GetFontDefault(); } - LoadMap(map_path); + game.mode = STATE_TITLE; game.cursor_captured = false; EnableCursor(); @@ -248,7 +248,21 @@ void InitGame(const char* map_path) { game.is_grounded = false; } +void SetMap(const char *path) { + strncpy(game.map_path, path, sizeof(game.map_path) - 1); + game.map_path[sizeof(game.map_path) - 1] = '\0'; +} + void UpdateGame(void) { + if (game.mode == STATE_TITLE) { + if (IsKeyPressed(KEY_ENTER)) { + if (LoadMap(game.map_path)) { + game.mode = STATE_PLAYING; + } + } + return; + } + if (IsMouseButtonPressed(MOUSE_BUTTON_RIGHT)) { game.cursor_captured = !game.cursor_captured; if (game.cursor_captured) DisableCursor(); @@ -257,6 +271,7 @@ void UpdateGame(void) { if (IsKeyPressed(KEY_ONE)) LoadMap("maps/demo1.map"); if (IsKeyPressed(KEY_TWO)) LoadMap("maps/demo2.map"); + if (IsKeyPressed(KEY_THREE)) LoadMap("maps/demo3.map"); if (IsKeyPressed(KEY_V)) { game.vsync = !game.vsync; @@ -274,25 +289,50 @@ void UpdateGame(void) { void DrawGame(void) { BeginDrawing(); - ClearBackground(DARKGRAY); - BeginMode3D(game.camera); - - // Enable backface culling to hide interior faces of brushes - rlEnableBackfaceCulling(); - for (int i = 0; i < game.world_model_count; i++) { - DrawModel(game.world_models[i], (Vector3){ 0, 0, 0 }, 1.0f, WHITE); + ClearBackground(BLACK); + + if (game.mode == STATE_TITLE) { + int screenWidth = GetScreenWidth(); + int screenHeight = GetScreenHeight(); + + const char *title = "STALAG"; + const char *sub = "Press ENTER to Start"; + + int titleSize = 60; + int subSize = 20; + + Vector2 titlePos = { + (float)(screenWidth - MeasureTextEx(game.font_ui, title, (float)titleSize, 4).x) / 2, + (float)screenHeight / 2 - 40 + }; + Vector2 subPos = { + (float)(screenWidth - MeasureTextEx(game.font_ui, sub, (float)subSize, 2).x) / 2, + (float)screenHeight / 2 + 40 + }; + + DrawTextEx(game.font_ui, title, titlePos, (float)titleSize, 4, WHITE); + DrawTextEx(game.font_ui, sub, subPos, (float)subSize, 2, GRAY); + } else { + ClearBackground(DARKGRAY); + BeginMode3D(game.camera); + + // Enable backface culling to hide interior faces of brushes + rlEnableBackfaceCulling(); + for (int i = 0; i < game.world_model_count; i++) { + DrawModel(game.world_models[i], (Vector3){ 0, 0, 0 }, 1.0f, WHITE); + } + + EndMode3D(); + + int screenWidth = GetScreenWidth(); + int screenHeight = GetScreenHeight(); + DrawLine(screenWidth / 2 - 10, screenHeight / 2, screenWidth / 2 + 10, screenHeight / 2, GREEN); + DrawLine(screenWidth / 2, screenHeight / 2 - 10, screenWidth / 2, screenHeight / 2 + 10, GREEN); + + DrawTextEx(game.font_ui, TextFormat("%i FPS", GetFPS()), (Vector2){ 10, 10 }, 20, 2, GREEN); + DrawTextEx(game.font_ui, TextFormat("VSync: %s", game.vsync ? "ON" : "OFF"), (Vector2){ 10, 35 }, 20, 2, GREEN); + DrawTextEx(game.font_ui, TextFormat("Speed: %.0f", game.horizontal_speed), (Vector2){ 10, 60 }, 20, 2, GREEN); } - - EndMode3D(); - - int screenWidth = GetScreenWidth(); - int screenHeight = GetScreenHeight(); - DrawLine(screenWidth / 2 - 10, screenHeight / 2, screenWidth / 2 + 10, screenHeight / 2, GREEN); - DrawLine(screenWidth / 2, screenHeight / 2 - 10, screenWidth / 2, screenHeight / 2 + 10, GREEN); - - DrawTextEx(game.font_ui, TextFormat("%i FPS", GetFPS()), (Vector2){ 10, 10 }, 20, 2, GREEN); - DrawTextEx(game.font_ui, TextFormat("VSync: %s", game.vsync ? "ON" : "OFF"), (Vector2){ 10, 35 }, 20, 2, GREEN); - DrawTextEx(game.font_ui, TextFormat("Speed: %.0f", game.horizontal_speed), (Vector2){ 10, 60 }, 20, 2, GREEN); EndDrawing(); } -- cgit v1.2.3