diff options
| -rw-r--r-- | .vscode/settings.json | 6 | ||||
| -rw-r--r-- | build/data/imgs/grenade.png | bin | 0 -> 491 bytes | |||
| -rw-r--r-- | build/data/sounds/error.wav | bin | 0 -> 8908 bytes | |||
| -rw-r--r-- | build/data/sounds/impact_wood.wav | bin | 0 -> 3704 bytes | |||
| -rw-r--r-- | build/zombies.exe | bin | 1979153 -> 1979802 bytes | |||
| -rw-r--r-- | data/imgs/grenade.png | bin | 0 -> 491 bytes | |||
| -rw-r--r-- | data/sounds/error.wav | bin | 0 -> 8908 bytes | |||
| -rw-r--r-- | data/sounds/impact_wood.wav | bin | 0 -> 3704 bytes | |||
| -rw-r--r-- | include/asset_defs.h | 7 | ||||
| -rw-r--r-- | include/audio.h | 4 | ||||
| -rw-r--r-- | include/objects.h | 1 | ||||
| -rw-r--r-- | include/throwables.h | 1 | ||||
| -rw-r--r-- | src/asset_defs.c | 5 | ||||
| -rw-r--r-- | src/audio.c | 35 | ||||
| -rw-r--r-- | src/bullets.c | 19 | ||||
| -rw-r--r-- | src/throwables.c | 10 |
16 files changed, 58 insertions, 30 deletions
diff --git a/.vscode/settings.json b/.vscode/settings.json deleted file mode 100644 index 6386813..0000000 --- a/.vscode/settings.json +++ /dev/null @@ -1,6 +0,0 @@ -{ - "files.associations": { - "*.ejs": "html", - "sprite.h": "c" - } -}
\ No newline at end of file diff --git a/build/data/imgs/grenade.png b/build/data/imgs/grenade.png Binary files differnew file mode 100644 index 0000000..320b29b --- /dev/null +++ b/build/data/imgs/grenade.png diff --git a/build/data/sounds/error.wav b/build/data/sounds/error.wav Binary files differnew file mode 100644 index 0000000..e633d40 --- /dev/null +++ b/build/data/sounds/error.wav diff --git a/build/data/sounds/impact_wood.wav b/build/data/sounds/impact_wood.wav Binary files differnew file mode 100644 index 0000000..5ddeafc --- /dev/null +++ b/build/data/sounds/impact_wood.wav diff --git a/build/zombies.exe b/build/zombies.exe Binary files differindex 214f186..b02bfb7 100644 --- a/build/zombies.exe +++ b/build/zombies.exe diff --git a/data/imgs/grenade.png b/data/imgs/grenade.png Binary files differnew file mode 100644 index 0000000..320b29b --- /dev/null +++ b/data/imgs/grenade.png diff --git a/data/sounds/error.wav b/data/sounds/error.wav Binary files differnew file mode 100644 index 0000000..e633d40 --- /dev/null +++ b/data/sounds/error.wav diff --git a/data/sounds/impact_wood.wav b/data/sounds/impact_wood.wav Binary files differnew file mode 100644 index 0000000..5ddeafc --- /dev/null +++ b/data/sounds/impact_wood.wav diff --git a/include/asset_defs.h b/include/asset_defs.h index 27c31e4..63f46bd 100644 --- a/include/asset_defs.h +++ b/include/asset_defs.h @@ -22,6 +22,9 @@ image* img_spawner; image* img_obj_plants; image* img_obj_wall1; +// Throwables +image* img_grenade; + // Players image* img_player; @@ -39,6 +42,10 @@ Mix_Chunk* wav_throwable_bounce; Mix_Chunk* wav_shoot_mp5; Mix_Chunk* wav_reload_mp5; +Mix_Chunk* wav_impact_wood; +Mix_Chunk* wav_error; + + void load_assets(); #endif
\ No newline at end of file diff --git a/include/audio.h b/include/audio.h index b4657d7..47cd10e 100644 --- a/include/audio.h +++ b/include/audio.h @@ -5,11 +5,13 @@ #define CHANNEL_THROWABLES 0 #define CHANNEL_SHOOTING 1 +#define CHANNEL_IMPACT 2 typedef enum t_audio_event_type { EVENT_SHOOT, EVENT_RELOAD, EVENT_BOUNCE_THROWABLE, + EVENT_IMPACT, } audio_event_type; typedef struct t_audio_event { @@ -17,12 +19,14 @@ typedef struct t_audio_event { audio_event_type type; u32 playerid; vec3f position; + object_type obj; } audio_event; #define MAX_AUDIO_EVENTS 20 audio_event audio_events[MAX_AUDIO_EVENTS] = {0}; int max_audio_events = MAX_AUDIO_EVENTS; +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); void play_sounds_in_queue(); void clear_sounds_in_queue(); diff --git a/include/objects.h b/include/objects.h index e742f1e..29e6db0 100644 --- a/include/objects.h +++ b/include/objects.h @@ -19,6 +19,7 @@ typedef struct t_light_emitter { } light_emitter; typedef enum t_object_type { + OBJECT_NONE = 0, OBJECT_COBBLESTONEWALL1 = 1, OBJECT_PLANTBOX1 = 2, } object_type; diff --git a/include/throwables.h b/include/throwables.h index f4507b6..16811b2 100644 --- a/include/throwables.h +++ b/include/throwables.h @@ -10,6 +10,7 @@ typedef enum t_throwable_type { + THROWABLE_NONE = 0, THROWABLE_GRENADE, } throwable_type; 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 |
