Heliothryx game update

- added background music in menu



git-svn-id: svn://kolibrios.org@5302 a494cfbc-eb01-0410-851d-a64ba20cac60
This commit is contained in:
alpine 2014-12-30 22:47:04 +00:00
parent 02ccb0c644
commit 945c8f3a43
6 changed files with 143 additions and 19 deletions

View File

@ -238,14 +238,18 @@ void soundbuf_sin_fade(rs_soundbuf_t *snd, float freq) {
rskos_snd_update_buffer(&snd->hbuf, snd->data, snd->length_samples);
};
void soundbuf_play(rs_soundbuf_t *snd) {
rskos_snd_play(&snd->hbuf, 0);
void soundbuf_play(rs_soundbuf_t *snd, int mode) {
rskos_snd_play(&snd->hbuf, mode);
};
void soundbuf_stop(rs_soundbuf_t *snd) {
rskos_snd_stop(&snd->hbuf);
};
void soundbuf_loop_check(rs_soundbuf_t *snd) {
rskos_snd_check_loop(&snd->hbuf);
};
unsigned char clamp_byte(int value) {
@ -510,7 +514,7 @@ void GameInit() {
#ifndef RS_KOS
rs_audio_init(RS_AUDIO_FMT_MONO16, RS_AUDIO_FREQ_16000, 0);
rs_audio_init(RS_AUDIO_FMT_MONO16, RS_AUDIO_FREQ_16000, 2);
#endif
soundbuf_init(&game.sound_test1, 2048);
@ -545,7 +549,7 @@ void GameInit() {
rs_sgen_func_normalize(0, 1.0);
rs_sgen_func_lowpass(2, 0, 0.6, 0.0, 20.0);
rs_sgen_func_normalize(2, 1.0);
rs_sgen_func_normalize(2, 0.7);
rs_sgen_wave_out(2);
@ -567,7 +571,7 @@ void GameInit() {
rs_sgen_func_normalize(0, 1.0);
rs_sgen_func_highpass(2, 0, 1.0, 0.3, 20.0);
rs_sgen_func_normalize(2, 1.0);
rs_sgen_func_normalize(2, 0.6);
rs_sgen_wave_out(2);
@ -575,6 +579,74 @@ void GameInit() {
soundbuf_update(&game.sound_hit);
rs_sgen_term();
#define NOTE(i) ( 3 << ( (i)/12) ) / ( 24 - ( (i) % 12) )
int amp = 70;
int t_shift = 0;
int t;
soundlen = 128 * 1024;
soundbuf_init(&game.sound_music, soundlen);
for (t = t_shift; t < soundlen+t_shift; t++) {
game.sound_music.data[t-t_shift] = (0xFF &
(
((t>>11) | (t>>7) | ( t>>5) | (t))
)
) * amp;
};
soundbuf_update(&game.sound_music);
int d[4] = { 5, 6, 1, 2 };
soundbuf_init(&game.sound_music2, soundlen);
for (t = t_shift; t < soundlen+t_shift; t++) {
// y = 1 + (t & 16383);
// x = (t * c[ (t>>13) & 3 ] / 24) & 127;
game.sound_music2.data[t-t_shift] = (0xFF &
(
//( t*5 & t >> 7 ) | ( t*2 & t >> 10 )
// ( ((t*t*t/1000000 + t) % 127) | t>>4 | t>>5 | (t%127) ) + ( (t>>16) | t )
// ((t>>11) | (t>>7) | ( t>>5) | (t))
// //+
// //(( (t*5) >>12) & ( (t*3)>>19))
// (3000 / y) * 35
// + x*y*40000
// + ( ( ((t>>8) & (t>>10)) | (t >> 14) | x) & 63 )
// ( ((6 * t / d[ (t>>13) & 15 ] ) & 127) * 10000 )
//|( ( t>>3 ) )
(t*NOTE( d[ (t>>13) & 3 ] )*10000)
| ((t>>6)*20000)
)
) * amp;
};
soundbuf_update(&game.sound_music2);
soundbuf_play( &game.sound_music, SND_MODE_LOOP );
};
@ -639,7 +711,27 @@ void GameKeyDown(int key) {
case RS_KEY_A:
BIT_SET(game.keyboard_state, RS_ATTACK_KEY_MASK);
game.shoot_keypressed = 1;
// soundbuf_loop_check( &game.sound_music );
break;
// case RS_KEY_SPACE:
// soundbuf_play( &game.sound_music, SND_MODE_LOOP );
// break;
// #ifdef RS_LINUX
//
// case RS_KEY_Z:
// soundbuf_play( &game.sound_music2, 0 );
// break;
//
// #endif
};
@ -694,11 +786,6 @@ void GameKeyDown(int key) {
break;
case RS_KEY_SPACE:
#ifdef RS_LINUX
soundbuf_play( &game.sound_hit );
#endif
//game_obj_add( game_obj( OBJ_EXPLOSION, 0, 0, 0, game.tx + 80, game.ty - 10, 0, 0.0 ) );
@ -782,10 +869,10 @@ void game_ding(int i) {
switch (i) {
case 0:
soundbuf_play(&game.sound_test2);
soundbuf_play(&game.sound_test2, 0);
break;
case 1:
soundbuf_play(&game.sound_test3);
soundbuf_play(&game.sound_test3, 0);
break;
};

View File

@ -95,7 +95,8 @@ void soundbuf_free(rs_soundbuf_t *snd);
void soundbuf_fill(rs_soundbuf_t *snd, int amp, int freq_div);
void soundbuf_sin(rs_soundbuf_t *snd, float freq);
void soundbuf_sin_fade(rs_soundbuf_t *snd, float freq);
void soundbuf_play(rs_soundbuf_t *snd);
void soundbuf_play(rs_soundbuf_t *snd, int mode);
void soundbuf_loop_check(rs_soundbuf_t *snd);
void soundbuf_stop(rs_soundbuf_t *snd);
// Game Objects
@ -194,6 +195,9 @@ typedef struct rs_game_t {
rs_soundbuf_t sound_explosions[SOUND_EXPLOSIONS_COUNT];
rs_soundbuf_t sound_hit;
rs_soundbuf_t sound_music;
rs_soundbuf_t sound_music2;
int status;
int flags;

View File

@ -90,11 +90,12 @@ void player_hit() {
game.health--;
game.bg_color = COLOR_DARK_RED;
soundbuf_play( &game.sound_hit );
soundbuf_play( &game.sound_hit, 0 );
if (game.health < 1) {
game.status = STATUS_MENU;
soundbuf_play( &game.sound_music, SND_MODE_LOOP );
menu_open( MENU_GAME_OVER );
};
@ -117,7 +118,7 @@ void GameProcess() {
game.shoot_restore_delay = 0;
game.ammo--;
soundbuf_play(&game.sound_test1);
soundbuf_play(&game.sound_test1, 0);
game_obj_add( game_obj( OBJ_BULLET, 0, 0, 0, game.player_x+5, game.player_y, 0, 0.0) );
// };
@ -275,6 +276,7 @@ void GameProcess() {
else if (game.stage == 10) {
game.status = STATUS_MENU;
soundbuf_play( &game.sound_music, SND_MODE_LOOP );
menu_open( MENU_LEVEL_PASSED );
level_passed_score_str[1] = '0' + (game.score / 100) % 10;
@ -403,7 +405,7 @@ void GameProcess() {
for (i = 0; i < game.objs_count; i++) {
if ( IS_BIT_SET( game.objs[i].flags, OBJ_FLAG_DESTROYED ) ) {
soundbuf_play( &game.sound_explosions[ rs_rand() % SOUND_EXPLOSIONS_COUNT ] );
soundbuf_play( &game.sound_explosions[ rs_rand() % SOUND_EXPLOSIONS_COUNT ], 0 );
game_obj_add( game_obj( OBJ_EXPLOSION, 0, 0, EXPLOSION_RADIUS, game.objs[i].x, game.objs[i].y, 0, 0.0 ) );
game_obj_remove(i);
i--;
@ -416,6 +418,10 @@ void GameProcess() {
};
game_draw();
if (game.status == STATUS_MENU) {
soundbuf_loop_check( &game.sound_music );
};
}

View File

@ -104,7 +104,7 @@ void menu_cursor_up() {
};
void menu_open(int i) {
game.menu_index = i;
game.menu_item_index = -1;
@ -162,6 +162,8 @@ void menu_action_start() {
game.bg_color = COLOR_BLACK;
soundbuf_stop( &game.sound_music );
};
void menu_action_exit() {

View File

@ -132,7 +132,8 @@ void rskos_snd_update_buffer(SNDBUF *hbuf, signed short *buffer, unsigned int le
void rskos_snd_play(SNDBUF *hbuf, unsigned int mode) {
rs_sound_play(*hbuf);
// rs_sound_play(*hbuf);
rs_sound_play_adv(*hbuf, mode==SND_MODE_LOOP ? 1 : 0, mode==SND_MODE_LOOP ? 0 : -1, 1.0);
};
@ -140,6 +141,10 @@ void rskos_snd_stop(SNDBUF *hbuf) {
rs_sound_stop(*hbuf);
};
void rskos_snd_check_loop(SNDBUF *phbuf) {
//
};
#else
@ -208,12 +213,29 @@ void rskos_snd_stop(SNDBUF *hbuf) {
void rskos_snd_play(SNDBUF *phbuf, unsigned int mode) {
SetBufferPos(*phbuf, 0);
PlayBuffer(*phbuf, 0);
PlayBuffer(*phbuf, 0); // SND_MODE_LOOP
};
void rskos_snd_stop(SNDBUF *phbuf) {
StopBuffer(*phbuf);
};
void rskos_snd_check_loop(SNDBUF *phbuf) {
int offset;
int length;
GetBufferPos(*phbuf, &offset);
//GetBufferSize(*phbuf, &length);
// kol_board_puti(offset);
//kol_board_putc('\n');
if (offset <= 0) {
SetBufferPos(*phbuf, 0); //offset - length/2);
PlayBuffer(*phbuf, 0); // SND_MODE_LOOP
};
};

View File

@ -24,10 +24,13 @@ void rskos_exit();
#endif
#endif
#define SND_MODE_LOOP 1
//void rskos_snd_init();
void rskos_snd_create_buffer(SNDBUF *phbuf, signed short *buffer, unsigned int length_samples);
void rskos_snd_update_buffer(SNDBUF *phbuf, signed short *buffer, unsigned int length_samples);
void rskos_snd_play(SNDBUF *phbuf, unsigned int mode);
void rskos_snd_stop(SNDBUF *phbuf);
void rskos_snd_check_loop(SNDBUF *phbuf);
#endif