diff options
| author | Aldrik Ramaekers <aldrikboy@gmail.com> | 2024-05-11 16:32:33 +0200 |
|---|---|---|
| committer | Aldrik Ramaekers <aldrikboy@gmail.com> | 2024-05-11 16:32:33 +0200 |
| commit | 28bf7168e633629a6a049f639950a30f26102f40 (patch) | |
| tree | 2caa6d5d68ebc2228409d32f8c1bd61fa8e81c16 | |
| parent | a50de53da1dc128ffbcdacba28353fe0825c4ac9 (diff) | |
automatic door
| -rw-r--r-- | .vscode/settings.json | 4 | ||||
| -rw-r--r-- | data/maps/map1.dat | bin | 8384008 -> 8384008 bytes | |||
| -rw-r--r-- | include/glass_doors.h | 20 | ||||
| -rw-r--r-- | main.c | 2 | ||||
| -rw-r--r-- | src/game.c | 1 | ||||
| -rw-r--r-- | src/glass_doors.c | 49 | ||||
| -rw-r--r-- | src/map.c | 5 | ||||
| -rw-r--r-- | src/objects.c | 5 | ||||
| -rw-r--r-- | src/players.c | 2 |
9 files changed, 86 insertions, 2 deletions
diff --git a/.vscode/settings.json b/.vscode/settings.json index e9e1d02..21cfb64 100644 --- a/.vscode/settings.json +++ b/.vscode/settings.json @@ -3,6 +3,8 @@ "project_base.h": "c", "initializer_list": "c", "type_traits": "c", - "xutility": "c" + "xutility": "c", + "editor.h": "c", + "glass_doors.h": "c" } }
\ No newline at end of file diff --git a/data/maps/map1.dat b/data/maps/map1.dat Binary files differindex f6cad45..56427bf 100644 --- a/data/maps/map1.dat +++ b/data/maps/map1.dat diff --git a/include/glass_doors.h b/include/glass_doors.h new file mode 100644 index 0000000..07804d5 --- /dev/null +++ b/include/glass_doors.h @@ -0,0 +1,20 @@ +#ifndef INCLUDE_GLASS_DOOR +#define INCLUDE_GLASS_DOOR + +#include "objects.h" + +typedef struct t_glass_door +{ + object obj; + bool is_open; + float time_since_open; +} glass_door; + +#define MAX_GLASS_DOORS 100 +glass_door glass_doors[MAX_GLASS_DOORS]; + +void create_glass_door(object o); +void draw_glass_doors(platform_window* window, uint32_t ystart, uint32_t yend); +void update_glass_doors_server(); + +#endif
\ No newline at end of file @@ -30,6 +30,7 @@ #include "include/zombie_chunk.h" #include "include/sprite.h" #include "include/editor.h" +#include "include/glass_doors.h" #include "src/map.c" #include "src/players.c" @@ -53,6 +54,7 @@ #include "src/zombie_chunk.c" #include "src/sprite.c" #include "src/editor.c" +#include "src/glass_doors.c" #define CONFIG_DIRECTORY "zombieshooter" @@ -222,6 +222,7 @@ void update_server(platform_window* window) { update_zombie_chunks_server(); update_round_server(); update_points_animation_server(); + update_glass_doors_server(); broadcast_players = platform_get_time(TIME_FULL, TIME_NS); update_players_server(); diff --git a/src/glass_doors.c b/src/glass_doors.c new file mode 100644 index 0000000..dc5ed5e --- /dev/null +++ b/src/glass_doors.c @@ -0,0 +1,49 @@ +#include "../include/glass_doors.h" + +void create_glass_door(object o) +{ + for (int i = 0; i < MAX_GLASS_DOORS; i++) + { + if (glass_doors[i].obj.active) continue; + glass_doors[i].obj = o; + glass_doors[i].time_since_open = 0.0f; + glass_doors[i].is_open = 0; + return; + } +} + +void update_glass_doors_server() +{ + for (int i = 0; i < MAX_GLASS_DOORS; i++) + { + if (!glass_doors[i].obj.active) continue; + glass_doors[i].is_open = 0; + + for (int x = 0; x < MAX_PLAYERS; x++) { + if (!players[x].active) continue; + + if (distance_between((vec2f){.x = glass_doors[i].obj.position.x, .y = glass_doors[i].obj.position.y}, + (vec2f){.x = players[x].playerx, .y = players[x].playery}) < 3.0f) { + glass_doors[i].is_open = 1; + } + } + } +} + +void draw_glass_doors(platform_window* window, uint32_t ystart, uint32_t yend) +{ + for (int i = 0; i < MAX_GLASS_DOORS; i++) + { + if (!glass_doors[i].obj.active) continue; + if (!((int)glass_doors[i].obj.position.y >= ystart && (int)glass_doors[i].obj.position.y <= yend+1)) continue; + + object o = glass_doors[i].obj; + box box = get_box_of_object(window, o); + + image* img = glass_doors[i].is_open ? img_glass_door_h_open : img_glass_door_h_closed; + if (img) { + renderer->render_image(img, box.tl_u.x, box.tl_u.y, + box.br_d.x - box.tl_d.x, box.br_d.y - box.tr_u.y); + } + } +}
\ No newline at end of file @@ -1,4 +1,5 @@ #include "../include/map.h" +#include "../include/glass_doors.h" int player_zoom = 30; static int get_height_of_tile_tl(int current_height, int x, int y) { @@ -271,6 +272,10 @@ void load_mapdata_into_world() { if (o.type == OBJECT_ZOMBIE_SPAWNER) { create_spawner((vec2){.x = o.position.x, .y = o.position.y}); } + + if (o.type == OBJECT_GLASS_DOOR_H) { + create_glass_door(o); + } } } diff --git a/src/objects.c b/src/objects.c index c1caad7..e551544 100644 --- a/src/objects.c +++ b/src/objects.c @@ -1,5 +1,6 @@ #include "../include/objects.h" #include "../include/wall_item.h" +#include "../include/glass_doors.h" box get_box_of_object(platform_window* window, object o) { return get_render_box_of_square(window, (vec3f){o.position.x, o.position.y, o.position.z}, o.size); @@ -132,6 +133,8 @@ void draw_objects(platform_window* window) { for (int i = 0; i < MAX_OBJECTS; i++) { if (!loaded_map.objects[i].active) continue; object o = loaded_map.objects[i]; + + if (o.type == OBJECT_GLASS_DOOR_H) continue; box box = get_box_of_object(window, o); @@ -149,6 +152,7 @@ void draw_objects(platform_window* window) { if (!is_editing_map) #endif draw_players(window, prev_y, prev_y); + draw_glass_doors(window, prev_y, prev_y); } } @@ -157,6 +161,7 @@ void draw_objects(platform_window* window) { if (!is_editing_map) #endif draw_players(window, prev_y, MAP_SIZE_Y); + draw_glass_doors(window, prev_y, MAP_SIZE_Y); } void create_objects() { diff --git a/src/players.c b/src/players.c index 5ad954f..4fb513e 100644 --- a/src/players.c +++ b/src/players.c @@ -51,7 +51,7 @@ void spawn_player(u32 id, network_client client) { players[i].active = true; players[i].sec_since_last_shot = 10.0f; players[i].sec_since_last_damage_taken = 10.0f; - players[i].playerx = 30; + players[i].playerx = 40; players[i].playery = 3; players[i].gunx = 0.0f; players[i].guny = 0.0f; |
