summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorAldrik Ramaekers <aldrikboy@gmail.com>2024-05-11 10:10:23 +0200
committerAldrik Ramaekers <aldrikboy@gmail.com>2024-05-11 10:10:23 +0200
commit981d99c229161c8afa508468032fe3ea0b924d3b (patch)
treecb0a2047210da5bb67e4e5b1acb6f9af390c9783 /src
parent962ebf95459a8da08f44898d13d185e60de59b45 (diff)
render order, zombie render fix
Diffstat (limited to 'src')
-rw-r--r--src/drops.c4
-rw-r--r--src/editor.c8
-rw-r--r--src/game.c12
-rw-r--r--src/map.c2
-rw-r--r--src/objects.c40
-rw-r--r--src/pathfinding.c1
-rw-r--r--src/players.c3
-rw-r--r--src/wall_item.c2
-rw-r--r--src/zombie_chunk.c2
-rw-r--r--src/zombies.c10
10 files changed, 52 insertions, 32 deletions
diff --git a/src/drops.c b/src/drops.c
index 5bc7cef..8db2e88 100644
--- a/src/drops.c
+++ b/src/drops.c
@@ -56,11 +56,11 @@ void draw_drops(platform_window* window) {
b.position.y += 0.2f;
b.position.x -= 0.07f;
box shadow_box = get_render_box_of_square(window, b.position, b.size);
- render_box_with_outline(shadow_box, rgba(0,0,0,alpha * (120.0f/255.0f)));
+ render_fill_box_with_outline(shadow_box, rgba(0,0,0,alpha * (120.0f/255.0f)));
b = drops[i];
box full_box = get_render_box_of_square(window, b.position, b.size);
- //render_box_with_outline(full_box, rgba(218,112,214, alpha));
+ //render_fill_box_with_outline(full_box, rgba(218,112,214, alpha));
renderer->render_image_tint(img_drop, full_box.tl_u.x, full_box.tl_u.y,
full_box.br_d.x - full_box.tl_d.x, full_box.br_d.y - full_box.tr_u.y, rgba(218,112,214, alpha));
diff --git a/src/editor.c b/src/editor.c
index c506cbc..de9a33f 100644
--- a/src/editor.c
+++ b/src/editor.c
@@ -143,10 +143,10 @@ void draw_placing_rectangle(platform_window* window) {
tile t = loaded_map.heightmap[mouse_tile_y][mouse_tile_x];
box box = get_render_box_of_square(window, (vec3f){mouse_tile_x, mouse_tile_y, 0}, (vec3f){1,1,t.height});
- render_quad_with_outline(box.tl_d, box.tr_d, box.bl_d, box.br_d, rgba(255,0,0, 70));
- render_quad_with_outline(box.tl_u, box.tr_u, box.bl_u, box.br_u, rgba(255,0,0, 70));
- render_quad_with_outline(box.tl_u, box.tl_d, box.bl_u, box.bl_d, rgba(255,0,0, 70));
- render_quad_with_outline(box.bl_u, box.br_u, box.bl_d, box.br_d, rgba(255,0,0, 70));
+ render_fill_quad_with_outline(box.tl_d, box.tr_d, box.bl_d, box.br_d, rgba(255,0,0, 70));
+ render_fill_quad_with_outline(box.tl_u, box.tr_u, box.bl_u, box.br_u, rgba(255,0,0, 70));
+ render_fill_quad_with_outline(box.tl_u, box.tl_d, box.bl_u, box.bl_d, rgba(255,0,0, 70));
+ render_fill_quad_with_outline(box.bl_u, box.br_u, box.bl_d, box.br_d, rgba(255,0,0, 70));
}
static bool push_icon_button(int x, int y, int w, image* img, bool isSelected) {
diff --git a/src/game.c b/src/game.c
index 60540a8..b3fd0b2 100644
--- a/src/game.c
+++ b/src/game.c
@@ -385,22 +385,12 @@ void update_game(platform_window* window) {
take_player_input(window);
draw_grid(window);
+ draw_objects(window);
draw_wallitems(window);
draw_zombie_chunks(window);
draw_drops(window);
draw_bullets(window);
draw_throwables(window);
-
- #ifdef MODE_DEBUG
- if (!is_editing_map)
- #endif
- draw_zombies(window);
-
- #ifdef MODE_DEBUG
- if (!is_editing_map)
- #endif
-
- draw_players(window);
draw_round(window);
draw_spawners(window);
draw_overlay(window);
diff --git a/src/map.c b/src/map.c
index 8ec60fb..47f8a07 100644
--- a/src/map.c
+++ b/src/map.c
@@ -434,8 +434,6 @@ void draw_grid(platform_window* window) {
loaded_map.heightmap[y][x].br = bottomright;
}
}
-
- draw_objects(window);
}
inline map_info get_map_info(platform_window* window) {
diff --git a/src/objects.c b/src/objects.c
index 213879c..d5dc0ce 100644
--- a/src/objects.c
+++ b/src/objects.c
@@ -5,17 +5,32 @@ 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);
}
-void render_box_with_outline(box box, color c) {
- render_quad_with_outline(box.tl_d, box.tr_d, box.bl_d, box.br_d, c); // down
- render_quad_with_outline(box.tl_u, box.tr_u, box.bl_u, box.br_u, c); // up
+void render_fill_box_with_outline(box box, color c) {
+ render_fill_quad_with_outline(box.tl_d, box.tr_d, box.bl_d, box.br_d, c); // down
+ render_fill_quad_with_outline(box.tl_u, box.tr_u, box.bl_u, box.br_u, c); // up
- render_quad_with_outline(box.tr_u, box.tr_d, box.br_u, box.br_d, c); // right
- render_quad_with_outline(box.tl_u, box.tl_d, box.bl_u, box.bl_d, c); // left
- render_quad_with_outline(box.bl_u, box.br_u, box.bl_d, box.br_d, c); // bottom
+ render_fill_quad_with_outline(box.tr_u, box.tr_d, box.br_u, box.br_d, c); // right
+ render_fill_quad_with_outline(box.tl_u, box.tl_d, box.bl_u, box.bl_d, c); // left
+ render_fill_quad_with_outline(box.bl_u, box.br_u, box.bl_d, box.br_d, c); // bottom
}
-void render_quad_with_outline(vec2f tl, vec2f tr, vec2f bl, vec2f br, color c) {
+void render_quad_outline(vec2f tl, vec2f tr, vec2f bl, vec2f br, color c) {
+ renderer->render_line(tl.x, tl.y, tr.x, tr.y, 1, rgba(0,0,255, c.a)); // top
+ renderer->render_line(tl.x, tl.y, bl.x, bl.y, 1, rgba(0,0,255, c.a)); // left
+ renderer->render_line(tr.x, tr.y, br.x, br.y, 1, rgba(0,0,255, c.a)); // right
+ renderer->render_line(bl.x, bl.y, br.x, br.y, 1, rgba(0,0,255, c.a)); // bottom
+}
+void render_box_outline(box box, color c) {
+ render_quad_outline(box.tl_d, box.tr_d, box.bl_d, box.br_d, c); // down
+ render_quad_outline(box.tl_u, box.tr_u, box.bl_u, box.br_u, c); // up
+
+ render_quad_outline(box.tr_u, box.tr_d, box.br_u, box.br_d, c); // right
+ render_quad_outline(box.tl_u, box.tl_d, box.bl_u, box.bl_d, c); // left
+ render_quad_outline(box.bl_u, box.br_u, box.bl_d, box.br_d, c); // bottom
+}
+
+void render_fill_quad_with_outline(vec2f tl, vec2f tr, vec2f bl, vec2f br, color c) {
renderer->render_quad(
tl.x, tl.y,
bl.x, bl.y,
@@ -97,6 +112,7 @@ image* get_image_from_objecttype(object_type tile) {
void draw_objects(platform_window* window) {
map_info info = get_map_info(window);
+ uint32_t prev_y = 0;
for (int i = 0; i < MAX_OBJECTS; i++) {
if (!loaded_map.objects[i].active) continue;
object o = loaded_map.objects[i];
@@ -108,7 +124,17 @@ void draw_objects(platform_window* window) {
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);
}
+ render_box_outline(box, rgb(255,0,0));
+
+ if (prev_y < o.position.y) {
+ prev_y = o.position.y;
+ draw_zombies(window, prev_y, prev_y);
+ draw_players(window, prev_y, prev_y);
+ }
}
+
+ draw_zombies(window, prev_y, MAP_SIZE_Y);
+ draw_players(window, prev_y, MAP_SIZE_Y);
}
void create_objects() {
diff --git a/src/pathfinding.c b/src/pathfinding.c
index 70b084b..939adbe 100644
--- a/src/pathfinding.c
+++ b/src/pathfinding.c
@@ -219,6 +219,7 @@ bool find_path_to(vec2f start_pos, vec2f end_pos, array *to_fill, pathfinding_re
vec2f get_open_tile_next_to_target(float x, float y)
{
vec2f adjecent[8] = { {0, -1}, {0, 1}, {-1, 0}, {1, 0}, {-1, -1}, {-1, 1}, {1, -1}, {1, 1} };
+ //vec2f adjecent[4] = { {0, -1}, {0, 1}, {-1, 0}, {1, 0}};
vec2f v_s;
v_s.x = x;
diff --git a/src/players.c b/src/players.c
index cb7842e..2454c28 100644
--- a/src/players.c
+++ b/src/players.c
@@ -603,11 +603,12 @@ void draw_player(platform_window* window, player* p, int index) {
}
}
-void draw_players(platform_window* window) {
+void draw_players(platform_window* window, uint32_t ystart, uint32_t yend) {
float size = get_player_size_in_tile();
for (int i = 0; i < MAX_PLAYERS; i++) {
if (!players[i].active) continue;
+ if (!((int)players[i].playery >= ystart && (int)players[i].playery <= yend+1)) continue;
float height = get_height_of_tile_under_coords(players[i].playerx, players[i].playery);
players[i].height = height;
diff --git a/src/wall_item.c b/src/wall_item.c
index ef656a6..12b5ce7 100644
--- a/src/wall_item.c
+++ b/src/wall_item.c
@@ -80,7 +80,7 @@ void draw_keybinding_for_wallitem_purchase(platform_window* window, wall_item it
key_box.tl_u.y -= KEY_INSET; key_box.bl_u.y -= KEY_INSET;
key_box.tr_u.x -= KEY_INSET; key_box.br_u.x -= KEY_INSET;
key_box.tr_u.y -= KEY_INSET; key_box.br_u.y -= KEY_INSET;
- render_box_with_outline(key_box, rgb(255,255,255));
+ render_fill_box_with_outline(key_box, rgb(255,255,255));
int surface_w = key_box.tr_u.x - key_box.tl_u.x;
int surface_h = key_box.br_u.y - key_box.tr_u.y;
diff --git a/src/zombie_chunk.c b/src/zombie_chunk.c
index fea1ce3..87cb65f 100644
--- a/src/zombie_chunk.c
+++ b/src/zombie_chunk.c
@@ -101,7 +101,7 @@ void draw_zombie_chunks(platform_window* window) {
if (alpha < 0) alpha = 0;
box box = get_render_box_of_square(window, zombie_chunks[i].position, (vec3f){0.6f, 0.6f, 0.6f});
- //render_box_with_outline(box, rgba(200, 50, 50, alpha));
+ //render_fill_box_with_outline(box, rgba(200, 50, 50, alpha));
renderer->render_set_rotation(zombie_chunks[i].rotation);
renderer->render_image_tint(get_chunk_image_from_type(zombie_chunks[i].type), box.tl_d.x, box.tl_d.y, box.tr_d.x - box.tl_d.x, box.br_d.y - box.tr_d.y, rgba(255,255,255,alpha));
diff --git a/src/zombies.c b/src/zombies.c
index c128a0c..04253b8 100644
--- a/src/zombies.c
+++ b/src/zombies.c
@@ -430,17 +430,21 @@ void update_zombies_server(platform_window* window) {
}
}
-void draw_zombies(platform_window* window) {
+void draw_zombies(platform_window* window, uint32_t ystart, uint32_t yend) {
map_info info = get_map_info(window);
for (int i = 0; i < SERVER_MAX_ZOMBIES; i++) {
zombie o = zombies[i];
if (!o.alive) continue;
+ if (!((int)o.position.y >= ystart && (int)o.position.y <= yend+1)) continue;
+
+ float zombie_size = o.size.x * get_tile_width(window);
+ o.position.x -=o.size.x/2.0f;
+ o.position.y -=o.size.x/2.0f;
sprite_frame frame = sprite_get_frame(img_alien_run, &o.sprite_run);
box box = get_render_box_of_square(window, (vec3f){o.position.x, o.position.y, o.position.z}, o.size);
vec2f zombie_pos = world_pos_to_screen_pos(window, o.position.x, o.position.y, o.position.z);
- float zombie_size = o.size.x * get_tile_width(window);
float rads = -atan2(o.dir.x, o.dir.y);
if (rads >= 0.0f) {
@@ -472,7 +476,7 @@ void draw_zombies(platform_window* window) {
renderer->render_rectangle(zombie_pos.x + (zombie_size/2) - (bar_w/2), zombie_pos.y - bar_h, bar_w*percentage, bar_h, rgb(100,0,0));
}
- //if (global_state.server) draw_path_of_zombie(window, o);
+ if (global_state.server) draw_path_of_zombie(window, o);
}
}