aboutsummaryrefslogtreecommitdiff
path: root/main.c
diff options
context:
space:
mode:
Diffstat (limited to 'main.c')
-rw-r--r--main.c106
1 files changed, 87 insertions, 19 deletions
diff --git a/main.c b/main.c
index 481f5f3..9f32ecc 100644
--- a/main.c
+++ b/main.c
@@ -1,29 +1,97 @@
1#define _POSIX_C_SOURCE 200809L
2#define NONSTD_IMPLEMENTATION 1#define NONSTD_IMPLEMENTATION
3#define VFS_IMPLEMENTATION 2#define VFS_IMPLEMENTATION
4#include "all.h" 3#include "all.h"
5 4
6int main(void) { 5#include <getopt.h>
7 SetConfigFlags(FLAG_VSYNC_HINT | FLAG_WINDOW_RESIZABLE | FLAG_WINDOW_HIGHDPI);
8 InitWindow(WINDOW_WIDTH, WINDOW_HEIGHT, WINDOW_TITLE);
9 6
10 int monitor = GetCurrentMonitor(); 7int main(int argc, char *argv[]) {
11 SetWindowPosition((GetMonitorWidth(monitor) - GetScreenWidth()) / 2, 8 stringb map_path;
12 (GetMonitorHeight(monitor) - GetScreenHeight()) / 2); 9 sb_init(&map_path, 256);
13 10 sb_append_cstr(&map_path, "maps/demo3.map");
14 SetTargetFPS(GetMonitorRefreshRate(monitor));
15 11
16 vfs_init("data.pak"); 12 bool skip_title = false;
17 InitGame();
18 game.vsync = true;
19 13
20 while (!WindowShouldClose()) { 14 static struct option long_options[] = {
21 UpdateGame(); 15 {"map", required_argument, 0, 'm'},
22 DrawGame(); 16 {0, 0, 0, 0}
23 } 17 };
24 18
25 vfs_shutdown(); 19 int opt;
26 CloseWindow(); 20 int option_index = 0;
21 while ((opt = getopt_long_only(argc, argv, "m:", long_options, &option_index)) != -1) {
22 switch (opt) {
23 case 'm':
24 sb_free(&map_path);
25 sb_init(&map_path, 256);
26 sb_append_cstr(&map_path, optarg);
27 skip_title = true;
28 break;
29 }
30 }
27 31
28 return 0; 32 SetConfigFlags(FLAG_VSYNC_HINT | FLAG_WINDOW_RESIZABLE | FLAG_WINDOW_HIGHDPI);
33 InitWindow(WINDOW_WIDTH, WINDOW_HEIGHT, WINDOW_TITLE);
34
35 int monitor = GetCurrentMonitor();
36 SetWindowPosition((GetMonitorWidth(monitor) - GetScreenWidth()) / 2, (GetMonitorHeight(monitor) - GetScreenHeight()) / 2);
37 SetTargetFPS(GetMonitorRefreshRate(monitor));
38
39 vfs_init(VFS_DATA_PAK);
40 InitGame();
41 SetMap(map_path.data);
42
43 if (skip_title) {
44 if (LoadMap(game.map_path)) {
45 game.mode = STATE_PLAYING;
46 game.cursor_captured = true;
47 DisableCursor();
48 }
49 }
50
51 game.vsync = true;
52
53 while (!WindowShouldClose()) {
54 // Global Map Switching (Debug/Demo)
55 if (IsKeyPressed(KEY_ONE)) {
56 if (LoadMap("maps/demo1.map")) {
57 game.mode = STATE_PLAYING;
58 game.cursor_captured = true;
59 DisableCursor();
60 }
61 }
62 if (IsKeyPressed(KEY_TWO)) {
63 if (LoadMap("maps/demo2.map")) {
64 game.mode = STATE_PLAYING;
65 game.cursor_captured = true;
66 DisableCursor();
67 }
68 }
69 if (IsKeyPressed(KEY_THREE)) {
70 if (LoadMap("maps/demo3.map")) {
71 game.mode = STATE_PLAYING;
72 game.cursor_captured = true;
73 DisableCursor();
74 }
75 }
76
77 // Game State Switcher
78 switch (game.mode) {
79 case STATE_MENU:
80 UpdateMenu();
81 DrawMenu();
82 break;
83 case STATE_PLAYING:
84 UpdateGame();
85 DrawGame();
86 break;
87 }
88 }
89
90 UnloadMap();
91 UnloadAssets();
92 vfs_shutdown();
93 CloseWindow();
94 sb_free(&map_path);
95
96 return 0;
29} 97}