summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAldrik Ramaekers <aldrik@amftech.nl>2023-10-29 09:06:10 +0100
committerAldrik Ramaekers <aldrik@amftech.nl>2023-10-29 09:06:10 +0100
commit2bcffc7def20dd1e660d742f54bd97307b9f193d (patch)
tree84443fceb1b067549874b4f14e0d4aa36b0630db
parentd2c3f612b3d7b0071e98e589777d495ba45eafe4 (diff)
grenade work
-rw-r--r--build/data/imgs/throwables/grenade.png (renamed from build/data/imgs/grenade.png)bin491 -> 491 bytes
-rw-r--r--build/data/imgs/throwables/grenade_explode.pngbin0 -> 10612 bytes
-rw-r--r--build/data/sounds/grenade_explode.wavbin0 -> 52268 bytes
-rw-r--r--build/zombies.exebin1983269 -> 1986947 bytes
-rw-r--r--data/imgs/throwables/grenade.png (renamed from data/imgs/grenade.png)bin491 -> 491 bytes
-rw-r--r--data/imgs/throwables/grenade_explode.pngbin0 -> 10612 bytes
-rw-r--r--data/sounds/grenade_explode.wavbin0 -> 52268 bytes
-rw-r--r--include/asset_defs.h3
-rw-r--r--include/audio.h5
-rw-r--r--include/throwables.h9
-rw-r--r--src/asset_defs.c4
-rw-r--r--src/audio.c20
-rw-r--r--src/game.c2
-rw-r--r--src/throwables.c54
14 files changed, 75 insertions, 22 deletions
diff --git a/build/data/imgs/grenade.png b/build/data/imgs/throwables/grenade.png
index 320b29b..320b29b 100644
--- a/build/data/imgs/grenade.png
+++ b/build/data/imgs/throwables/grenade.png
Binary files differ
diff --git a/build/data/imgs/throwables/grenade_explode.png b/build/data/imgs/throwables/grenade_explode.png
new file mode 100644
index 0000000..8caaa3c
--- /dev/null
+++ b/build/data/imgs/throwables/grenade_explode.png
Binary files differ
diff --git a/build/data/sounds/grenade_explode.wav b/build/data/sounds/grenade_explode.wav
new file mode 100644
index 0000000..87beacd
--- /dev/null
+++ b/build/data/sounds/grenade_explode.wav
Binary files differ
diff --git a/build/zombies.exe b/build/zombies.exe
index 07251d2..4d9aca5 100644
--- a/build/zombies.exe
+++ b/build/zombies.exe
Binary files differ
diff --git a/data/imgs/grenade.png b/data/imgs/throwables/grenade.png
index 320b29b..320b29b 100644
--- a/data/imgs/grenade.png
+++ b/data/imgs/throwables/grenade.png
Binary files differ
diff --git a/data/imgs/throwables/grenade_explode.png b/data/imgs/throwables/grenade_explode.png
new file mode 100644
index 0000000..8caaa3c
--- /dev/null
+++ b/data/imgs/throwables/grenade_explode.png
Binary files differ
diff --git a/data/sounds/grenade_explode.wav b/data/sounds/grenade_explode.wav
new file mode 100644
index 0000000..87beacd
--- /dev/null
+++ b/data/sounds/grenade_explode.wav
Binary files differ
diff --git a/include/asset_defs.h b/include/asset_defs.h
index 7237a6d..65767c6 100644
--- a/include/asset_defs.h
+++ b/include/asset_defs.h
@@ -24,6 +24,7 @@ image* img_obj_wall1;
// Throwables
image* img_grenade;
+image* img_grenade_explode;
// Players
image* img_player;
@@ -39,6 +40,8 @@ image* img_tile_grass1;
// Sounds
Mix_Chunk* wav_throwable_bounce;
+Mix_Chunk* wav_grenade_explode;
+
Mix_Chunk* wav_shoot_mp5;
Mix_Chunk* wav_reload_mp5;
diff --git a/include/audio.h b/include/audio.h
index c7cb9c7..de76af8 100644
--- a/include/audio.h
+++ b/include/audio.h
@@ -2,6 +2,7 @@
#define INCLUDE_AUDIO_
#include <projectbase/project_base.h>
+#include "throwables.h"
#define NUMBER_OF_AUDIO_CHANNELS 64
@@ -9,11 +10,13 @@
#define CHANNEL_SHOOTING 1
#define CHANNEL_IMPACT 2
#define CHANNEL_RELOAD 3
+#define CHANNEL_EXPLODE 4
typedef enum t_audio_event_type {
EVENT_SHOOT,
EVENT_RELOAD,
EVENT_BOUNCE_THROWABLE,
+ EVENT_EXPLODE_THROWABLE,
EVENT_IMPACT,
} audio_event_type;
@@ -24,12 +27,14 @@ typedef struct t_audio_event {
vec3f position;
object_type obj;
zombie_type zombie;
+ throwable_type throwable;
} audio_event;
#define MAX_AUDIO_EVENTS 20
audio_event audio_events[MAX_AUDIO_EVENTS] = {0};
int max_audio_events = MAX_AUDIO_EVENTS;
+void add_throwable_audio_event_to_queue(audio_event_type event, throwable_type throwable, u32 playerid, vec3f position);
void add_zombie_audio_event_to_queue(audio_event_type event, zombie_type zombie, u32 playerid, vec3f position);
void add_object_audio_event_to_queue(audio_event_type event, object_type obj, u32 playerid, vec3f position);
void add_audio_event_to_queue(audio_event_type event, u32 playerid, vec3f position);
diff --git a/include/throwables.h b/include/throwables.h
index 16811b2..2106c94 100644
--- a/include/throwables.h
+++ b/include/throwables.h
@@ -14,20 +14,27 @@ typedef enum t_throwable_type
THROWABLE_GRENADE,
} throwable_type;
+typedef enum t_throwable_state
+{
+ THROWABLE_FLYING,
+ THROWABLE_EXPLODED,
+} throwable_state;
+
typedef struct t_throwable {
u32 player_id;
bool active;
+ throwable_state state;
throwable_type type;
vec3f position;
vec3f direction;
float alive_time;
int bounces;
+ sprite sprite;
} throwable;
throwable throwables[500] = {0};
int max_throwables = 500;
-void clear_throwables();
void throw_throwable(platform_window* window, u32 id, throwable_type type, float dirx, float diry);
void draw_throwables(platform_window* window);
diff --git a/src/asset_defs.c b/src/asset_defs.c
index ee8dced..60f53bb 100644
--- a/src/asset_defs.c
+++ b/src/asset_defs.c
@@ -16,7 +16,8 @@ void load_assets() {
img_sunny = assets_load_image_from_file("data/imgs/icons/sunny.png");
// Throwables
- img_grenade = assets_load_image_from_file("data/imgs/grenade.png");
+ img_grenade = assets_load_image_from_file("data/imgs/throwables/grenade.png");
+ img_grenade_explode = assets_load_image_from_file("data/imgs/throwables/grenade_explode.png");
// Objects
img_spawner = assets_load_image_from_file("data/imgs/spawner.png");
@@ -37,6 +38,7 @@ void load_assets() {
// sounds
wav_throwable_bounce = Mix_LoadWAV("data/sounds/throwable_bounce.wav");
+ wav_grenade_explode = Mix_LoadWAV("data/sounds/grenade_explode.wav");
wav_shoot_mp5 = Mix_LoadWAV("data/sounds/shoot_mp5.wav");
wav_reload_mp5 = Mix_LoadWAV("data/sounds/reload_mp5.wav");
wav_shoot_nova = Mix_LoadWAV("data/sounds/shoot_nova.wav");
diff --git a/src/audio.c b/src/audio.c
index c6f69b9..734bec6 100644
--- a/src/audio.c
+++ b/src/audio.c
@@ -1,10 +1,19 @@
#include "../include/audio.h"
+void add_throwable_audio_event_to_queue(audio_event_type event, throwable_type throwable, u32 playerid, vec3f position) {
+ for (int i = 0; i < max_audio_events; i++) {
+ if (audio_events[i].active) continue;
+
+ audio_events[i] = (audio_event){.active = true, .throwable = throwable, .obj = OBJECT_NONE, .zombie = ZOMBIE_TYPE_NONE, .playerid = playerid, .position = position, .type = event};
+ return;
+ }
+}
+
void add_zombie_audio_event_to_queue(audio_event_type event, zombie_type zombie, u32 playerid, vec3f position) {
for (int i = 0; i < max_audio_events; i++) {
if (audio_events[i].active) continue;
- audio_events[i] = (audio_event){.active = true, .obj = OBJECT_NONE, .zombie = zombie, .playerid = playerid, .position = position, .type = event};
+ audio_events[i] = (audio_event){.active = true, .throwable = THROWABLE_NONE, .obj = OBJECT_NONE, .zombie = zombie, .playerid = playerid, .position = position, .type = event};
return;
}
}
@@ -13,7 +22,7 @@ void add_object_audio_event_to_queue(audio_event_type event, object_type obj, u3
for (int i = 0; i < max_audio_events; i++) {
if (audio_events[i].active) continue;
- audio_events[i] = (audio_event){.active = true, .obj = obj, .zombie = ZOMBIE_TYPE_NONE, .playerid = playerid, .position = position, .type = event};
+ audio_events[i] = (audio_event){.active = true, .throwable = THROWABLE_NONE, .obj = obj, .zombie = ZOMBIE_TYPE_NONE, .playerid = playerid, .position = position, .type = event};
return;
}
}
@@ -29,6 +38,7 @@ static int get_channel_from_audio_event_type(audio_event_type event) {
case EVENT_SHOOT: return CHANNEL_SHOOTING;
case EVENT_RELOAD: return CHANNEL_RELOAD;
case EVENT_IMPACT: return CHANNEL_IMPACT;
+ case EVENT_EXPLODE_THROWABLE: return CHANNEL_EXPLODE;
default: return 0;
}
@@ -41,6 +51,12 @@ static Mix_Chunk* get_sample_from_audio_event(audio_event event, u32 playerid) {
switch (event.type)
{
case EVENT_BOUNCE_THROWABLE: return wav_throwable_bounce;
+ case EVENT_EXPLODE_THROWABLE: {
+ switch(event.throwable) {
+ case THROWABLE_GRENADE: return wav_grenade_explode;
+ default: return wav_error;
+ }
+ }
case EVENT_SHOOT: {
switch (p->guntype)
{
diff --git a/src/game.c b/src/game.c
index ec1d3cd..8bf9106 100644
--- a/src/game.c
+++ b/src/game.c
@@ -191,8 +191,6 @@ void update_server(platform_window* window) {
broadcast_zombies = platform_get_time(TIME_FULL, TIME_NS);
update_zombies_server(window);
broadcast_zombies = platform_get_time(TIME_FULL, TIME_NS) - broadcast_zombies;
-
- clear_throwables();
broadcast_stamp = platform_get_time(TIME_FULL, TIME_NS);
broadcast_to_clients(create_protocol_user_list());
diff --git a/src/throwables.c b/src/throwables.c
index 630dccb..eba6dfc 100644
--- a/src/throwables.c
+++ b/src/throwables.c
@@ -1,16 +1,6 @@
#include "../include/throwables.h"
#include "../include/audio.h"
-void clear_throwables() {
- for (int i = 0; i < max_throwables; i++) {
- if (!throwables[i].active) continue;
- throwables[i].alive_time += SERVER_TICK_RATE;
- if (throwables[i].alive_time >= 2.0f) {
- throwables[i].active = false;
- }
- }
-}
-
void throw_throwable(platform_window* window, u32 id, throwable_type type, float dirx, float diry) {
for (int i = 0; i < max_throwables; i++) {
if (throwables[i].active) continue;
@@ -20,9 +10,11 @@ void throw_throwable(platform_window* window, u32 id, throwable_type type, float
log_info("User with unknown id throwing stuff");
}
- throwable t = {.active = true, .alive_time = 0.0f, .type = type, .direction = (vec3f){.x = dirx, .y = diry, .z = -0.2f},
+ throwable t = {.active = true, .state = THROWABLE_FLYING, .alive_time = 0.0f, .type = type, .direction = (vec3f){.x = dirx, .y = diry, .z = -0.2f},
.player_id = id, .position = (vec3f){.x = p->playerx, .y = p->playery, .z = p->height}};
+ t.sprite = create_sprite(img_grenade_explode, 12, 96, 96, 0.1f);
+
throwables[i] = t;
break;
}
@@ -74,6 +66,23 @@ void update_throwables_server() {
for (int i = 0; i < max_throwables; i++) {
throwable b = throwables[i];
if (!b.active) continue;
+
+ throwables[i].alive_time += SERVER_TICK_RATE;
+ 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);
+ }
+
+ throwables[i].state = THROWABLE_EXPLODED;
+ update_sprite(&throwables[i].sprite);
+ }
+ if (throwables[i].alive_time >= 3.2f) {
+ throwables[i].active = false;
+ continue;
+ }
+
player *p = get_player_by_id(b.player_id);
if (!p) continue;
@@ -121,11 +130,24 @@ void draw_throwables(platform_window* window) {
float throwable_render_x = t.position.x*info.tile_width + (t.position.y*info.px_incline);
float throwable_render_y = t.position.y*info.tile_height - (t.position.z*info.px_raised_per_h);
- box full_box = get_render_box_of_square(window, t.position, (vec3f){0.2, 0.2, 0.2});
- renderer->render_image(img_grenade, full_box.tl_u.x, full_box.tl_u.y,
+ if (t.state == THROWABLE_EXPLODED) {
+ 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});
+
+ sprite_frame frame = sprite_get_frame(&throwables[i].sprite);
+ renderer->render_image_quad_partial(img_grenade_explode,
+ box.tl_u.x, box.tl_u.y,
+ box.bl_d.x, box.bl_d.y,
+ box.br_d.x, box.br_d.y,
+ box.tr_u.x, box.tr_u.y,
+ frame.tl, frame.tr, frame.bl, frame.br);
+ }
+ else if (t.state == THROWABLE_FLYING) {
+ box full_box = get_render_box_of_square(window, t.position, (vec3f){0.2, 0.2, 0.2});
+ renderer->render_image(img_grenade, 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);
-
-
- //renderer->render_image(img_grenade, throwable_render_x, throwable_render_y, 10, 10);
+ }
}
} \ No newline at end of file