From a2cfd98d122462bf8d9080cf09601c128be37430 Mon Sep 17 00:00:00 2001 From: alpine Date: Tue, 30 Dec 2014 18:04:09 +0000 Subject: [PATCH] Heliothryx game update - added some sounds - added visual damage effect on player hit git-svn-id: svn://kolibrios.org@5298 a494cfbc-eb01-0410-851d-a64ba20cac60 --- programs/games/heliothryx/Tupfile.lua | 4 +- .../games/heliothryx/game/rs/rsplatform_kos.c | 4 +- programs/games/heliothryx/game/rsgame.c | 63 ++++++++++++++++++- programs/games/heliothryx/game/rsgame.h | 39 +++++++----- programs/games/heliothryx/game/rsgamedraw.c | 5 +- programs/games/heliothryx/game/rsgamelogic.c | 4 ++ programs/games/heliothryx/game/rsgamemenu.c | 2 + 7 files changed, 100 insertions(+), 21 deletions(-) diff --git a/programs/games/heliothryx/Tupfile.lua b/programs/games/heliothryx/Tupfile.lua index 38b5ba3aed..1232c6b582 100644 --- a/programs/games/heliothryx/Tupfile.lua +++ b/programs/games/heliothryx/Tupfile.lua @@ -15,7 +15,7 @@ then C_LANG = "LANG_SP" -- just for example, other languages are not implemented else C_LANG = "LANG_EN" -- default language is English end -CFLAGS = CFLAGS .. " -DRS_KOS -D" .. C_LANG .. " " +CFLAGS = CFLAGS .. " -Werror=implicit -DRS_KOS -D" .. C_LANG .. " " -compile_gcc{ "system/kolibri.c", "game/rs/rsmicrolibc.c", "game/rs/rsplatform_kos.c", "game/rs/rsmx.c", "game/rsnoise.c", "game/rsgentex.c", "game/rsgame.c", "game/rsgamedraw.c", "game/rsgamelogic.c", "game/rskos.c", "game/rsgametext.c", "game/rsgamemenu.c"} +compile_gcc{ "system/kolibri.c", "game/rs/rsmicrolibc.c", "game/rs/rsplatform_kos.c", "game/rs/rsmx.c", "game/rsnoise.c", "game/rsgentex.c", "game/rssoundgen.c", "game/rsgame.c", "game/rsgamedraw.c", "game/rsgamelogic.c", "game/rskos.c", "game/rsgametext.c", "game/rsgamemenu.c"} link_gcc ("heliothryx") diff --git a/programs/games/heliothryx/game/rs/rsplatform_kos.c b/programs/games/heliothryx/game/rs/rsplatform_kos.c index d856ab051b..4bd57960dc 100644 --- a/programs/games/heliothryx/game/rs/rsplatform_kos.c +++ b/programs/games/heliothryx/game/rs/rsplatform_kos.c @@ -1,4 +1,6 @@ #include "rsplatform.h" + +#include "../rsgame.h" rs_app_t rs_app; @@ -186,7 +188,7 @@ void kol_main() if (!logic_halted) { if (key_up) { - GameKeyUp(key, 1); + GameKeyUp(key); } else { GameKeyDown(key); diff --git a/programs/games/heliothryx/game/rsgame.c b/programs/games/heliothryx/game/rsgame.c index 1f88636137..3bd8bda51c 100755 --- a/programs/games/heliothryx/game/rsgame.c +++ b/programs/games/heliothryx/game/rsgame.c @@ -185,6 +185,10 @@ void soundbuf_init(rs_soundbuf_t *snd, int length_samples) { rskos_snd_create_buffer(&snd->hbuf, snd->data, length_samples); }; +void soundbuf_update(rs_soundbuf_t *snd) { + rskos_snd_update_buffer(&snd->hbuf, snd->data, snd->length_samples); +}; + void soundbuf_free(rs_soundbuf_t *snd) { snd->status = 0; free(snd->data); @@ -258,6 +262,8 @@ void game_reg_init() { game.player_x = 0; game.player_y = 0; game.tz = 0; + + game.bg_color = COLOR_BLACK; // int i; // for (i = 0; i < BULLETS_COUNT; i++) { @@ -520,6 +526,56 @@ void GameInit() { soundbuf_sin(&game.sound_test3, 0.24); + + + + int soundlen = 55000; + +// int freqs[SOUND_EXPLOSIONS_COUNT] = { 440, 523, 587, 698, 783, 880, 1046, 1174 }; + + for (i = 0; i < SOUND_EXPLOSIONS_COUNT; i++) { + + soundbuf_init(&game.sound_explosions[i], soundlen); + + rs_sgen_init(3, soundlen); + + rs_sgen_func_noise(2, 1000); + //rs_sgen_func_phaser(0, 2, 0.9, 15.2 + 1.0*i/SOUND_EXPLOSIONS_COUNT, 6.0, 3.0, 2000.0, 1.73); + rs_sgen_func_phaser(0, 2, 0.9, 16.2 + 0.5*i/SOUND_EXPLOSIONS_COUNT, 6.0, 3.0, 900.0, 0.93); + 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_wave_out(2); + + memcpy(game.sound_explosions[i].data, (unsigned char*) rs_sgen_reg.wave_out, soundlen*2); + soundbuf_update(&game.sound_explosions[i]); + + rs_sgen_term(); + + }; + + soundlen = 17888; + + soundbuf_init(&game.sound_hit, soundlen); + + rs_sgen_init(3, soundlen); + + rs_sgen_func_noise(2, 1000); + rs_sgen_func_phaser(0, 2, 0.9, 11.5, 16.0, 13.0, 1300.0, 1.93); + 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_wave_out(2); + + memcpy(game.sound_hit.data, (unsigned char*) rs_sgen_reg.wave_out, soundlen*2); + soundbuf_update(&game.sound_hit); + + rs_sgen_term(); + }; @@ -564,7 +620,7 @@ void GameTerm() { -void GameKeyDown(int key, int first) { +void GameKeyDown(int key) { switch (key) { @@ -639,8 +695,9 @@ void GameKeyDown(int key, int first) { case RS_KEY_SPACE: #ifdef RS_LINUX - game.stage_timer = 0; - game.stage = 7; + + 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 ) ); diff --git a/programs/games/heliothryx/game/rsgame.h b/programs/games/heliothryx/game/rsgame.h index d51dc157a1..4e389778d5 100755 --- a/programs/games/heliothryx/game/rsgame.h +++ b/programs/games/heliothryx/game/rsgame.h @@ -19,22 +19,12 @@ #include "rskos.h" #include "rs/rsplatform.h" -//#include "rs/rstexture.h" -//#include "rs/rsshader.h" -//#include "rs/rsgl.h" + #include "rs/rsdebug.h" #include "rs/rsbits.h" -//#include "rs/rskeyboard.h" +#include "rsgamelogic.h" -//#include "rs/rsaudio.h" - -//#include "rs/rsfile.h" - -//#include "rs/rsvbo.h" -//#include "rs/rsfbo.h" - -//#include "rs/rsthread.h" #include "rs/rsmx.h" @@ -70,7 +60,7 @@ typedef union color_t { // for little-endian (ARGB) #define COLOR_BLACK 0xFF000000 #define COLOR_TRANSPARENT 0x00000000 -#define COLOR_DARK_RED 0xFF660000 +#define COLOR_DARK_RED 0xFF401000 @@ -174,6 +164,8 @@ void game_obj_remove(int index); #define GAME_FLAG_BOSS_DESTROYED 0x01 +#define SOUND_EXPLOSIONS_COUNT 8 + typedef struct rs_game_t { rs_texture_t framebuffer; unsigned char *scaled_framebuffer; // 24-bit BGRBGRBGR... for direct drawing @@ -193,11 +185,15 @@ typedef struct rs_game_t { rs_texture_t tex_gui_line; + int bg_color; rs_soundbuf_t sound_test1; rs_soundbuf_t sound_test2; rs_soundbuf_t sound_test3; + rs_soundbuf_t sound_explosions[SOUND_EXPLOSIONS_COUNT]; + rs_soundbuf_t sound_hit; + int status; int flags; @@ -243,6 +239,14 @@ typedef struct rs_game_t { extern rs_game_t game; void game_reg_init(); + + + + + + + + /* __ /cc\ /aaaa\ @@ -251,12 +255,19 @@ void game_reg_init(); ------------------------------- */ + + + + + + + void game_ding(int i); void GameInit(); void GameTerm(); -void GameKeyDown(int key, int first); +void GameKeyDown(int key); void GameKeyUp(int key); void GameMouseDown(int x, int y); diff --git a/programs/games/heliothryx/game/rsgamedraw.c b/programs/games/heliothryx/game/rsgamedraw.c index 3ac8cb72b1..b491493e71 100755 --- a/programs/games/heliothryx/game/rsgamedraw.c +++ b/programs/games/heliothryx/game/rsgamedraw.c @@ -28,7 +28,10 @@ void game_draw() { // }; - texture_clear(&game.framebuffer, COLOR_BLACK); + texture_clear(&game.framebuffer, game.bg_color ); + + game.bg_color = COLOR_BLACK; + // texture_clear(&game.tex); // texture_draw(&game.framebuffer, &game.tex, 40, 40, DRAW_MODE_ADDITIVE); diff --git a/programs/games/heliothryx/game/rsgamelogic.c b/programs/games/heliothryx/game/rsgamelogic.c index 36b2bcb0b0..8fce149645 100644 --- a/programs/games/heliothryx/game/rsgamelogic.c +++ b/programs/games/heliothryx/game/rsgamelogic.c @@ -88,6 +88,9 @@ int check_collision_with_player(int obj1) { void player_hit() { game.health--; + game.bg_color = COLOR_DARK_RED; + + soundbuf_play( &game.sound_hit ); if (game.health < 1) { @@ -400,6 +403,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 ] ); 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--; diff --git a/programs/games/heliothryx/game/rsgamemenu.c b/programs/games/heliothryx/game/rsgamemenu.c index 977055bcd0..a824dd2011 100644 --- a/programs/games/heliothryx/game/rsgamemenu.c +++ b/programs/games/heliothryx/game/rsgamemenu.c @@ -160,6 +160,8 @@ void menu_action_start() { game.objs_count = 0; + game.bg_color = COLOR_BLACK; + }; void menu_action_exit() {