From 93fccad3ca512626c590eb3a01e89628a3f12543 Mon Sep 17 00:00:00 2001 From: alpine Date: Tue, 23 Dec 2014 15:39:58 +0000 Subject: [PATCH] Marble Match-3 Game update: - added saving highscores git-svn-id: svn://kolibrios.org@5260 a494cfbc-eb01-0410-851d-a64ba20cac60 --- programs/games/marblematch3/game/rsgame.c | 21 +++- programs/games/marblematch3/game/rsgame.h | 8 ++ programs/games/marblematch3/game/rsgamedraw.c | 31 ++++- programs/games/marblematch3/game/rskos.c | 115 ++++++++++++++++++ programs/games/marblematch3/game/rskos.h | 5 + programs/games/marblematch3/game/strings.h | 2 +- programs/games/marblematch3/game/strings_en.h | 3 + programs/games/marblematch3/game/strings_ru.h | 3 + 8 files changed, 183 insertions(+), 5 deletions(-) diff --git a/programs/games/marblematch3/game/rsgame.c b/programs/games/marblematch3/game/rsgame.c index 0582e58945..7044c0893e 100644 --- a/programs/games/marblematch3/game/rsgame.c +++ b/programs/games/marblematch3/game/rsgame.c @@ -219,12 +219,15 @@ unsigned char clamp_byte(int value) { void game_reg_init() { + game.loader_counter = 0; game.menu_replay_timeout = 0; game.process_timer = 0; + game.hiscore = 0; + game.sound_index = 0; game.need_redraw = 1; @@ -410,7 +413,15 @@ void GameProcess() { if (game.status == STATUS_LOADING) { game.loader_counter++; if (game.loader_counter == 2) { - + + // Hiscore file... + + rskos_file_load(HISCORE_FILENAME, (unsigned char*)&game.hiscore, 4); + + DEBUG10f("hiscore: %d \n", game.hiscore); + + // Textures... + game_textures_init_stage2(); @@ -533,6 +544,12 @@ void GameProcess() { // Game Over game.status = STATUS_MENU; game.need_redraw = 1; + + if (game.score > game.hiscore) { + game.hiscore = game.score; + rskos_file_save(HISCORE_FILENAME, (unsigned char*)&game.hiscore, 4); + }; + soundbuf_play(&game.sound_bang); game.menu_replay_timeout = 40; @@ -631,7 +648,7 @@ void GameKeyDown(int key, int first) { if (key == RS_KEY_A) { - game.need_redraw = 1; + game.time = 50; }; diff --git a/programs/games/marblematch3/game/rsgame.h b/programs/games/marblematch3/game/rsgame.h index f3ecc130ac..565513254f 100644 --- a/programs/games/marblematch3/game/rsgame.h +++ b/programs/games/marblematch3/game/rsgame.h @@ -142,6 +142,12 @@ void soundbuf_stop(rs_soundbuf_t *snd); //#define GAME_MODE_MATCH3 0 //#define GAME_MODE_RAMPAGE 1 +#ifdef RS_KOS + #define HISCORE_FILENAME "/sys/games/marble-hiscore.dat" +#else + #define HISCORE_FILENAME "marble-hiscore.dat" +#endif + typedef struct rs_game_t { rs_texture_t framebuffer; unsigned char *bgr_framebuffer; // 24-bit BGRBGRBGR... for direct drawing @@ -179,6 +185,8 @@ typedef struct rs_game_t { int process_timer; + int hiscore; + // int tx; // int ty; // int tz; diff --git a/programs/games/marblematch3/game/rsgamedraw.c b/programs/games/marblematch3/game/rsgamedraw.c index 154c394bde..d60860ad96 100644 --- a/programs/games/marblematch3/game/rsgamedraw.c +++ b/programs/games/marblematch3/game/rsgamedraw.c @@ -52,12 +52,39 @@ void game_draw() { game_textout_at_center( 0, 260, 0, s ); game_textout_at_center( -3, 260-2, 3, s ); + + if (game.score == game.hiscore) { + game_textout_at_center( 0, 290, 0, L_NEW_HISCORE); + game_textout_at_center( -3, 290-2, 3, L_NEW_HISCORE ); + } + else { + char hs[] = L_HISCORE; + str_num = strchr(hs, 'x'); + str_num[0] = '0' + ( (game.hiscore / 100) % 10); + str_num[1] = '0' + ( (game.hiscore / 10) % 10); + str_num[2] = '0' + ( (game.hiscore / 1) % 10); + game_textout_at_center( 0, 290, 0, hs); + game_textout_at_center( -3, 290-2, 3, hs ); + }; + + } + else { + if (game.hiscore) { + char *str_num; + char hs[] = L_HISCORE; + str_num = strchr(hs, 'x'); + str_num[0] = '0' + ( (game.hiscore / 100) % 10); + str_num[1] = '0' + ( (game.hiscore / 10) % 10); + str_num[2] = '0' + ( (game.hiscore / 1) % 10); + game_textout_at_center( 0, 230, 0, hs); + game_textout_at_center( -3, 230-2, 3, hs ); + }; }; if (!game.menu_replay_timeout) { - game_textout_at_center( 0, 300, 0, L_START ); - game_textout_at_center( -3, 300-2, 3, L_START ); + game_textout_at_center( 0, 400, 0, L_START ); + game_textout_at_center( -3, 400-2, 3, L_START ); }; diff --git a/programs/games/marblematch3/game/rskos.c b/programs/games/marblematch3/game/rskos.c index b9212bc07b..a5d44b668c 100644 --- a/programs/games/marblematch3/game/rskos.c +++ b/programs/games/marblematch3/game/rskos.c @@ -104,6 +104,46 @@ void rskos_exit() { rsAppExit(); }; + + + +int rskos_file_save(char *filename, unsigned char *data, int length) { + FILE *fp; + + fp = fopen(filename, "w"); + if (!fp) { + return 0; + }; + + fwrite(data, 1, length, fp); + fclose(fp); + + return 1; + +}; + +int rskos_file_load(char *filename, unsigned char *data, int length) { + FILE *fp; + + fp = fopen(filename, "r"); + if (!fp) { + return 0; + }; + + fread(data, 1, length, fp); + fclose(fp); + + return 1; +}; + + + + + + + + + //void rskos_snd_init() { // // // @@ -142,11 +182,86 @@ void rskos_snd_stop(SNDBUF *hbuf) { #else #include "rs/rsplatform.h" + + + #pragma pack(push,1) + + typedef struct rskos_file_struct_t { + + unsigned int func_num; + unsigned int offset; + unsigned int flags; + unsigned int length; + unsigned char *data; + unsigned char zero; + char *filename; + + } rskos_file_struct_t; + + #pragma pack(pop) + unsigned int rskos_get_time() { return 1; }; + + + + + + + + + + int rskos_file_load(char *filename, unsigned char *data, int length) { + +// char filename_abs[] = "/sys/games/************************"; +// memcpy( filename_abs[ strchr(filename_abs, "*") ], filename, strlen(filename)+1 ); + + rskos_file_struct_t file_struct; + file_struct.func_num = 0; + file_struct.offset = 0; + file_struct.flags = 0; + file_struct.length = length; + file_struct.data = data; + file_struct.zero = 0; + file_struct.filename = filename; + + asm volatile ("int $0x40"::"a"(70), "b"(&file_struct) : "memory"); + + return 1; + } + + + + int rskos_file_save(char *filename, unsigned char *data, int length) { + +// char filename_abs[] = "/sys/games/************************"; +// memcpy( filename_abs[ strchr(filename_abs, "*") ], filename, strlen(filename)+1 ); + + rskos_file_struct_t file_struct; + file_struct.func_num = 2; + file_struct.offset = 0; + file_struct.flags = 0; + file_struct.length = length; + file_struct.data = data; + file_struct.zero = 0; + file_struct.filename = filename; + + asm volatile ("int $0x40"::"a"(70), "b"(&file_struct) : "memory" ); + + return 1; + } + + + + + + + + + void rskos_draw_area(int x, int y, int w, int h, int k_scale, unsigned char *data, unsigned char *scaled_buffer, int image_format) { diff --git a/programs/games/marblematch3/game/rskos.h b/programs/games/marblematch3/game/rskos.h index e0bd6c01d1..3d06d6a5b5 100644 --- a/programs/games/marblematch3/game/rskos.h +++ b/programs/games/marblematch3/game/rskos.h @@ -16,6 +16,11 @@ void rskos_get_screen_size(unsigned int *pw, unsigned int *ph); void rskos_exit(); +// files + +int rskos_file_save(char *filename, unsigned char *data, int length); +int rskos_file_load(char *filename, unsigned char *data, int length); + // sound #ifndef SNDBUF diff --git a/programs/games/marblematch3/game/strings.h b/programs/games/marblematch3/game/strings.h index d2f7f8f6ef..c0a3f78e85 100644 --- a/programs/games/marblematch3/game/strings.h +++ b/programs/games/marblematch3/game/strings.h @@ -2,7 +2,7 @@ #define RS_STRINGS_H #ifndef RS_KOS - #include "strings_en.h" + #include "strings_ru.h" #else #ifdef LANG_RU diff --git a/programs/games/marblematch3/game/strings_en.h b/programs/games/marblematch3/game/strings_en.h index 3fa33b9d71..89236b6941 100644 --- a/programs/games/marblematch3/game/strings_en.h +++ b/programs/games/marblematch3/game/strings_en.h @@ -17,6 +17,9 @@ #define L_GAME_OVER "GAME 0VER" +#define L_HISCORE "REC0RD: xxx" +#define L_NEW_HISCORE "NEW REC0RD" + #define L_BOTTOM_LINE_DEVELOPER_INFO "DEVELOPER: ROMAN SHUVALOV` TOGLIATTI_ 2014" #endif diff --git a/programs/games/marblematch3/game/strings_ru.h b/programs/games/marblematch3/game/strings_ru.h index 6fe5f2cdbc..b85234ad9c 100644 --- a/programs/games/marblematch3/game/strings_ru.h +++ b/programs/games/marblematch3/game/strings_ru.h @@ -17,6 +17,9 @@ #define L_GAME_OVER "igPA 0K0H4EHA" +#define L_HISCORE "PEK0Pd: xxx" +#define L_NEW_HISCORE "H0B\\^ PEK0Pd" + #define L_BOTTOM_LINE_DEVELOPER_INFO "PA3PAb0T4iK: P0MAH hYBAl0B` T0l]aTTi_ 2014" #endif