summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAldrik Ramaekers <aldrik@amftech.nl>2023-10-29 08:26:31 +0100
committerAldrik Ramaekers <aldrik@amftech.nl>2023-10-29 08:26:31 +0100
commitd2c3f612b3d7b0071e98e589777d495ba45eafe4 (patch)
treee3084f2ac5ea942c41cb2878263a397b1eaa1b56
parentf2522c04446bb4bd597a8625f9398e67ff957565 (diff)
more sounds
-rw-r--r--build/data/sounds/reload_nova.wavbin0 -> 92152 bytes
-rw-r--r--build/data/sounds/shoot_nova.wavbin0 -> 237008 bytes
-rw-r--r--build/zombies.exebin1981936 -> 1983269 bytes
-rw-r--r--data/sounds/reload_nova.wavbin0 -> 92152 bytes
-rw-r--r--data/sounds/shoot_nova.wavbin0 -> 237008 bytes
-rw-r--r--include/asset_defs.h3
-rw-r--r--include/audio.h3
-rw-r--r--include/game.h1
-rw-r--r--main.c14
-rw-r--r--src/asset_defs.c2
-rw-r--r--src/audio.c8
-rw-r--r--src/bullets.c13
-rw-r--r--src/game.c8
13 files changed, 37 insertions, 15 deletions
diff --git a/build/data/sounds/reload_nova.wav b/build/data/sounds/reload_nova.wav
new file mode 100644
index 0000000..364b9d2
--- /dev/null
+++ b/build/data/sounds/reload_nova.wav
Binary files differ
diff --git a/build/data/sounds/shoot_nova.wav b/build/data/sounds/shoot_nova.wav
new file mode 100644
index 0000000..b38e096
--- /dev/null
+++ b/build/data/sounds/shoot_nova.wav
Binary files differ
diff --git a/build/zombies.exe b/build/zombies.exe
index dc93d54..07251d2 100644
--- a/build/zombies.exe
+++ b/build/zombies.exe
Binary files differ
diff --git a/data/sounds/reload_nova.wav b/data/sounds/reload_nova.wav
new file mode 100644
index 0000000..364b9d2
--- /dev/null
+++ b/data/sounds/reload_nova.wav
Binary files differ
diff --git a/data/sounds/shoot_nova.wav b/data/sounds/shoot_nova.wav
new file mode 100644
index 0000000..b38e096
--- /dev/null
+++ b/data/sounds/shoot_nova.wav
Binary files differ
diff --git a/include/asset_defs.h b/include/asset_defs.h
index acca89e..7237a6d 100644
--- a/include/asset_defs.h
+++ b/include/asset_defs.h
@@ -42,6 +42,9 @@ Mix_Chunk* wav_throwable_bounce;
Mix_Chunk* wav_shoot_mp5;
Mix_Chunk* wav_reload_mp5;
+Mix_Chunk* wav_shoot_nova;
+Mix_Chunk* wav_reload_nova;
+
Mix_Chunk* wav_impact_zombie;
Mix_Chunk* wav_impact_wood;
Mix_Chunk* wav_error;
diff --git a/include/audio.h b/include/audio.h
index 38543dd..c7cb9c7 100644
--- a/include/audio.h
+++ b/include/audio.h
@@ -3,9 +3,12 @@
#include <projectbase/project_base.h>
+#define NUMBER_OF_AUDIO_CHANNELS 64
+
#define CHANNEL_THROWABLES 0
#define CHANNEL_SHOOTING 1
#define CHANNEL_IMPACT 2
+#define CHANNEL_RELOAD 3
typedef enum t_audio_event_type {
EVENT_SHOOT,
diff --git a/include/game.h b/include/game.h
index f2fd0cb..03fbf11 100644
--- a/include/game.h
+++ b/include/game.h
@@ -14,6 +14,7 @@
typedef enum t_game_state {
GAMESTATE_IDLE,
GAMESTATE_LOADING_MAP,
+ GAMESTATE_LOADING_ASSETS,
GAMESTATE_PLAYING,
} game_state;
diff --git a/main.c b/main.c
index ef9d26e..87ac283 100644
--- a/main.c
+++ b/main.c
@@ -77,6 +77,9 @@ void handle_args(int argc, char **argv) {
}
connect_to_server(ip, port);
}
+
+ log_info("STATE: GAMESTATE_PLAYING");
+ global_state.state = GAMESTATE_PLAYING;
}
int main(int argc, char **argv)
@@ -91,8 +94,13 @@ int main(int argc, char **argv)
settings_set_number("USE_GPU", 1);
if (Mix_OpenAudio(48000, AUDIO_F32SYS, 2, 2048) == 0) {
- log_info("Audio system initialized.");
- Mix_MasterVolume(MIX_MAX_VOLUME/4);
+ if (Mix_AllocateChannels(NUMBER_OF_AUDIO_CHANNELS) == 64) {
+ log_info("Audio system initialized.");
+ Mix_MasterVolume(MIX_MAX_VOLUME/4);
+ }
+ else {
+ log_info("Channel allocation failed.");
+ }
}
else {
log_info("Audio failed.");
@@ -102,7 +110,7 @@ int main(int argc, char **argv)
bool did_handle_args = false;
while(platform_keep_running(window)) {
- if (global_asset_collection.done_loading_assets && !did_handle_args) {
+ if (global_asset_collection.done_loading_assets && !did_handle_args && global_state.state == GAMESTATE_LOADING_ASSETS) {
handle_args(argc, argv);
did_handle_args = true;
}
diff --git a/src/asset_defs.c b/src/asset_defs.c
index a83ad96..ee8dced 100644
--- a/src/asset_defs.c
+++ b/src/asset_defs.c
@@ -39,6 +39,8 @@ 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_shoot_nova = Mix_LoadWAV("data/sounds/shoot_nova.wav");
+ wav_reload_nova = Mix_LoadWAV("data/sounds/reload_nova.wav");
wav_impact_wood = Mix_LoadWAV("data/sounds/impact_wood.wav");
wav_error = Mix_LoadWAV("data/sounds/error.wav");
wav_impact_zombie = Mix_LoadWAV("data/sounds/impact_zombie.wav");
diff --git a/src/audio.c b/src/audio.c
index b174610..c6f69b9 100644
--- a/src/audio.c
+++ b/src/audio.c
@@ -26,8 +26,8 @@ static int get_channel_from_audio_event_type(audio_event_type event) {
switch (event)
{
case EVENT_BOUNCE_THROWABLE: return CHANNEL_THROWABLES;
- case EVENT_SHOOT:
- case EVENT_RELOAD: return CHANNEL_SHOOTING;
+ case EVENT_SHOOT: return CHANNEL_SHOOTING;
+ case EVENT_RELOAD: return CHANNEL_RELOAD;
case EVENT_IMPACT: return CHANNEL_IMPACT;
default: return 0;
@@ -45,13 +45,15 @@ static Mix_Chunk* get_sample_from_audio_event(audio_event event, u32 playerid) {
switch (p->guntype)
{
case GUN_MP5: return wav_shoot_mp5;
+ case GUN_NOVA: return wav_shoot_nova;
default: return wav_error;
}
}
case EVENT_RELOAD: {
switch (p->guntype)
{
- case GUN_MP5: return wav_reload_mp5;
+ case GUN_MP5: return wav_reload_mp5;
+ case GUN_NOVA: return wav_reload_nova;
default: return wav_error;
}
}
diff --git a/src/bullets.c b/src/bullets.c
index f7f033d..403b1b6 100644
--- a/src/bullets.c
+++ b/src/bullets.c
@@ -20,12 +20,6 @@ void shoot(platform_window* window, u32 id, float dirx, float diry) {
int bullets_to_shoot = g.bullets_per_shot;
if (bullets_to_shoot > p->ammo_in_mag) bullets_to_shoot = p->ammo_in_mag;
p->ammo_in_mag -= bullets_to_shoot;
- if (p->ammo_in_mag == 0) {
- add_audio_event_to_queue(EVENT_RELOAD, p->id, (vec3f){.x = p->playerx, .y = p->playery, .z = p->height});
- p->interact_state = INTERACT_RELOADING;
- p->sec_since_interact_state_change = 0;
- return;
- }
add_audio_event_to_queue(EVENT_SHOOT, p->id, (vec3f){.x = p->playerx, .y = p->playery, .z = p->height});
@@ -50,6 +44,13 @@ void shoot(platform_window* window, u32 id, float dirx, float diry) {
break;
}
}
+
+ if (p->ammo_in_mag == 0) {
+ add_audio_event_to_queue(EVENT_RELOAD, p->id, (vec3f){.x = p->playerx, .y = p->playery, .z = p->height});
+ p->interact_state = INTERACT_RELOADING;
+ p->sec_since_interact_state_change = 0;
+ return;
+ }
}
bool check_if_bullet_collided_with_section(float* dist_of_closest_intersect, vec2f bstart, vec2f bend, vec2f l1, vec2f l2, vec2f* intersect_point_buf) {
diff --git a/src/game.c b/src/game.c
index a9a91c1..ec1d3cd 100644
--- a/src/game.c
+++ b/src/game.c
@@ -52,6 +52,7 @@ void connect_to_server(char* ip, char* port) {
}
void load_map() {
+ log_info("STATE: GAMESTATE_LOADING_MAP");
global_state.state = GAMESTATE_LOADING_MAP;
outgoing_allocator = create_allocator(MAX_NETWORK_BUFFER_SIZE);
@@ -71,12 +72,13 @@ void load_map() {
thread t = thread_start(pathfinding_thread, 0);
thread_detach(&t);
- global_state.state = GAMESTATE_PLAYING;
- log_info("Done loading map");
+ log_info("STATE: GAMESTATE_LOADING_ASSETS");
+ global_state.state = GAMESTATE_LOADING_ASSETS;
}
void init_game() {
- global_state.state = IDLE;
+ log_info("STATE: GAMESTATE_IDLE");
+ global_state.state = GAMESTATE_IDLE;
global_state.network_state = DISCONNECTED;
load_assets();