summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorAldrik Ramaekers <aldrik@amftech.nl>2023-10-28 15:39:00 +0200
committerAldrik Ramaekers <aldrik@amftech.nl>2023-10-28 15:39:00 +0200
commit1ac22220f6077b3367456384b4bb563f1c5c2d29 (patch)
tree4a85a2af22fb76e029698638581e738a95ff9957 /src
parent2f3be64ddfcd5beac009b56cee34812e20849ef1 (diff)
sound effects, throwable speed
Diffstat (limited to 'src')
-rw-r--r--src/asset_defs.c5
-rw-r--r--src/audio.c35
-rw-r--r--src/bullets.c19
-rw-r--r--src/throwables.c10
4 files changed, 45 insertions, 24 deletions
diff --git a/src/asset_defs.c b/src/asset_defs.c
index 88e6616..86832d4 100644
--- a/src/asset_defs.c
+++ b/src/asset_defs.c
@@ -15,6 +15,9 @@ void load_assets() {
img_tiles = assets_load_image_from_file("data/imgs/icons/tiles.png");
img_sunny = assets_load_image_from_file("data/imgs/icons/sunny.png");
+ // Throwables
+ img_grenade = assets_load_image_from_file("data/imgs/grenade.png");
+
// Objects
img_spawner = assets_load_image_from_file("data/imgs/spawner.png");
img_obj_plants = assets_load_image_from_file("data/imgs/plants.png");
@@ -36,4 +39,6 @@ void load_assets() {
wav_throwable_bounce = Mix_LoadWAV("data/sounds/throwable_bounce.wav");
wav_shoot_mp5 = Mix_LoadWAV("data/sounds/shoot_mp5.wav");
wav_reload_mp5 = Mix_LoadWAV("data/sounds/reload_mp5.wav");
+ wav_impact_wood = Mix_LoadWAV("data/sounds/impact_wood.wav");
+ wav_error = Mix_LoadWAV("data/sounds/error.wav");
} \ No newline at end of file
diff --git a/src/audio.c b/src/audio.c
index 4a10241..0c53538 100644
--- a/src/audio.c
+++ b/src/audio.c
@@ -1,61 +1,70 @@
#include "../include/audio.h"
-void add_audio_event_to_queue(audio_event_type event, u32 playerid, vec3f position) {
+void add_object_audio_event_to_queue(audio_event_type event, object_type obj, 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, .playerid = playerid, .position = position, .type = event};
+ audio_events[i] = (audio_event){.active = true, .obj = obj, .playerid = playerid, .position = position, .type = event};
return;
}
}
+void add_audio_event_to_queue(audio_event_type event, u32 playerid, vec3f position) {
+ add_object_audio_event_to_queue(event, OBJECT_NONE, playerid, position);
+}
+
static int get_channel_from_audio_event_type(audio_event_type event) {
switch (event)
{
case EVENT_BOUNCE_THROWABLE: return CHANNEL_THROWABLES;
- case EVENT_SHOOT: return CHANNEL_SHOOTING;
+ case EVENT_SHOOT:
case EVENT_RELOAD: return CHANNEL_SHOOTING;
+ case EVENT_IMPACT: return CHANNEL_IMPACT;
default: return 0;
}
}
-static Mix_Chunk* get_sample_from_audio_event_type(audio_event_type event, u32 playerid) {
+static Mix_Chunk* get_sample_from_audio_event(audio_event event, u32 playerid) {
player* p = get_player_by_id(playerid);
if (!p) return 0;
- switch (event)
+ switch (event.type)
{
case EVENT_BOUNCE_THROWABLE: return wav_throwable_bounce;
case EVENT_SHOOT: {
switch (p->guntype)
{
case GUN_MP5: return wav_shoot_mp5;
- default:
- break;
+ default: return wav_error;
}
}
case EVENT_RELOAD: {
switch (p->guntype)
{
case GUN_MP5: return wav_reload_mp5;
- default:
- break;
+ default: return wav_error;
}
}
- default:
- break;
+ case EVENT_IMPACT: {
+ switch (event.obj)
+ {
+ case OBJECT_PLANTBOX1: return wav_impact_wood;
+ default: return wav_error;
+ }
+ }
+
+ default: return wav_error;
}
}
void play_sounds_in_queue() {
for (int i = 0; i < max_audio_events; i++) {
if (!audio_events[i].active) continue;
-
play_positioned_sound(
get_channel_from_audio_event_type(audio_events[i].type),
- get_sample_from_audio_event_type(audio_events[i].type, audio_events[i].playerid),
+ get_sample_from_audio_event(audio_events[i], audio_events[i].playerid),
audio_events[i].position, 20);
}
}
diff --git a/src/bullets.c b/src/bullets.c
index f5d5198..728326e 100644
--- a/src/bullets.c
+++ b/src/bullets.c
@@ -70,14 +70,14 @@ bool check_if_bullet_collided_with_section(float* dist_of_closest_intersect, vec
return false;
}
-bool check_if_bullet_collided_with_object(bullet* b, platform_window* window) {
+object_type check_if_bullet_collided_with_object(bullet* b, platform_window* window) {
map_info info = get_map_info(window);
float size = get_bullet_size_in_tile(window);
vec2f bstart = (vec2f){b->position.x, b->position.y};
vec2f bend = (vec2f){b->endx, b->endy};
- bool result = false;
+ object_type result = OBJECT_NONE;
float dist_of_closest_intersect = __FLT_MAX__;
for (int i = 0; i < MAX_OBJECTS; i++) {
@@ -87,19 +87,19 @@ bool check_if_bullet_collided_with_object(bullet* b, platform_window* window) {
box obj_box = get_box_of_square((vec3f){o.position.x, o.position.y, o.h}, o.size);
vec2f intersect_point;
if (check_if_bullet_collided_with_section(&dist_of_closest_intersect, bstart, bend, obj_box.bl_d, obj_box.br_d, &intersect_point)) {
- result = true;
+ result = o.type;
}
if (check_if_bullet_collided_with_section(&dist_of_closest_intersect, bstart, bend, obj_box.tl_d, obj_box.tr_d, &intersect_point)) {
- result = true;
+ result = o.type;
}
if (check_if_bullet_collided_with_section(&dist_of_closest_intersect, bstart, bend, obj_box.tl_d, obj_box.bl_d, &intersect_point)) {
- result = true;
+ result = o.type;
}
if (check_if_bullet_collided_with_section(&dist_of_closest_intersect, bstart, bend, obj_box.tr_d, obj_box.br_d, &intersect_point)) {
- result = true;
+ result = o.type;
}
- if (result) {
+ if (result != OBJECT_NONE) {
b->endy = intersect_point.y;
b->endx = intersect_point.x;
}
@@ -234,10 +234,13 @@ void update_bullets_server(platform_window* window) {
b = bullets[i];
}
- if (check_if_bullet_collided_with_object(&b, window)) {
+ object_type obj_collision = check_if_bullet_collided_with_object(&b, window);
+ if (obj_collision != OBJECT_NONE) {
bullets[i].endy = b.endy;
bullets[i].endx = b.endx;
b = bullets[i];
+
+ add_object_audio_event_to_queue(EVENT_IMPACT, obj_collision, p->id, (vec3f){.x = p->playerx, .y = p->playery, .z = p->height});
}
if (check_if_bullet_collided_with_zombie(&b, window, p)) {
diff --git a/src/throwables.c b/src/throwables.c
index 275e95b..1d04565 100644
--- a/src/throwables.c
+++ b/src/throwables.c
@@ -4,8 +4,8 @@
void clear_throwables() {
for (int i = 0; i < max_throwables; i++) {
if (!throwables[i].active) continue;
- throwables[i].alive_time += update_delta;
- if (throwables[i].alive_time >= 3.0f) {
+ throwables[i].alive_time += SERVER_TICK_RATE;
+ if (throwables[i].alive_time >= 2.0f) {
throwables[i].active = false;
}
}
@@ -69,6 +69,7 @@ bool check_if_throwable_collided_with_object(throwable* b, vec3f oldpos, vec3f n
void update_throwables_server() {
float speed = 7.0f * SERVER_TICK_RATE;
float gravity = 0.015f;
+ float speed_decrease = 0.97f;
for (int i = 0; i < max_throwables; i++) {
throwable b = throwables[i];
@@ -86,6 +87,9 @@ void update_throwables_server() {
if (throwables[i].direction.z != 0) throwables[i].direction.z += gravity;
throwables[i].position.z -= throwables[i].direction.z;
+ throwables[i].direction.x *= speed_decrease;
+ throwables[i].direction.y *= speed_decrease;
+
// bouncing off floor
float floor = get_height_of_tile_under_coords(throwables[i].position.x, throwables[i].position.y);
if (throwables[i].position.z < floor && throwables[i].direction.z != 0) {
@@ -117,6 +121,6 @@ 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);
- renderer->render_rectangle(throwable_render_x, throwable_render_y, 10, 10, rgb(255, 51, 51));
+ renderer->render_image(img_grenade, throwable_render_x, throwable_render_y, 10, 10);
}
} \ No newline at end of file