summaryrefslogtreecommitdiff
path: root/src
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 /src
parentd2c3f612b3d7b0071e98e589777d495ba45eafe4 (diff)
grenade work
Diffstat (limited to 'src')
-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
4 files changed, 59 insertions, 21 deletions
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