From 3c1a224d37eae97de7d1562ab280343352f925fe Mon Sep 17 00:00:00 2001 From: "Juan J. Martinez" Date: Sat, 29 Jul 2023 12:57:54 +0100 Subject: Music WIP --- data/music.it | Bin 81629 -> 289255 bytes src/game.c | 42 +++++++++++++++++++++++++++++++++++------- src/sound.h | 7 +++++++ 3 files changed, 42 insertions(+), 7 deletions(-) diff --git a/data/music.it b/data/music.it index 373a4e1..8d38016 100644 Binary files a/data/music.it and b/data/music.it differ diff --git a/src/game.c b/src/game.c index eed6749..d440cb8 100644 --- a/src/game.c +++ b/src/game.c @@ -32,7 +32,7 @@ #define HUD_ALL 255 #define GAMEOVER_DELAY 96 -#define STAGECLEAR_DELAY 96 +#define STAGECLEAR_DELAY 64 static uint32_t hiscore = 15000; @@ -159,6 +159,10 @@ static void run_intro() wait_frames(32); + sound_music_pattern(PAT_INTRO); + /* so the music starts */ + wait_vsync(); + blit_target(TARGET_SCREEN); while (dst.x < 224) { @@ -181,6 +185,8 @@ static void run_intro() wait_vsync(); blit_copy16(&dst); + wait_frames(32); + sound_music_pattern(PAT_SILENCE); wait_frames(64); } @@ -196,18 +202,24 @@ static uint8_t run_gameover() put_text(124, 90, "GAME OVER", 1); + sound_music_pattern(PAT_GAMEOVER); + /* wait some time, and check if the player wants to continue */ - for (uint16_t i = 0; i < 364; i++) + for (uint16_t i = 0; i < 524; i++) { - if (i == 64 || i == 300) - put_text(68, 105, "PRESS SPACE TO CONTINUE", i == 64 ? 5 : 0); + if (i == 200 || i == 400) + put_text(68, 105, "PRESS SPACE TO CONTINUE", i == 200 ? 5 : 0); - if (i > 64 && i < 300 && keys[KEY_SPACE]) + if (i > 200 && i < 400 && keys[KEY_SPACE]) + { + sound_music_pattern(PAT_SILENCE); return 1; + } wait_vsync(); } + sound_music_pattern(PAT_SILENCE); return 0; } @@ -217,8 +229,10 @@ static void run_stageclear() put_text(116, 100, "STAGE", 1); put_text(164, 100, "CLEAR", 1); + sound_music_pattern(PAT_STAGE); + /* wait some time */ - wait_frames(96); + wait_frames(164); while (time) { @@ -292,8 +306,10 @@ next_stage: entities_draw(); put_text(136, 100, "READY?", 1); + sound_music_pattern(PAT_READY); + /* wait some time */ - wait_frames(96); + wait_frames(128); /* erase the READY? text */ Rect ready = { 136, 100, 184, 8 }; @@ -303,6 +319,8 @@ next_stage: timer_start(GAME_TIME_MAX, &clock_updated); + sound_music_pattern(PAT_PLAY); + while (!keys[KEY_ESC]) { if (clock_updated) @@ -346,9 +364,14 @@ next_stage: } else { + if (stageclear == STAGECLEAR_DELAY) + sound_music_pattern(PAT_SILENCE); + stageclear--; if (stageclear == 1) { + sound_music_pattern(PAT_SILENCE); + run_stageclear(); stage++; if (stage == STAGES_LEN) @@ -391,6 +414,9 @@ next_stage: if (gameover) { + if (gameover == GAMEOVER_DELAY) + sound_music_pattern(PAT_SILENCE); + gameover--; if (gameover == 1) { @@ -404,6 +430,8 @@ next_stage: } } + sound_music_pattern(PAT_SILENCE); + /* wait for ESC to be release */ while (keys[KEY_ESC]) wait_vsync(); diff --git a/src/sound.h b/src/sound.h index 5f96d29..2446b68 100644 --- a/src/sound.h +++ b/src/sound.h @@ -12,6 +12,13 @@ enum { EFX_DEATH, }; +#define PAT_SILENCE 0 +#define PAT_INTRO 1 +#define PAT_READY 2 +#define PAT_STAGE 3 +#define PAT_GAMEOVER 4 +#define PAT_PLAY 5 + uint8_t sound_init(uint8_t nosound); void sound_free(); void sound_update(); -- cgit v1.2.3