Marble Match-3 Game update:

- added saving highscores



git-svn-id: svn://kolibrios.org@5260 a494cfbc-eb01-0410-851d-a64ba20cac60
This commit is contained in:
alpine 2014-12-23 15:39:58 +00:00
parent 10c14031be
commit 93fccad3ca
8 changed files with 183 additions and 5 deletions

View File

@ -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;
@ -411,6 +414,14 @@ void GameProcess() {
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;
};

View File

@ -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;

View File

@ -53,11 +53,38 @@ 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 );
};

View File

@ -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() {
// //
//
@ -144,10 +184,85 @@ void rskos_snd_stop(SNDBUF *hbuf) {
#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) {
// unsigned char *scaled_buffer = malloc(w*k_scale*h*k_scale*3);

View File

@ -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

View File

@ -2,7 +2,7 @@
#define RS_STRINGS_H
#ifndef RS_KOS
#include "strings_en.h"
#include "strings_ru.h"
#else
#ifdef LANG_RU

View File

@ -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

View File

@ -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