summaryrefslogtreecommitdiff
path: root/main.c
diff options
context:
space:
mode:
Diffstat (limited to 'main.c')
-rw-r--r--main.c60
1 files changed, 31 insertions, 29 deletions
diff --git a/main.c b/main.c
index 045c512..25f5ece 100644
--- a/main.c
+++ b/main.c
@@ -9,6 +9,8 @@
#include "include/pathfinding.h"
#include "include/list.h"
#include "include/allocator.h"
+#include "include/game.h"
+#include "include/protocol.h"
#include "src/map.c"
#include "src/players.c"
@@ -19,50 +21,52 @@
#include "src/pathfinding.c"
#include "src/list.c"
#include "src/allocator.c"
+#include "src/game.c"
+#include "src/protocol.c"
#define CONFIG_DIRECTORY "zombieshooter"
font* fnt;
void update_func(platform_window* window) {
renderer->render_clear(window, rgb(0,255,0));
-
- draw_grid(window);
- draw_spawners(window);
-
- char buf[200];
- sprintf(buf, "QUEUE: %d", global_pathfinding_queue.length);
- renderer->render_text(fnt, _global_camera.x, _global_camera.y, buf, rgb(255,255,255));
+ update_game(window);
}
-void resize_func(platform_window* window, u32 change_x,u32 change_y) {
-
-}
-void close_func(platform_window* window) {
-
+void handle_args(int argc, char **argv) {
+ char* ip = 0;
+ char* port = 0;
+ for (int i = 1; i < argc; i++) {
+ char* prev_str = argv[i-1];
+ char* str = argv[i];
+ if (strcmp(prev_str, "-ip") == 0) {
+ ip = str;
+ }
+ if (strcmp(prev_str, "-port") == 0) {
+ port = str;
+ }
+ }
+
+ if (ip && port) {
+ if (strcmp(ip, "127.0.0.1") == 0) {
+ start_server(port);
+ }
+ connect_to_server(ip, port);
+ }
}
int main(int argc, char **argv)
{
platform_init(argc, argv, CONFIG_DIRECTORY);
- platform_window *window = platform_open_window_ex("Zombies!", 700, 700, 1200, 1000, 500, 500, FLAGS_MINIMIZE, update_func, resize_func, close_func, 0, 0);
+ platform_window *window = platform_open_window_ex("Zombies!", 700, 700, 1200, 1000, 500, 500, FLAGS_MINIMIZE, update_func, 0, 0, 0, 0);
settings_set_number("USE_GPU", 1);
platform_toggle_vsync(window, true);
-
- fnt = assets_load_font(mono_ttf, mono_ttf+mono_ttf_len, 16);
- load_map_from_data();
- create_objects();
- pathfinding_init();
+ init_game();
+ handle_args(argc, argv);
- network_server *server = networking_create_server();
-
- thread t = thread_start(pathfinding_thread, 0);
- thread_detach(&t);
-
- network_client *client = network_connect_to_server("127.0.0.1", "27015");
- network_client_send(client, "Bing Bong");
+ fnt = assets_load_font(mono_ttf, mono_ttf+mono_ttf_len, 16);
while(platform_keep_running(window)) {
platform_handle_events();
@@ -71,10 +75,8 @@ int main(int argc, char **argv)
settings_write_to_file();
platform_destroy();
pathfinding_destroy();
-
- network_client_close(client);
- networking_destroy_server(server);
-
+ destroy_game();
+
memory_print_leaks();
return 0;