summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--build/zombies.exebin1986947 -> 1988075 bytes
-rw-r--r--include/throwables.h3
-rw-r--r--include/zombies.h1
-rw-r--r--src/audio.c14
-rw-r--r--src/bullets.c21
-rw-r--r--src/throwables.c31
-rw-r--r--src/zombies.c26
7 files changed, 71 insertions, 25 deletions
diff --git a/build/zombies.exe b/build/zombies.exe
index 4d9aca5..ca0274d 100644
--- a/build/zombies.exe
+++ b/build/zombies.exe
Binary files differ
diff --git a/include/throwables.h b/include/throwables.h
index 2106c94..0d227d9 100644
--- a/include/throwables.h
+++ b/include/throwables.h
@@ -30,8 +30,11 @@ typedef struct t_throwable {
float alive_time;
int bounces;
sprite sprite;
+ int damage;
} throwable;
+vec3f grenade_explosion_size = (vec3f){2.0f, 2.0f, 2.0f};
+
throwable throwables[500] = {0};
int max_throwables = 500;
diff --git a/include/zombies.h b/include/zombies.h
index eeadaaf..b2aeb2a 100644
--- a/include/zombies.h
+++ b/include/zombies.h
@@ -39,6 +39,7 @@ spawner spawner_tiles[MAX_SPAWNERS] = {0};
#define SERVER_MAX_ZOMBIES (50)
zombie zombies[SERVER_MAX_ZOMBIES] = {0};
+bool hit_zombie(int index, int damage);
void create_spawner(vec2 position);
void draw_spawners(platform_window* window);
void draw_zombies(platform_window* window);
diff --git a/src/audio.c b/src/audio.c
index 734bec6..1c2dbc5 100644
--- a/src/audio.c
+++ b/src/audio.c
@@ -82,7 +82,7 @@ static Mix_Chunk* get_sample_from_audio_event(audio_event event, u32 playerid) {
default: return wav_error;
}
}
- else {
+ else if (event.obj != OBJECT_NONE) {
switch (event.obj)
{
case OBJECT_PLANTBOX1: return wav_impact_wood;
@@ -98,10 +98,16 @@ static Mix_Chunk* get_sample_from_audio_event(audio_event event, u32 playerid) {
void play_sounds_in_queue() {
for (int i = 0; i < max_audio_events; i++) {
if (!audio_events[i].active) continue;
+
+ Mix_Chunk* sample = get_sample_from_audio_event(audio_events[i], audio_events[i].playerid);
+ /*if (sample == wav_error) {
+ log_infox("Missing sample for type: %d | zombie: %d | object: %d | throwable: %d",
+ audio_events[i].type, audio_events[i].obj, audio_events[i].zombie, audio_events[i].throwable);
+ }*/
+
+ int channel = get_channel_from_audio_event_type(audio_events[i].type);
play_positioned_sound(
- get_channel_from_audio_event_type(audio_events[i].type),
- get_sample_from_audio_event(audio_events[i], audio_events[i].playerid),
- audio_events[i].position, 20);
+ channel, sample, audio_events[i].position, 20);
}
}
diff --git a/src/bullets.c b/src/bullets.c
index 403b1b6..9441ead 100644
--- a/src/bullets.c
+++ b/src/bullets.c
@@ -159,26 +159,11 @@ bool check_if_bullet_collided_with_zombie(bullet* b, platform_window* window, pl
if (result) {
b->endy = intersect_point_of_closest_zombie.y;
b->endx = intersect_point_of_closest_zombie.x;
- zombies[index_of_closest_zombie].health -= b->damage;
- b->damage = 0;
-
- // 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);
+
+ if (hit_zombie(index_of_closest_zombie, b->damage)) {
p->kills++;
}
+ b->damage = 0;
}
return result;
diff --git a/src/throwables.c b/src/throwables.c
index eba6dfc..2e7d957 100644
--- a/src/throwables.c
+++ b/src/throwables.c
@@ -15,6 +15,10 @@ void throw_throwable(platform_window* window, u32 id, throwable_type type, float
t.sprite = create_sprite(img_grenade_explode, 12, 96, 96, 0.1f);
+ switch(type) {
+ case THROWABLE_GRENADE: t.damage = 1500; break;
+ }
+
throwables[i] = t;
break;
}
@@ -58,6 +62,26 @@ bool check_if_throwable_collided_with_object(throwable* b, vec3f oldpos, vec3f n
return result;
}
+void explode_grenade(throwable t) {
+ int max_explosion_range = 3;
+
+ for (int i = 0; i < SERVER_MAX_ZOMBIES; i++) {
+ zombie o = zombies[i];
+ if (!o.alive) continue;
+
+ if (t.position.z <= o.position.z + o.size.z && t.position.z >= t.position.z) {
+
+ vec3f grenade_center = get_center_of_square(t.position, grenade_explosion_size);
+ vec3f zombie_center = get_center_of_square(o.position, o.size);
+ float dist_between_grenade_and_zombie = distance_between_3f(o.position, t.position);
+ if (dist_between_grenade_and_zombie > max_explosion_range) continue;
+
+ float damage_multiplier = 1.0f - (dist_between_grenade_and_zombie / max_explosion_range);
+ hit_zombie(i, t.damage*damage_multiplier);
+ }
+ }
+}
+
void update_throwables_server() {
float speed = 7.0f * SERVER_TICK_RATE;
float gravity = 0.015f;
@@ -71,8 +95,11 @@ void update_throwables_server() {
if (throwables[i].alive_time >= 2.0f) {
if (throwables[i].state == THROWABLE_FLYING) {
- //wav_grenade_explode
add_throwable_audio_event_to_queue(EVENT_EXPLODE_THROWABLE, b.type, b.player_id, b.position);
+
+ switch(b.type) {
+ case THROWABLE_GRENADE: explode_grenade(b); break;
+ }
}
throwables[i].state = THROWABLE_EXPLODED;
@@ -134,7 +161,7 @@ void draw_throwables(platform_window* window) {
vec3f explode_location = t.position;
explode_location.x -= 0.9f;
explode_location.y -= 0.9f;
- box box = get_render_box_of_square(window, explode_location, (vec3f){2.0f, 2.0f, 2.0f});
+ box box = get_render_box_of_square(window, explode_location, grenade_explosion_size);
sprite_frame frame = sprite_get_frame(&throwables[i].sprite);
renderer->render_image_quad_partial(img_grenade_explode,
diff --git a/src/zombies.c b/src/zombies.c
index 4c1225a..28c3d62 100644
--- a/src/zombies.c
+++ b/src/zombies.c
@@ -38,6 +38,30 @@ void create_spawner(vec2 position) {
}
}
+bool hit_zombie(int index, int damage) {
+ zombies[index].health -= damage;
+
+ // Random chunks when zombie is hit.
+ if (rand() % 5 == 0) {
+ spawn_zombie_chunk(get_center_of_square(zombies[index].position, zombies[index].size));
+ }
+
+ if (zombies[index].health <= 0) {
+ vec3f center = get_center_of_square(zombies[index].position, zombies[index].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].alive = false;
+ spawn_drop(zombies[index].position);
+ return true;
+ }
+
+ return false;
+}
+
void spawn_zombie(int x, int y) {
for (int i = 0; i < SERVER_MAX_ZOMBIES; i++) {
zombie o = zombies[i];
@@ -47,7 +71,7 @@ void spawn_zombie(int x, int y) {
zombies[i].next_path = array_create(sizeof(vec2f));
zombies[i].alive = true;
zombies[i].type = ZOMBIE_TYPE_NORMAL;
- zombies[i].health = 100.0f;
+ zombies[i].health = 1000.0f;
zombies[i].position = (vec3f){x,y, 0};
zombies[i].size = (vec3f){0.4, 0.4, 1};
zombies[i].time_since_last_path = 0.0f;