diff options
| -rw-r--r-- | Makefile | 2 | ||||
| -rw-r--r-- | build/SDL2.dll | bin | 0 -> 1561088 bytes | |||
| -rw-r--r-- | build/SDL2_mixer.dll | bin | 0 -> 123904 bytes | |||
| -rw-r--r-- | build/zombies.exe | bin | 1734476 -> 1738175 bytes | |||
| -rw-r--r-- | include/objects.h | 1 | ||||
| -rw-r--r-- | libs/SDL2.dll | bin | 0 -> 1561088 bytes | |||
| -rw-r--r-- | libs/SDL2_mixer.dll | bin | 0 -> 123904 bytes | |||
| -rw-r--r-- | src/game.c | 5 | ||||
| -rw-r--r-- | src/objects.c | 6 | ||||
| -rw-r--r-- | src/zombies.c | 31 |
10 files changed, 33 insertions, 12 deletions
@@ -2,6 +2,8 @@ main: rm -rf "build/" mkdir -p "build/" cp -a "data/." "build/data" + cp -a "libs/SDL2_mixer.dll" "build/" + cp -a "libs/SDL2.dll" "build/" gcc -m64 -g -DMODE_DEBUG main.c -o build/zombies.exe -lprojectbase-debug -Llibs/ -lSDL2 -lSDL2_mixer -lWs2_32 ./build/zombies.exe -ip 127.0.0.1 -port 27015 diff --git a/build/SDL2.dll b/build/SDL2.dll Binary files differnew file mode 100644 index 0000000..ddba03c --- /dev/null +++ b/build/SDL2.dll diff --git a/build/SDL2_mixer.dll b/build/SDL2_mixer.dll Binary files differnew file mode 100644 index 0000000..40bb1c1 --- /dev/null +++ b/build/SDL2_mixer.dll diff --git a/build/zombies.exe b/build/zombies.exe Binary files differindex e786e24..1922106 100644 --- a/build/zombies.exe +++ b/build/zombies.exe diff --git a/include/objects.h b/include/objects.h index 46d03ff..d819f82 100644 --- a/include/objects.h +++ b/include/objects.h @@ -31,6 +31,7 @@ typedef struct t_box { int max_objects = 150; object objects[150]; +object get_object_at_tile(float x, float y); void create_objects(); void draw_objects_at_row(platform_window* window, int row); box get_box_of_object(platform_window* window, object o); diff --git a/libs/SDL2.dll b/libs/SDL2.dll Binary files differnew file mode 100644 index 0000000..ddba03c --- /dev/null +++ b/libs/SDL2.dll diff --git a/libs/SDL2_mixer.dll b/libs/SDL2_mixer.dll Binary files differnew file mode 100644 index 0000000..40bb1c1 --- /dev/null +++ b/libs/SDL2_mixer.dll @@ -18,7 +18,7 @@ void start_server(char* port) { } static u32 get_session_id() { - u32 time = platform_get_time(TIME_NS, TIME_FULL); + u64 time = platform_get_time(TIME_NS, TIME_FULL); return (((time * 2654435789U) + time) * 2654435789U) + platform_get_processid(); } @@ -249,10 +249,9 @@ void update_game(platform_window* window) { update_client(window); } - if (global_state.network_state == CONNECTED) { if (!global_state.server) { - update_zombies_client(window); + update_zombies_client(window); // move to update_client? } take_player_input(window); diff --git a/src/objects.c b/src/objects.c index 350529d..23a57c6 100644 --- a/src/objects.c +++ b/src/objects.c @@ -18,11 +18,11 @@ void render_quad_with_outline(vec2f tl, vec2f tr, vec2f bl, vec2f br, color c) { renderer->render_line(bl.x, bl.y, br.x, br.y, 1, rgb(0,0,255)); // bottom } -object get_object_at_tile(int x, int y) { +object get_object_at_tile(float x, float y) { for (int i = 0; i < max_objects; i++) { object o = objects[i]; - if (!o.active) continue; - if (o.position.x == x && o.position.y == y) return o; + if (!o.active) continue; + if (x >= o.position.x && x < o.position.x + o.size.x && y >= o.position.y && y < o.position.y + o.size.y) return o; } return (object){0}; } diff --git a/src/zombies.c b/src/zombies.c index 76c5267..8289ad4 100644 --- a/src/zombies.c +++ b/src/zombies.c @@ -40,7 +40,7 @@ void spawn_zombie(int x, int y) { player closest_player = get_closest_player_to_tile(x, y); - make_pathfinding_request((vec2f){x,y}, (vec2f){closest_player.playerx, closest_player.playery}, &zombies[i].path, &zombies[i].request); + make_pathfinding_request((vec2f){x,y}, (vec2f){closest_player.playerx, closest_player.playery}, &zombies[i].next_path, &zombies[i].request); break; } } @@ -157,6 +157,21 @@ void update_zombies_client(platform_window* window) { } } +static vec2f get_random_point_around_player(player p, zombie o) { + // Convert from degrees to radians via multiplication by PI/180 + + try_again:; + float radius = 0.8f, angleInDegrees = (rand() % 360); + vec2f origin = (vec2f){o.position.x, o.position.y}; + float x = (float)(radius * cos(angleInDegrees * M_PI / 180.0f)) + p.playerx; + float y = (float)(radius * sin(angleInDegrees * M_PI / 180.0f)) + p.playery; + + object obj = get_object_at_tile(x, y); + if (obj.active) goto try_again; + + return (vec2f){x, y}; +} + void update_zombies_server(platform_window* window) { float speed = 0.05f; @@ -167,9 +182,9 @@ void update_zombies_server(platform_window* window) { zombies[i].time_since_last_path += update_delta; if (zombies[i].time_since_last_path > 0.05f) { player closest_player = get_closest_player_to_tile((int)o.position.x, (int)o.position.y); - make_pathfinding_request((vec2f){o.position.x,o.position.y}, - (vec2f){closest_player.playerx, closest_player.playery + get_player_size_in_tile()}, - &zombies[i].next_path, &zombies[i].request); + vec2f target_tile = (vec2f){closest_player.playerx, closest_player.playery+(get_player_size_in_tile()/2)}; + + make_pathfinding_request((vec2f){o.position.x,o.position.y}, target_tile, &zombies[i].next_path, &zombies[i].request); zombies[i].time_since_last_path = 0; } else { @@ -177,8 +192,12 @@ void update_zombies_server(platform_window* window) { { if (zombies[i].request.to_fill->length) { array_destroy(&zombies[i].path); - zombies[i].path = array_copy(&zombies[i].next_path); - array_clear(&zombies[i].next_path); + zombies[i].path = array_copy(zombies[i].request.to_fill); + + player closest_player = get_closest_player_to_tile((int)o.position.x, (int)o.position.y); + vec2f final_pos = get_random_point_around_player(closest_player, zombies[i]); + array_push_at(&zombies[i].path, (u8*)&final_pos, 0); + array_clear(zombies[i].request.to_fill); } } mutex_unlock(&zombies[i].request.mutex); |
