Updated Marble Match-3 Game

- improved graphics
- smooth animations



git-svn-id: svn://kolibrios.org@5239 a494cfbc-eb01-0410-851d-a64ba20cac60
This commit is contained in:
alpine 2014-12-18 18:37:40 +00:00
parent 7b22babed6
commit 073eb8b7d0
5 changed files with 112 additions and 72 deletions

View File

@ -217,6 +217,8 @@ void game_reg_init() {
game.loader_counter = 0; game.loader_counter = 0;
game.process_timer = 0;
game.need_redraw = 1; game.need_redraw = 1;
game.score = 0; game.score = 0;
@ -381,7 +383,7 @@ void game_fall() {
}; };
}; };
int process_timer = 0;
void GameProcess() { void GameProcess() {
@ -400,13 +402,12 @@ void GameProcess() {
} }
else if (game.status == STATUS_PLAYING) { else if (game.status == STATUS_PLAYING) {
game.process_timer++;
process_timer++; if (game.process_timer > ANIMATION_PROCESS_TIMER_LIMIT) {
if (process_timer > 3) {
game_check_and_explode(); game_check_and_explode();
game_fall(); game_fall();
process_timer = 0; game.process_timer = 0;
}; };
int i; int i;
@ -607,8 +608,16 @@ void GameKeyUp(int key) {
}; };
typedef struct {
int a;
int b;
unsigned short c;
unsigned short d;
} cc_t;
void GameMouseDown(int x, int y) { void GameMouseDown(int x, int y) {
game.need_redraw = 1; game.need_redraw = 1;
game.tx = x; game.tx = x;
@ -657,7 +666,7 @@ void GameMouseDown(int x, int y) {
} }
else { else {
// success // success
process_timer = 0; game.process_timer = 0;
}; };
} }

View File

@ -135,6 +135,8 @@ void soundbuf_stop(rs_soundbuf_t *snd);
#define EXPLOSIONS_MAX_COUNT 16 #define EXPLOSIONS_MAX_COUNT 16
//#define EXPLOSION_PACK(x,y,frame) ( (x) | ( (y)<<8 ) | (frame)<<16 ) //#define EXPLOSION_PACK(x,y,frame) ( (x) | ( (y)<<8 ) | (frame)<<16 )
#define ANIMATION_PROCESS_TIMER_LIMIT 3
typedef struct rs_game_t { typedef struct rs_game_t {
rs_texture_t framebuffer; rs_texture_t framebuffer;
unsigned char *scaled_framebuffer; // 24-bit BGRBGRBGR... for direct drawing unsigned char *scaled_framebuffer; // 24-bit BGRBGRBGR... for direct drawing
@ -167,6 +169,8 @@ typedef struct rs_game_t {
int window_scale; int window_scale;
int process_timer;
int tx; int tx;
int ty; int ty;
int tz; int tz;

View File

@ -17,7 +17,10 @@ void game_draw() {
int w = GAME_WIDTH; int w = GAME_WIDTH;
int h = GAME_HEIGHT; int h = GAME_HEIGHT;
int continue_need_redraw = 0;
if (game.need_redraw) { if (game.need_redraw) {
// if (1) {
@ -59,20 +62,25 @@ void game_draw() {
texture_draw(&game.framebuffer, &game.tex_bg_gameplay, 0, 0, DRAW_MODE_REPLACE); texture_draw(&game.framebuffer, &game.tex_bg_gameplay, 0, 0, DRAW_MODE_REPLACE);
int i, j; int i, j, y_shift;
for (i = 0; i < FIELD_HEIGHT; i++) { for (i = 0; i < FIELD_HEIGHT; i++) {
for (j = 0; j < FIELD_WIDTH; j++) { for (j = 0; j < FIELD_WIDTH; j++) {
if ( IS_BIT_SET( game.field[i*FIELD_WIDTH + j], CRYSTAL_VISIBLE_BIT )) { if ( IS_BIT_SET( game.field[i*FIELD_WIDTH + j], CRYSTAL_VISIBLE_BIT )) {
texture_draw( &game.framebuffer, &game.tex_crystals[ game.field[i*FIELD_WIDTH + j] & CRYSTAL_INDEX_MASK ], FIELD_X0+ j*CRYSTAL_SIZE, FIELD_Y0+ i*CRYSTAL_SIZE, DRAW_MODE_ALPHA ); y_shift = 0;
if (game.selected) { if ( IS_BIT_SET( game.field[i*FIELD_WIDTH + j], CRYSTAL_MOVING_BIT ) ) {
if ( (j == game.selected_x) && (i == game.selected_y) ) { y_shift = -CRYSTAL_SIZE + CRYSTAL_SIZE*(game.process_timer+1)/(ANIMATION_PROCESS_TIMER_LIMIT+1);
texture_draw( &game.framebuffer, &game.tex_cursor, FIELD_X0+ j*CRYSTAL_SIZE, FIELD_Y0+ i*CRYSTAL_SIZE, DRAW_MODE_ALPHA ); continue_need_redraw = 1;
};
}; };
texture_draw( &game.framebuffer, &game.tex_crystals[ game.field[i*FIELD_WIDTH + j] & CRYSTAL_INDEX_MASK ], FIELD_X0+ j*CRYSTAL_SIZE, y_shift + FIELD_Y0+ i*CRYSTAL_SIZE, DRAW_MODE_ALPHA );
}; };
}; };
}; };
if (game.selected) {
texture_draw( &game.framebuffer, &game.tex_cursor, FIELD_X0+ game.selected_x*CRYSTAL_SIZE, FIELD_Y0+ game.selected_y*CRYSTAL_SIZE, DRAW_MODE_ALPHA );
};
for (i = 0; i < game.explosions_count; i++) { for (i = 0; i < game.explosions_count; i++) {
texture_draw( &game.framebuffer, &(game.tex_explosion[ (game.explosions[i]>>16) & 0xFF ]), texture_draw( &game.framebuffer, &(game.tex_explosion[ (game.explosions[i]>>16) & 0xFF ]),
FIELD_X0 + CRYSTAL_SIZE*( game.explosions[i] & 0xFF) - (EXPLOSION_SIZE-CRYSTAL_SIZE)/2 , FIELD_X0 + CRYSTAL_SIZE*( game.explosions[i] & 0xFF) - (EXPLOSION_SIZE-CRYSTAL_SIZE)/2 ,
@ -99,10 +107,13 @@ void game_draw() {
}; };
rskos_draw_area(0, 0, w, h, game.window_scale, game.framebuffer.data, game.scaled_framebuffer); // rskos_draw_area(0, 0, w, h, game.window_scale, game.framebuffer.data, NULL, RSKOS_BGRA);
rskos_draw_area(0, 0, w, h, game.window_scale, game.framebuffer.data, game.scaled_framebuffer, 0);
}; };
game.need_redraw = 0; if (!continue_need_redraw) {
game.need_redraw = 0;
};
}; };
@ -194,47 +205,51 @@ void game_textures_init_stage1() {
float cr_b[CRYSTALS_COUNT] = { 0.0, 0.1, 1.0, 1.0, 0.0, 0.9, 0.9 }; float cr_b[CRYSTALS_COUNT] = { 0.0, 0.1, 1.0, 1.0, 0.0, 0.9, 0.9 };
// rs_gen_init(5, CRYSTAL_SIZE);
// for (i = 0; i < CRYSTALS_COUNT; i++) {
// texture_init(&(game.tex_crystals[i]), CRYSTAL_SIZE, CRYSTAL_SIZE);
//
// rs_gen_func_set(0, 0.0);
// rs_gen_func_radial(0, 0.5, 0.5, 0.5, 0.75, 10.0);
//
// rs_gen_func_set(1, 0.0);
// rs_gen_func_cell(1, 110+100*i, 7+i, NULL, 1.0, 1.0, 0.0, 1.0, 0.0, 1.0);
// rs_gen_func_normalize(1, 0.0, 1.0);
//
// rs_gen_tex_out_rgba_set(0.0, 0.0, 0.0, 0.0);
// rs_gen_tex_out_rgba(1, 1, 1, 0, cr_b[i], cr_g[i], cr_r[i], 1.0);
//
// memcpy(game.tex_crystals[i].data, rs_gen_reg.tex_out, CRYSTAL_SIZE*CRYSTAL_SIZE*4 );
// };
// rs_gen_term();
rs_gen_init(5, CRYSTAL_SIZE); rs_gen_init(5, CRYSTAL_SIZE);
for (i = 0; i < CRYSTALS_COUNT; i++) { for (i = 0; i < CRYSTALS_COUNT; i++) {
texture_init(&(game.tex_crystals[i]), CRYSTAL_SIZE, CRYSTAL_SIZE); texture_init(&(game.tex_crystals[i]), CRYSTAL_SIZE, CRYSTAL_SIZE);
rs_gen_func_set(0, 0.0); rs_gen_func_set(0, 0.0);
rs_gen_func_radial(0, 0.5, 0.5, 0.5, 0.75, 10.0); rs_gen_func_radial(0, 0.5, 0.5, 0.5, 0.75, 10.0);
// rs_gen_func_perlin(2, 33, 4, 0.5, 350+i); rs_gen_func_set(1, 1.0);
// rs_gen_func_normalize(2, 0.0, 1.0); rs_gen_func_cell(1, 310+100*i, 5, NULL, -0.5, 1.0, 1.0, 0.0, -2.0, 2.0);
// rs_gen_func_posterize(2, 4);
//
// rs_gen_func_cell(1, 410+i, 50, NULL, -2.0, 1.0, 1.0, 1.0, 0.0, 1.0);
// rs_gen_func_posterize(1, 2);
// rs_gen_func_normalize(1, 0.0, 1.0);
// rs_gen_func_add(1, 1, 2, 1.0, 0.5);
// rs_gen_func_normalize(1, 0.0, 1.0);
// rs_gen_func_posterize(1, 4);
//
// rs_gen_func_add(1, 0, 1, 1.0, 1.0);
// rs_gen_func_normalize(1, 0.0, 1.0);
// rs_gen_func_mult(1, 0, 1);
// rs_gen_func_normalize(1, 0.0, 1.0);
// rs_gen_func_posterize(1, 4);
rs_gen_func_set(1, 0.0);
rs_gen_func_cell(1, 110+100*i, 7+i, NULL, 1.0, 1.0, 0.0, 1.0, 0.0, 1.0);
rs_gen_func_normalize(1, 0.0, 1.0); rs_gen_func_normalize(1, 0.0, 1.0);
// rs_gen_func_mult_add_value(1, 1, 0.9, 0.1);
// rs_gen_func_normalmap(2, 3, 3, 1, 1.0); rs_gen_func_normalmap(2, 3, 4, 1, 1.0);
// rs_gen_func_mult(1, 1, 2); rs_gen_func_mult_add_value(3, 3, -1.0, 1.0);
//rs_gen_tex_out_rgba_set(0.0, 0.0, 0.0, 0.0); rs_gen_func_clamp(2, 0.5, 1.0);
//rs_gen_tex_out_rgba(1, 1, 1, 1, 0.5+ 0.03*(i%2), 0.7+ 0.03*(i%3) , 0.9, 1.0); rs_gen_func_normalize(2, 0.0, 1.0);
// rs_gen_tex_out_rgba_set(0.2 + 0.2*(i/3), 0.2 + 0.1*(i%5), 0.2 + 0.1*(i%7), 0.0); rs_gen_func_clamp(3, 0.5, 1.0);
// rs_gen_tex_out_rgba(1, 1, 1, 1, 0.0, 0.0, 0.0, 1.0); rs_gen_func_normalize(3, 0.0, 1.0);
rs_gen_func_add(4, 2, 3, 0.5, 0.5);
rs_gen_func_mult(1, 1, 4);
rs_gen_func_normalize(1, 0.0, 1.0);
rs_gen_tex_out_rgba_set(0.0, 0.0, 0.0, 0.0); rs_gen_tex_out_rgba_set(0.0, 0.0, 0.0, 0.0);
// rs_gen_tex_out_rgba_set( cr_b[i], cr_g[i], cr_r[i], 0.0);
rs_gen_tex_out_rgba(1, 1, 1, 0, cr_b[i], cr_g[i], cr_r[i], 1.0); rs_gen_tex_out_rgba(1, 1, 1, 0, cr_b[i], cr_g[i], cr_r[i], 1.0);
// rs_gen_tex_out_rgba(4, 4, 4, 0, 0.8-0.8*cr_b[i], 0.8-0.8*cr_g[i], 0.8-0.8*cr_r[i], 0.0);
// rs_gen_tex_out_rgba(1, 1, 1, 0, 1.0, 1.0, 1.0, 1.0);
memcpy(game.tex_crystals[i].data, rs_gen_reg.tex_out, CRYSTAL_SIZE*CRYSTAL_SIZE*4 ); memcpy(game.tex_crystals[i].data, rs_gen_reg.tex_out, CRYSTAL_SIZE*CRYSTAL_SIZE*4 );
}; };

View File

@ -35,18 +35,19 @@ unsigned int rskos_get_time() {
}; };
void rskos_draw_area(int x, int y, int w, int h, int k_scale, unsigned char *data, unsigned char *scaled_buffer) { 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) {
int bpp = image_format == RSKOS_BGR ? 3 : 4;
int i, j; // int i, j;
//
for (i = 0; i < h*k_scale; i++) { // for (i = 0; i < h*k_scale; i++) {
for (j = 0; j < w*k_scale; j++) { // for (j = 0; j < w*k_scale; j++) {
scaled_buffer[ (i*w*k_scale + j)*3 + 0] = data[ ( (i/k_scale)*w + (j/k_scale) )*4 + 0]; // scaled_buffer[ (i*w*k_scale + j)*3 + 0] = data[ ( (i/k_scale)*w + (j/k_scale) )*4 + 0];
scaled_buffer[ (i*w*k_scale + j)*3 + 1] = data[ ( (i/k_scale)*w + (j/k_scale) )*4 + 1]; // scaled_buffer[ (i*w*k_scale + j)*3 + 1] = data[ ( (i/k_scale)*w + (j/k_scale) )*4 + 1];
scaled_buffer[ (i*w*k_scale + j)*3 + 2] = data[ ( (i/k_scale)*w + (j/k_scale) )*4 + 2]; // scaled_buffer[ (i*w*k_scale + j)*3 + 2] = data[ ( (i/k_scale)*w + (j/k_scale) )*4 + 2];
}; // };
}; // };
@ -65,7 +66,8 @@ void rskos_draw_area(int x, int y, int w, int h, int k_scale, unsigned char *dat
rs_tx_t tex = rs_tx_create_from_data(w*k_scale, h*k_scale, 3, 0, 1, scaled_buffer); //rs_tx_t tex = rs_tx_create_from_data(w*k_scale, h*k_scale, 3, 0, 1, scaled_buffer);
rs_tx_t tex = rs_tx_create_from_data(w, h, bpp, 0, 1, data);
glBindTexture(GL_TEXTURE_2D, tex); glBindTexture(GL_TEXTURE_2D, tex);
@ -86,10 +88,6 @@ void rskos_draw_area(int x, int y, int w, int h, int k_scale, unsigned char *dat
rsDoSwapBuffers(); rsDoSwapBuffers();
// swap buffers (??)
}; };
@ -150,22 +148,33 @@ void rskos_snd_stop(SNDBUF *hbuf) {
return 1; return 1;
}; };
void rskos_draw_area(int x, int y, int w, int h, int k_scale, unsigned char *data, unsigned char *scaled_buffer) { 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); // unsigned char *scaled_buffer = malloc(w*k_scale*h*k_scale*3);
int i, j;
for (i = 0; i < h*k_scale; i++) {
for (j = 0; j < w*k_scale; j++) { // if (scaled_buffer != NULL) {
scaled_buffer[ (i*w*k_scale + j)*3 + 0] = data[ ( (i/k_scale)*w + (j/k_scale) )*4 + 0];
scaled_buffer[ (i*w*k_scale + j)*3 + 1] = data[ ( (i/k_scale)*w + (j/k_scale) )*4 + 1]; int i, j;
scaled_buffer[ (i*w*k_scale + j)*3 + 2] = data[ ( (i/k_scale)*w + (j/k_scale) )*4 + 2];
for (i = 0; i < h*k_scale; i++) {
for (j = 0; j < w*k_scale; j++) {
scaled_buffer[ (i*w*k_scale + j)*3 + 0] = data[ ( (i/k_scale)*w + (j/k_scale) )*4 + 0];
scaled_buffer[ (i*w*k_scale + j)*3 + 1] = data[ ( (i/k_scale)*w + (j/k_scale) )*4 + 1];
scaled_buffer[ (i*w*k_scale + j)*3 + 2] = data[ ( (i/k_scale)*w + (j/k_scale) )*4 + 2];
};
}; };
};
kol_paint_image(0, 0, w*k_scale, h*k_scale, scaled_buffer); kol_paint_image(0, 0, w*k_scale, h*k_scale, scaled_buffer);
// }
// free(image_data); // else {
// //kol_paint_image_pal(0, 0, w, h, data, &image_format)
// h/=4;
// asm volatile ("int $0x40"::"a"(65), "b"(data), "c"(w*65536+h), "d"(0*65536+0), "D"(0), "S"(24) );
//// asm volatile ("int $0x40"::"a"(7), "c"(w*65536+h), "d"(x*65536+y), "b"(data));
// };
//
//// free(image_data);

View File

@ -6,7 +6,10 @@
unsigned int rskos_get_time(); unsigned int rskos_get_time();
void rskos_draw_area(int x, int y, int w, int h, int k_scale, unsigned char *data, unsigned char *scaled_buffer); #define RSKOS_BGRA 32
#define RSKOS_BGR 24
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);
void rskos_resize_window(int w, int h); void rskos_resize_window(int w, int h);
void rskos_get_screen_size(unsigned int *pw, unsigned int *ph); void rskos_get_screen_size(unsigned int *pw, unsigned int *ph);