diff options
Diffstat (limited to 'game.c')
| -rw-r--r-- | game.c | 80 |
1 files changed, 60 insertions, 20 deletions
| @@ -223,7 +223,7 @@ bool LoadMap(const char *filename) { | |||
| 223 | return true; | 223 | return true; |
| 224 | } | 224 | } |
| 225 | 225 | ||
| 226 | void InitGame(const char* map_path) { | 226 | void InitGame(void) { |
| 227 | array_init(texture_cache); | 227 | array_init(texture_cache); |
| 228 | game.world_models = NULL; | 228 | game.world_models = NULL; |
| 229 | game.world_model_count = 0; | 229 | game.world_model_count = 0; |
| @@ -238,7 +238,7 @@ void InitGame(const char* map_path) { | |||
| 238 | game.font_ui = GetFontDefault(); | 238 | game.font_ui = GetFontDefault(); |
| 239 | } | 239 | } |
| 240 | 240 | ||
| 241 | LoadMap(map_path); | 241 | game.mode = STATE_TITLE; |
| 242 | 242 | ||
| 243 | game.cursor_captured = false; | 243 | game.cursor_captured = false; |
| 244 | EnableCursor(); | 244 | EnableCursor(); |
| @@ -248,7 +248,21 @@ void InitGame(const char* map_path) { | |||
| 248 | game.is_grounded = false; | 248 | game.is_grounded = false; |
| 249 | } | 249 | } |
| 250 | 250 | ||
| 251 | void SetMap(const char *path) { | ||
| 252 | strncpy(game.map_path, path, sizeof(game.map_path) - 1); | ||
| 253 | game.map_path[sizeof(game.map_path) - 1] = '\0'; | ||
| 254 | } | ||
| 255 | |||
| 251 | void UpdateGame(void) { | 256 | void UpdateGame(void) { |
| 257 | if (game.mode == STATE_TITLE) { | ||
| 258 | if (IsKeyPressed(KEY_ENTER)) { | ||
| 259 | if (LoadMap(game.map_path)) { | ||
| 260 | game.mode = STATE_PLAYING; | ||
| 261 | } | ||
| 262 | } | ||
| 263 | return; | ||
| 264 | } | ||
| 265 | |||
| 252 | if (IsMouseButtonPressed(MOUSE_BUTTON_RIGHT)) { | 266 | if (IsMouseButtonPressed(MOUSE_BUTTON_RIGHT)) { |
| 253 | game.cursor_captured = !game.cursor_captured; | 267 | game.cursor_captured = !game.cursor_captured; |
| 254 | if (game.cursor_captured) DisableCursor(); | 268 | if (game.cursor_captured) DisableCursor(); |
| @@ -257,6 +271,7 @@ void UpdateGame(void) { | |||
| 257 | 271 | ||
| 258 | if (IsKeyPressed(KEY_ONE)) LoadMap("maps/demo1.map"); | 272 | if (IsKeyPressed(KEY_ONE)) LoadMap("maps/demo1.map"); |
| 259 | if (IsKeyPressed(KEY_TWO)) LoadMap("maps/demo2.map"); | 273 | if (IsKeyPressed(KEY_TWO)) LoadMap("maps/demo2.map"); |
| 274 | if (IsKeyPressed(KEY_THREE)) LoadMap("maps/demo3.map"); | ||
| 260 | 275 | ||
| 261 | if (IsKeyPressed(KEY_V)) { | 276 | if (IsKeyPressed(KEY_V)) { |
| 262 | game.vsync = !game.vsync; | 277 | game.vsync = !game.vsync; |
| @@ -274,25 +289,50 @@ void UpdateGame(void) { | |||
| 274 | 289 | ||
| 275 | void DrawGame(void) { | 290 | void DrawGame(void) { |
| 276 | BeginDrawing(); | 291 | BeginDrawing(); |
| 277 | ClearBackground(DARKGRAY); | 292 | ClearBackground(BLACK); |
| 278 | BeginMode3D(game.camera); | 293 | |
| 279 | 294 | if (game.mode == STATE_TITLE) { | |
| 280 | // Enable backface culling to hide interior faces of brushes | 295 | int screenWidth = GetScreenWidth(); |
| 281 | rlEnableBackfaceCulling(); | 296 | int screenHeight = GetScreenHeight(); |
| 282 | for (int i = 0; i < game.world_model_count; i++) { | 297 | |
| 283 | DrawModel(game.world_models[i], (Vector3){ 0, 0, 0 }, 1.0f, WHITE); | 298 | const char *title = "STALAG"; |
| 299 | const char *sub = "Press ENTER to Start"; | ||
| 300 | |||
| 301 | int titleSize = 60; | ||
| 302 | int subSize = 20; | ||
| 303 | |||
| 304 | Vector2 titlePos = { | ||
| 305 | (float)(screenWidth - MeasureTextEx(game.font_ui, title, (float)titleSize, 4).x) / 2, | ||
| 306 | (float)screenHeight / 2 - 40 | ||
| 307 | }; | ||
| 308 | Vector2 subPos = { | ||
| 309 | (float)(screenWidth - MeasureTextEx(game.font_ui, sub, (float)subSize, 2).x) / 2, | ||
| 310 | (float)screenHeight / 2 + 40 | ||
| 311 | }; | ||
| 312 | |||
| 313 | DrawTextEx(game.font_ui, title, titlePos, (float)titleSize, 4, WHITE); | ||
| 314 | DrawTextEx(game.font_ui, sub, subPos, (float)subSize, 2, GRAY); | ||
| 315 | } else { | ||
| 316 | ClearBackground(DARKGRAY); | ||
| 317 | BeginMode3D(game.camera); | ||
| 318 | |||
| 319 | // Enable backface culling to hide interior faces of brushes | ||
| 320 | rlEnableBackfaceCulling(); | ||
| 321 | for (int i = 0; i < game.world_model_count; i++) { | ||
| 322 | DrawModel(game.world_models[i], (Vector3){ 0, 0, 0 }, 1.0f, WHITE); | ||
| 323 | } | ||
| 324 | |||
| 325 | EndMode3D(); | ||
| 326 | |||
| 327 | int screenWidth = GetScreenWidth(); | ||
| 328 | int screenHeight = GetScreenHeight(); | ||
| 329 | DrawLine(screenWidth / 2 - 10, screenHeight / 2, screenWidth / 2 + 10, screenHeight / 2, GREEN); | ||
| 330 | DrawLine(screenWidth / 2, screenHeight / 2 - 10, screenWidth / 2, screenHeight / 2 + 10, GREEN); | ||
| 331 | |||
| 332 | DrawTextEx(game.font_ui, TextFormat("%i FPS", GetFPS()), (Vector2){ 10, 10 }, 20, 2, GREEN); | ||
| 333 | DrawTextEx(game.font_ui, TextFormat("VSync: %s", game.vsync ? "ON" : "OFF"), (Vector2){ 10, 35 }, 20, 2, GREEN); | ||
| 334 | DrawTextEx(game.font_ui, TextFormat("Speed: %.0f", game.horizontal_speed), (Vector2){ 10, 60 }, 20, 2, GREEN); | ||
| 284 | } | 335 | } |
| 285 | |||
| 286 | EndMode3D(); | ||
| 287 | |||
| 288 | int screenWidth = GetScreenWidth(); | ||
| 289 | int screenHeight = GetScreenHeight(); | ||
| 290 | DrawLine(screenWidth / 2 - 10, screenHeight / 2, screenWidth / 2 + 10, screenHeight / 2, GREEN); | ||
| 291 | DrawLine(screenWidth / 2, screenHeight / 2 - 10, screenWidth / 2, screenHeight / 2 + 10, GREEN); | ||
| 292 | |||
| 293 | DrawTextEx(game.font_ui, TextFormat("%i FPS", GetFPS()), (Vector2){ 10, 10 }, 20, 2, GREEN); | ||
| 294 | DrawTextEx(game.font_ui, TextFormat("VSync: %s", game.vsync ? "ON" : "OFF"), (Vector2){ 10, 35 }, 20, 2, GREEN); | ||
| 295 | DrawTextEx(game.font_ui, TextFormat("Speed: %.0f", game.horizontal_speed), (Vector2){ 10, 60 }, 20, 2, GREEN); | ||
| 296 | 336 | ||
| 297 | EndDrawing(); | 337 | EndDrawing(); |
| 298 | } | 338 | } |
