summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorAldrik Ramaekers <aldrik@amftech.nl>2022-12-19 20:36:03 +0100
committerAldrik Ramaekers <aldrik@amftech.nl>2022-12-19 20:36:03 +0100
commit1683c214b37c2bb8f3e43fd9054f3a53f7695f4a (patch)
tree75413c601901ff95f15beced52af60f4d1f22d14 /src
parent79efc8a8e9976bbdd41d4a47b58c71d3be9d4ff7 (diff)
splatter
Diffstat (limited to 'src')
-rw-r--r--src/asset_defs.c3
-rw-r--r--src/bullets.c14
-rw-r--r--src/drops.c7
-rw-r--r--src/game.c2
-rw-r--r--src/zombie_chunk.c22
5 files changed, 41 insertions, 7 deletions
diff --git a/src/asset_defs.c b/src/asset_defs.c
index c978da2..337a88f 100644
--- a/src/asset_defs.c
+++ b/src/asset_defs.c
@@ -7,6 +7,9 @@ void load_assets() {
img_icon_bullets = assets_load_image_from_file("data/imgs/bullets.png");
img_icon_nova = assets_load_image_from_file("data/imgs/nova.png");
+ img_drop = assets_load_image_from_file("data/imgs/drop.png");
+
img_zombie_chunk_hand = assets_load_image_from_file("data/imgs/zombie_chunk_hand.png");
img_zombie_chunk_foot = assets_load_image_from_file("data/imgs/zombie_chunk_foot.png");
+ img_zombie_chunk_blood = assets_load_image_from_file("data/imgs/zombie_chunk_blood.png");
} \ No newline at end of file
diff --git a/src/bullets.c b/src/bullets.c
index 1449f93..d701b50 100644
--- a/src/bullets.c
+++ b/src/bullets.c
@@ -156,9 +156,19 @@ bool check_if_bullet_collided_with_zombie(bullet* b, platform_window* window, pl
zombies[index_of_closest_zombie].health -= b->damage;
b->damage = 0;
- int chunk_count = rand() % 4 + 1;
- for (int c = 0; c < chunk_count; c++) spawn_zombie_chunk(get_center_of_square(zombies[index_of_closest_zombie].position, zombies[index_of_closest_zombie].size));
+ // Random chunks when zombie is hit.
+ if (rand() % 5 == 0) {
+ spawn_zombie_chunk(get_center_of_square(zombies[index_of_closest_zombie].position, zombies[index_of_closest_zombie].size));
+ }
+
if (zombies[index_of_closest_zombie].health <= 0) {
+ vec3f center = get_center_of_square(zombies[index_of_closest_zombie].position, zombies[index_of_closest_zombie].size);
+ spawn_zombie_splatter(center);
+
+ // Random chunks when zombie dies.
+ int chunk_count = rand() % 4 + 1;
+ for (int c = 0; c < chunk_count; c++) spawn_zombie_chunk(center);
+
zombies[index_of_closest_zombie].alive = false;
spawn_drop(zombies[index_of_closest_zombie].position);
p->kills++;
diff --git a/src/drops.c b/src/drops.c
index 95d1af7..18aac1d 100644
--- a/src/drops.c
+++ b/src/drops.c
@@ -55,12 +55,15 @@ void draw_drops(platform_window* window) {
b.size.z = 0.0f;
b.position.y += 0.2f;
b.position.x -= 0.07f;
+ b.size.x -= 0.1f;
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)));
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_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.tr_u.x - full_box.tl_d.x, full_box.br_d.y - full_box.tr_u.y, rgba(218,112,214, alpha));
int drop_h = full_box.br_d.y - full_box.tr_d.y;
@@ -94,7 +97,7 @@ void spawn_drop(vec3f pos) {
new_drop.active = true;
new_drop.time_active = 0.0f;
new_drop.position = pos;
- new_drop.size = (vec3f){0.3f, 0.3f, 0.4f};
+ new_drop.size = (vec3f){0.5f, 0.5f, 0.4f};
new_drop.start_h = pos.z;
new_drop.type = DROP_AMMO;
new_drop.data.ammo_count = 20;
diff --git a/src/game.c b/src/game.c
index 7cd0b0b..d184ae5 100644
--- a/src/game.c
+++ b/src/game.c
@@ -315,13 +315,13 @@ void update_game(platform_window* window) {
draw_grid(window);
draw_wallitems(window);
+ draw_zombie_chunks(window);
draw_drops(window);
draw_bullets(window);
draw_zombies(window);
draw_players(window);
draw_spawners(window);
draw_overlay(window);
- draw_zombie_chunks(window);
_global_camera.x = (int)_next_camera_pos.x;
_global_camera.y = (int)_next_camera_pos.y;
diff --git a/src/zombie_chunk.c b/src/zombie_chunk.c
index f248474..9a10e00 100644
--- a/src/zombie_chunk.c
+++ b/src/zombie_chunk.c
@@ -19,6 +19,23 @@ static image* get_chunk_image() {
return available_zombie_chunks[rand() % AVAILABLE_ZOMBIE_CHUNK_COUNT];
}
+void spawn_zombie_splatter(vec3f center) {
+ for (int i = 0; i < MAX_ZOMBIE_CHUNKS; i++)
+ {
+ if (zombie_chunks[i].active) continue;
+
+ float height = get_height_of_tile_under_coords(center.x, center.y);
+ center.z = height;
+ vec2f dir = (vec2f){0,0};
+
+ zombie_chunk chunk = {.active = true, .start_position = center, .direction = dir,
+ .position = center, .duration = 0.0f, .target_position = center,
+ .img = img_zombie_chunk_blood, .rotation = (float)rand()/(float)(RAND_MAX), .rotation_speed = 0.0f};
+ zombie_chunks[i] = chunk;
+ return;
+ }
+}
+
void spawn_zombie_chunk(vec3f center) {
for (int i = 0; i < MAX_ZOMBIE_CHUNKS; i++)
{
@@ -30,7 +47,7 @@ void spawn_zombie_chunk(vec3f center) {
zombie_chunk chunk = {.active = true, .start_position = center, .direction = dir,
.position = center, .duration = 0.0f, .target_position = (vec3f){target.x, target.y, height},
- .img = get_chunk_image(), .rotation = (float)rand()/(float)(RAND_MAX)};
+ .img = get_chunk_image(), .rotation = (float)rand()/(float)(RAND_MAX), .rotation_speed = dir.x < 0.0f ? update_delta : -update_delta};
zombie_chunks[i] = chunk;
return;
}
@@ -50,7 +67,8 @@ void update_zombie_chunks() {
continue;
}
- zombie_chunks[i].rotation += zombie_chunks[i].direction.x < 0.0f ? update_delta : -update_delta;
+
+ zombie_chunks[i].rotation += zombie_chunks[i].rotation_speed;
float x = zombie_chunks[i].start_position.x + ((zombie_chunks[i].start_position.x - zombie_chunks[i].target_position.x) / CHUNK_DURATION_OF_DROP) * zombie_chunks[i].duration;
float y = zombie_chunks[i].start_position.y + ((zombie_chunks[i].start_position.y - zombie_chunks[i].target_position.y) / CHUNK_DURATION_OF_DROP) * zombie_chunks[i].duration;