1#define NONSTD_IMPLEMENTATION
2#define VFS_IMPLEMENTATION
3#include "all.h"
4
5#include <getopt.h>
6
7int main(int argc, char *argv[]) {
8 stringb map_path;
9 sb_init(&map_path, 256);
10 sb_append_cstr(&map_path, "maps/demo4.map");
11
12 bool skip_title = false;
13 int target_fps = -1;
14 int width = WINDOW_WIDTH;
15 int height = WINDOW_HEIGHT;
16
17 static struct option long_options[] = {
18 {"map", required_argument, 0, 'm'},
19 {"fps", required_argument, 0, 'f'},
20 {"width", required_argument, 0, 'w'},
21 {"height", required_argument, 0, 'h'},
22 {0, 0, 0, 0}
23 };
24
25 int opt;
26 int option_index = 0;
27 while ((opt = getopt_long_only(argc, argv, "m:f:w:h:", long_options, &option_index)) != -1) {
28 switch (opt) {
29 case 'm':
30 sb_free(&map_path);
31 sb_init(&map_path, 256);
32 sb_append_cstr(&map_path, optarg);
33 skip_title = true;
34 break;
35 case 'f':
36 target_fps = atoi(optarg);
37 break;
38 case 'w':
39 width = atoi(optarg);
40 break;
41 case 'h':
42 height = atoi(optarg);
43 break;
44 }
45 }
46
47 unsigned int flags = FLAG_WINDOW_RESIZABLE | FLAG_WINDOW_HIGHDPI;
48 if (target_fps < 0) flags |= FLAG_VSYNC_HINT;
49
50 SetConfigFlags(flags);
51 InitWindow(width, height, WINDOW_TITLE);
52
53 int monitor = GetCurrentMonitor();
54 SetWindowPosition((GetMonitorWidth(monitor) - GetScreenWidth()) / 2, (GetMonitorHeight(monitor) - GetScreenHeight()) / 2);
55
56 vfs_init(VFS_DATA_PAK);
57 init_game();
58 game.screen_width = width;
59 game.screen_height = height;
60 set_map(map_path.data);
61
62 if (target_fps >= 0) {
63 game.target_fps = target_fps;
64 game.vsync = false;
65 SetTargetFPS(game.target_fps);
66 } else {
67 game.vsync = true;
68 SetTargetFPS(GetMonitorRefreshRate(monitor));
69 }
70
71 if (skip_title) {
72 if (load_map(game.map_path)) {
73 game.mode = STATE_PLAYING;
74 game.cursor_captured = true;
75 DisableCursor();
76 }
77 }
78
79 game.vsync = true;
80
81 while (!WindowShouldClose()) {
82 // Global Map Switching (Debug/Demo)
83 if (IsKeyPressed(KEY_ONE)) {
84 if (load_map("maps/demo1.map")) {
85 game.mode = STATE_PLAYING;
86 game.cursor_captured = true;
87 DisableCursor();
88 }
89 }
90 if (IsKeyPressed(KEY_TWO)) {
91 if (load_map("maps/demo2.map")) {
92 game.mode = STATE_PLAYING;
93 game.cursor_captured = true;
94 DisableCursor();
95 }
96 }
97 if (IsKeyPressed(KEY_THREE)) {
98 if (load_map("maps/demo3.map")) {
99 game.mode = STATE_PLAYING;
100 game.cursor_captured = true;
101 DisableCursor();
102 }
103 }
104 if (IsKeyPressed(KEY_FOUR)) {
105 if (load_map("maps/demo4.map")) {
106 game.mode = STATE_PLAYING;
107 game.cursor_captured = true;
108 DisableCursor();
109 }
110 }
111
112 // Game State Switcher
113 switch (game.mode) {
114 case STATE_MENU:
115 update_menu();
116 draw_menu();
117 break;
118 case STATE_PLAYING:
119 update_game();
120 draw_game();
121 break;
122 }
123 }
124
125 unload_map();
126 unload_assets();
127 vfs_shutdown();
128 CloseWindow();
129 sb_free(&map_path);
130
131 return 0;
132}