Marble Match-3 update

- increased performance
- decreased cpu load
- some cosmetic changes



git-svn-id: svn://kolibrios.org@5237 a494cfbc-eb01-0410-851d-a64ba20cac60
This commit is contained in:
alpine 2014-12-16 23:05:17 +00:00
parent 4fd735ecae
commit 5ff91b8eca
6 changed files with 369 additions and 459 deletions

View File

@ -15,13 +15,6 @@
#include "rs/rsplatform.h"
#ifdef RS_USE_C_LIBS // linux version
#include <math.h>
#include <stdlib.h>
#include <string.h>
#include "rs/rskeyboard.h"
#endif
@ -80,7 +73,7 @@ void texture_draw(rs_texture_t *dest, rs_texture_t *src, int x, int y, int mode)
for (i = istart; i < iend; i++) {
for (j = jstart; j < jend; j++) {
for (k = 0; k < 4; k++) {
dest->data[ 4 * ( (y+i)*dest->w + (x+j) ) + k ] = src->data[ (4*(i*src->w + j) + k) % modvalue ];
dest->data[ 4 * ( (y+i)*dest->w + (x+j) ) + k ] = src->data[ (4*((i+ishift)*src->w + j + jshift) + k) % modvalue];
};
};
};
@ -136,6 +129,16 @@ void texture_draw_vline(rs_texture_t *tex, int x, int y, int l, unsigned int col
};
};
void texture_draw_hline(rs_texture_t *tex, int x, int y, int l, unsigned int color) {
int i;
if (x+l >= tex->w) {
l = tex->w - x;
};
for (i = 0; i < l; i++) {
*((unsigned int*) &tex->data[ 4 * ( (y)*tex->w + (x+i) ) + 0 ]) = color;
};
};
void soundbuf_init(rs_soundbuf_t *snd, int length_samples) {
@ -214,6 +217,8 @@ void game_reg_init() {
game.loader_counter = 0;
game.need_redraw = 1;
game.score = 0;
game.time = 0;
@ -282,7 +287,6 @@ int game_check_and_explode() {
else {
if (match_count >= 2) {
found = 1;
// DEBUG10f("found vert (x %d, y %d, count %d) \n", x, y, match_count);
for (i = y+1; i < y+1+match_count+1; i++) {
BIT_SET( FIELD_ITEM(x, i), CRYSTAL_EXPLODED_BIT );
};
@ -318,7 +322,6 @@ int game_check_and_explode() {
else {
if (match_count >= 2) {
found = 1;
// DEBUG10f("found horiz (x %d, y %d, count %d) \n", x, y, match_count);
for (i = x+1; i < x+1+match_count+1; i++) {
BIT_SET( FIELD_ITEM(i, y), CRYSTAL_EXPLODED_BIT );
};
@ -329,7 +332,6 @@ int game_check_and_explode() {
};
if (match_count >= 2) { // last
found = 1;
// DEBUG10("found horiz (2)");
for (i = x+1; i < x+1+match_count+1; i++) {
BIT_SET( FIELD_ITEM(i, y), CRYSTAL_EXPLODED_BIT );
};
@ -349,9 +351,13 @@ int game_check_and_explode() {
if (game.score > 99) {
game.status = STATUS_MENU;
game.need_redraw = 1;
};
if (found) {
game.need_redraw = 1;
};
// DEBUG10f("found = %d \n", found);
return found;
};
@ -363,6 +369,7 @@ void game_fall() {
fall |= !(FIELD_ITEM(x, y) & CRYSTAL_VISIBLE_BIT);
if (fall) {
FIELD_ITEM(x, y) = FIELD_ITEM(x, y-1) | CRYSTAL_MOVING_BIT;
game.need_redraw = 1;
}
else {
BIT_CLEAR( FIELD_ITEM(x, y), CRYSTAL_MOVING_BIT );
@ -382,49 +389,12 @@ void GameProcess() {
game.loader_counter++;
if (game.loader_counter == 2) {
// texture_clear(&game.tex_bg, COLOR_SILVER);
// /*
rs_gen_init(6, 512);
rs_gen_func_perlin(0, 8, 5, 0.5, 1100);
rs_gen_func_normalize(0, 0.0, 1.0);
rs_gen_func_perlin(1, 8, 5, 0.5, 1700);
rs_gen_func_normalize(1, 0.0, 1.0);
rs_gen_func_cell(2, 1360, 50, NULL, 1.0, 0.887, -0.333, 1.0, 0.0, 4.0);
rs_gen_func_normalize(2, 0.0, 0.5);
rs_gen_func_adr(3, 2, 0, 1, 1.0, 0.3);
rs_gen_func_inv(3, 3, 7.5);
rs_gen_func_normalize(3, 0.0, 1.0);
// signed short c[] = { 0, 250, 250, 0, 500, 250, 250, 500};
signed short c[] = { 0, 0, 0, 512, 512, 0, 512, 512};
// signed short c[] = { 128, 128, 128, 384, 384, 128, 384, 384};
//rs_gen_func_cell(4, 0, 4, c, 0.0, 0.3, 1.0, 0.5, 0.0, 0.30);
rs_gen_func_cell(4, 0, 4, c, 1.0, 0.3, 0.0, 0.95, 0.0, 0.30);
rs_gen_func_normalize(4, 0.0, 1.0);
// rs_gen_func_radial(5, 0.5, 0.5, 0.60, 1.0, 4.0);
// rs_gen_func_add(4, 4, 5, 0.5, 0.5);
//
rs_gen_func_mult(4, 4, 3);
// coloring...
rs_gen_func_mult_add_value(0, 4, 0.8, 0.0);
rs_gen_func_add(0, 4, 1, 0.95, 0.05);
rs_gen_func_add(3, 4, 2, 0.95, 0.05);
rs_gen_tex_out_rgba(4, 0, 3, -1, 0.9, 0.9, 0.9, 1.0);
memcpy(game.tex_bg.data, rs_gen_reg.tex_out, 512*512*4 );
rs_gen_term();
// */
game_textures_init_stage2();
game.status = STATUS_MENU;
game.need_redraw = 1;
};
}
@ -441,6 +411,7 @@ void GameProcess() {
int i;
for (i = 0; i < game.explosions_count; i++) {
game.need_redraw = 1;
game.explosions[i] = (game.explosions[i] & 0xFFFF) | ( ((game.explosions[i]>>16)+1) << 16 );
if ( (game.explosions[i] >> 16) >= EXPLOSION_FRAMES_COUNT ) {
game.explosions[i] = game.explosions[game.explosions_count-1];
@ -449,7 +420,14 @@ void GameProcess() {
};
};
if ((game.time+1)/25 != game.time/25) {
game.need_redraw = 1;
};
game.time++;
};
@ -477,139 +455,7 @@ void GameInit() {
game_font_init();
texture_init(&game.framebuffer, GAME_WIDTH, GAME_HEIGHT);
// texture_init(&game.tex, 64, 64);
// rs_gen_init(1, 64);
// rs_gen_func_set(0, 0.0);
// rs_gen_func_cell(0, 1200, 10, NULL, 1.0, 1.0, 1.0, 1.0, 0.0, 1.0);
// rs_gen_func_normalize(0, 0.0, 1.0);
// rs_gen_func_posterize(0, 5);
// rs_gen_tex_out_rgba(0, 0, 0, -1, 1.0, 1.0, 1.0, 1.0);
// memcpy(game.tex.data, rs_gen_reg.tex_out, 64*64*4 );
// rs_gen_term();
texture_init(&game.tex_clouds, 128, 128);
rs_gen_init(1, 128);
rs_gen_func_perlin(0, 8, 5, 0.5, 1100);
rs_gen_func_normalize(0, 0.0, 1.0);
rs_gen_func_posterize(0, 6);
rs_gen_func_mult_add_value(0, 0, 0.6, 0.4);
// rs_gen_func_set(0, 1.0);
rs_gen_tex_out_rgba(0, 0, 0, -1, 1.0, 1.0, 1.0, 1.0);
memcpy(game.tex_clouds.data, rs_gen_reg.tex_out, 128*128*4 );
rs_gen_term();
texture_init(&game.tex_logo, GAME_WIDTH, 128);
texture_clear(&game.tex_logo, COLOR_TRANSPARENT);
game_textout_adv( &game.tex_logo, GAME_WIDTH/2 - 192, 3, 1, DRAW_MODE_REPLACE, "MARBLE");
game_textout_adv( &game.tex_logo, GAME_WIDTH/2 - 192, 63, 1, DRAW_MODE_REPLACE, "MATCH3");
texture_draw(&game.tex_logo, &game.tex_clouds, 0, 0, DRAW_MODE_MULT | DRAW_TILED_FLAG);
game_textout_adv( &game.tex_logo, GAME_WIDTH/2 - 192 - 4, 0, 1, DRAW_MODE_MULT, "MARBLE");
game_textout_adv( &game.tex_logo, GAME_WIDTH/2 - 192 - 4, 60, 1, DRAW_MODE_MULT, "MATCH3");
// rs_gen_init(1, 128);
// rs_gen_func_perlin(0, 8, 5, 0.5, 1100);
// rs_gen_func_normalize(0, 0.0, 1.0);
// rs_gen_func_posterize(0, 4);
// rs_gen_func_normalize(0, 0.0, 0.50);
// rs_gen_tex_out_rgba(0, 0, 0, -1, 0.9, 0.7, 0.5, 1.0);
// memcpy(game.tex_clouds.data, rs_gen_reg.tex_out, 128*128*4 );
// rs_gen_term();
texture_init(&game.tex_bg, 512, 512);
texture_clear(&game.tex_bg, COLOR_SILVER);
texture_init(&game.tex_cursor, CRYSTAL_SIZE, CRYSTAL_SIZE);
texture_clear(&game.tex_cursor, COLOR_SEMI_TRANSPARENT);
// float cr_r[CRYSTALS_COUNT] = { 0.8, 0.2, 0.1, 0.6, 0.7, 0.0, 0.7 };
// float cr_g[CRYSTALS_COUNT] = { 0.1, 0.6, 0.4, 0.0, 0.6, 0.0, 0.8 };
// float cr_b[CRYSTALS_COUNT] = { 0.1, 0.1, 0.7, 0.7, 0.0, 0.3, 0.9 };
// float cr_r[CRYSTALS_COUNT] = { 0.9, 0.3, 0.1, 0.7, 0.8, 0.0, 0.8 };
// float cr_g[CRYSTALS_COUNT] = { 0.1, 0.8, 0.5, 0.0, 0.7, 0.0, 0.8 };
// float cr_b[CRYSTALS_COUNT] = { 0.0, 0.1, 0.9, 0.8, 0.0, 0.5, 0.9 };
float cr_r[CRYSTALS_COUNT] = { 1.0, 0.4, 0.1, 0.9, 0.9, 0.2, 0.8 };
float cr_g[CRYSTALS_COUNT] = { 0.1, 1.0, 0.6, 0.1, 0.8, 0.2, 0.8 };
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_perlin(2, 33, 4, 0.5, 350+i);
// rs_gen_func_normalize(2, 0.0, 1.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_mult_add_value(1, 1, 0.9, 0.1);
// rs_gen_func_normalmap(2, 3, 3, 1, 1.0);
// rs_gen_func_mult(1, 1, 2);
//rs_gen_tex_out_rgba_set(0.0, 0.0, 0.0, 0.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_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_tex_out_rgba(1, 1, 1, 1, 0.0, 0.0, 0.0, 1.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);
memcpy(game.tex_crystals[i].data, rs_gen_reg.tex_out, CRYSTAL_SIZE*CRYSTAL_SIZE*4 );
};
rs_gen_term();
rs_gen_init(3, EXPLOSION_SIZE);
for (i = 0; i < EXPLOSION_FRAMES_COUNT; i++) {
texture_init(&(game.tex_explosion[i]), EXPLOSION_SIZE, EXPLOSION_SIZE);
rs_gen_func_set(0, 1.0);
// rs_gen_func_radial(0, 0.5, 0.5, 0.3 + 0.5*i/EXPLOSION_FRAMES_COUNT, 0.975, 4.0);
// rs_gen_func_set(0, 1.0);
rs_gen_func_set(1, 0.0);
rs_gen_func_radial(1, 0.5, 0.5, 0.1 + 0.4*i/EXPLOSION_FRAMES_COUNT, 1.0 - 1.0*i/EXPLOSION_FRAMES_COUNT, 2.5 + i%5);
rs_gen_tex_out_rgba_set( 0.0, 0.0, 0.0, 0.0);
rs_gen_tex_out_rgba(0, 0, 0, 1, 1.0, 1.0, 1.0, 1.0);
memcpy(game.tex_explosion[i].data, rs_gen_reg.tex_out, EXPLOSION_SIZE*EXPLOSION_SIZE*4 );
};
rs_gen_term();
game_textures_init_stage1();
@ -646,19 +492,11 @@ void GameTerm() {
game_font_term();
free(game.scaled_framebuffer);
game_textures_free();
texture_free(&game.framebuffer);
texture_free(&game.tex_logo);
texture_free(&game.tex_clouds);
texture_free(&game.tex_bg);
// texture_free(&game.tex_gui_line);
// int i;
// for (i = 0; i < ROCKS_COUNT; i++) {
// texture_free(&game.tex_rocks[i]);
// };
soundbuf_free(&game.sound_test1);
soundbuf_free(&game.sound_test2);
@ -676,6 +514,11 @@ void GameTerm() {
void GameKeyDown(int key, int first) {
if (key == RS_KEY_A) {
game.need_redraw = 1;
};
switch (key) {
case RS_KEY_LEFT:
@ -729,44 +572,15 @@ void GameKeyDown(int key, int first) {
if (game.status == STATUS_PLAYING) {
if (key == RS_KEY_A) {
};
if (key == RS_KEY_SPACE) {
// Check and explode match-3
game.score = 101;
};
// switch (key) {
//
// case RS_KEY_ESCAPE:
// game.status = STATUS_MENU;
// menu_open(0);
// break;
// case RS_KEY_A:
//
//// if ( (game.tx > 0) && (game.ty > 5) && (game.tx < GAME_WIDTH-20) && (game.ty < GAME_HEIGHT-10) ) {
////
//// soundbuf_play(&game.sound_test1);
////
//// game.bullet_index++;
//// game.bullet_index %= BULLETS_COUNT;
//// game.bullet_x[game.bullet_index] = game.tx + 12;
//// game.bullet_y[game.bullet_index] = game.ty + 3;
//// };
//
// break;
//
// };
};
};
@ -794,6 +608,9 @@ void GameKeyUp(int key) {
};
void GameMouseDown(int x, int y) {
game.need_redraw = 1;
game.tx = x;
game.ty = y;

View File

@ -116,11 +116,11 @@ void soundbuf_stop(rs_soundbuf_t *snd);
#define GAME_SHOOT_PERIOD 3
#define FIELD_WIDTH 12
#define FIELD_HEIGHT 9
#define FIELD_WIDTH 10
#define FIELD_HEIGHT 8
#define FIELD_LENGTH (FIELD_WIDTH * FIELD_HEIGHT)
#define CRYSTAL_SIZE 32
#define FIELD_X0 64
#define CRYSTAL_SIZE 40
#define FIELD_X0 56
#define FIELD_Y0 128
#define FIELD_ITEM(x,y) (game.field[(y)*FIELD_WIDTH+(x)])
@ -129,7 +129,7 @@ void soundbuf_stop(rs_soundbuf_t *snd);
#define CRYSTAL_EXPLODED_BIT 0x20
#define CRYSTAL_MOVING_BIT 0x40
#define EXPLOSION_FRAMES_COUNT 19
#define EXPLOSION_FRAMES_COUNT 10
#define EXPLOSION_SIZE 64
#define EXPLOSIONS_MAX_COUNT 16
@ -142,6 +142,8 @@ typedef struct rs_game_t {
int loader_counter;
rs_texture_t tex_bg;
rs_texture_t tex_bg_gameplay;
rs_texture_t tex_field;
rs_texture_t tex_logo;
rs_texture_t tex_clouds;
@ -178,6 +180,8 @@ typedef struct rs_game_t {
unsigned int explosions_count;
unsigned int explosions[EXPLOSIONS_MAX_COUNT]; //0x00TTYYXX, TT = frame, YY = fieldY, XX = fieldX
int need_redraw;
int score;
int time;

View File

@ -2,6 +2,9 @@
#include "rsgametext.h"
#include "rsgamemenu.h"
#include "rsgentex.h"
#include "rs/rsplatform.h"
#include "rskos.h"
#include "rsnoise.h"
@ -14,164 +17,331 @@ void game_draw() {
int w = GAME_WIDTH;
int h = GAME_HEIGHT;
// int kk = 20; // (rskos_get_time()/1) % 160;
//
// unsigned char *c = game.framebuffer.data;
//
// int i;
// for (i = 0; i < w*h*4; i+=4) {
// c[i+0] = 10; // i/w/3;
// c[i+1] = (( (1*i)*(i + kk)/70) & 5) ? 70 : 0;
// c[i+2] = 50;
// c[i+3] = i % 128;
// };
// texture_clear(&game.framebuffer, COLOR_DARK_RED);
// texture_clear(&game.tex);
if (game.need_redraw) {
// texture_draw(&game.framebuffer, &game.tex, 40, 40, DRAW_MODE_ADDITIVE);
// texture_draw(&game.framebuffer, &game.tex, 70, 50, DRAW_MODE_ADDITIVE);
// texture_draw(&game.framebuffer, &game.tex, 20, 60, DRAW_MODE_ADDITIVE);
// texture_draw(&game.framebuffer, &game.tex, 60, 70, DRAW_MODE_ADDITIVE);
//
// texture_draw(&game.framebuffer, &game.tex, 111, 150, DRAW_MODE_ADDITIVE);
// int i, c, c2, c3;
// for (i = 0; i < 100; i++) {
//// DEBUG10f("i = %d, v1 = %.4f, v2 = %.4f \n", i, rs_noise(kk+100, kk+i)*10, rs_noise(kk+200, kk+i+300)*10);
// c = (0.5+0.45*rs_noise(kk+150, kk+i))*255;
// c2 = c + 0.05*rs_noise(kk+150, kk+i)*255;
// c3 = c2; // (0.5+0.49*rs_noise(kk+150, kk+i+2))*255;
// texture_set_pixel(&game.framebuffer, (0.5+0.49*rs_noise(kk+1100, kk+i))*GAME_WIDTH, (0.5+0.49*rs_noise(kk+1200, kk+i+1300))*GAME_HEIGHT,
// c + (c2<<8) + (c3<<16) + 0xFF000000);
// };
// texture_clear(&game.tex_ground, COLOR_TRANSPARENT);
// rs_perlin_configure(47, 4, 0.5, 1000, 256);
// for (i = 0; i < game.tex_ground.w; i++) {
// texture_draw_vline(&game.tex_ground, i, 25 + rs_perlin(0,i+game.tz)*25, 2, 0xFF113300);
// texture_draw_vline(&game.tex_ground, i, 25 + rs_perlin(0,i+game.tz)*25 + 2, 999, 0xFF000000);
// };
//
//// texture_draw(&game.tex_ground, &game.tex_clouds, game.tz, 0, /* game.tx, game.ty, */ DRAW_MODE_ADDITIVE | DRAW_TILED_FLAG );
// texture_draw(&game.framebuffer, &game.tex_ground, 0, GAME_HEIGHT-50, DRAW_MODE_ALPHA);
texture_draw(&game.framebuffer, &game.tex_bg, 0, 0, DRAW_MODE_REPLACE);
if ( (game.status == STATUS_MENU) || (game.status == STATUS_LOADING) ){
// char **title = menu_titles[game.menu_index];
// int y = (game.menu_index == MENU_MAIN) ? 280 : 250;
// texture_draw(&game.framebuffer, &game.tex_gui_line, 0, y+15*game.menu_item_index, DRAW_MODE_ALPHA);
// while (*title) {
// game_textout(20, y, (*(title))[0]==' ' ? 3 : 0 , (*(title))+1 ); // first (zero) char defines action, title starts from second (1st) char
// title++;
// y+=15;
// };
if (game.menu_index == MENU_MAIN) {
if ( (game.status == STATUS_MENU) || (game.status == STATUS_LOADING) ) {
if (game.status == STATUS_LOADING) {
game_textout( GAME_WIDTH/2 - 192, 240, 0, " L0ADING``` " );
}
else {
// game_textout( GAME_WIDTH/2 - 192, 100, 1, "MARBLE");
// game_textout( GAME_WIDTH/2 - 192, 160, 1, "MATCH3");
texture_draw( &game.framebuffer, &game.tex_logo, 0, 50, DRAW_MODE_ALPHA );
if (game.time) {
texture_draw(&game.framebuffer, &game.tex_bg, 0, 0, DRAW_MODE_REPLACE);
if (game.menu_index == MENU_MAIN) {
if (game.status == STATUS_LOADING) {
game_textout( GAME_WIDTH/2 - 192, 240, 0, " L0ADING``` " );
}
else {
texture_draw( &game.framebuffer, &game.tex_logo, 0, 50, DRAW_MODE_ALPHA );
if (game.time) {
game_textout( GAME_WIDTH/2 - 192, 230, 3, " LEVEL PA55ED " );
char s[] = " TIME: 000 ";
int time_sec = game.time / 25;
s[11] = '0' + (( time_sec / 100 ) % 10);
s[12] = '0' + (( time_sec / 10 ) % 10);
s[13] = '0' + (( time_sec / 1 ) % 10);
game_textout( GAME_WIDTH/2 - 192, 260, 3, s );
};
game_textout( GAME_WIDTH/2 - 192, 300, 0, " CLICK T0 5TART " );
game_textout( GAME_WIDTH/2 - 192, 230, 3, " LEVEL PA55ED " );
char s[] = " TIME: 000 ";
int time_sec = game.time / 25;
s[11] = '0' + (( time_sec / 100 ) % 10);
s[12] = '0' + (( time_sec / 10 ) % 10);
s[13] = '0' + (( time_sec / 1 ) % 10);
game_textout( GAME_WIDTH/2 - 192, 260, 3, s );
};
game_textout( GAME_WIDTH/2 - 192, 300, 0, " CLICK T0 5TART " );
game_textout( 2, GAME_HEIGHT-10, 2, "DEVEL0PED BY R0MAN 5HUVAL0V");
};
}
else {
texture_draw(&game.framebuffer, &game.tex_bg_gameplay, 0, 0, DRAW_MODE_REPLACE);
game_textout( 2, GAME_HEIGHT-10, 2, "DEVEL0PED BY R0MAN 5HUVAL0V");
};
}
else {
int i, j;
for (i = 0; i < FIELD_HEIGHT; i++) {
for (j = 0; j < FIELD_WIDTH; j++) {
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 );
if (game.selected) {
if ( (j == game.selected_x) && (i == game.selected_y) ) {
texture_draw( &game.framebuffer, &game.tex_cursor, FIELD_X0+ j*CRYSTAL_SIZE, FIELD_Y0+ i*CRYSTAL_SIZE, DRAW_MODE_ALPHA );
int i, j;
for (i = 0; i < FIELD_HEIGHT; i++) {
for (j = 0; j < FIELD_WIDTH; j++) {
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 );
if (game.selected) {
if ( (j == game.selected_x) && (i == game.selected_y) ) {
texture_draw( &game.framebuffer, &game.tex_cursor, FIELD_X0+ j*CRYSTAL_SIZE, FIELD_Y0+ i*CRYSTAL_SIZE, DRAW_MODE_ALPHA );
};
};
};
};
};
};
for (i = 0; i < game.explosions_count; i++) {
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_Y0 + CRYSTAL_SIZE*( (game.explosions[i]>>8) & 0xFF) - (EXPLOSION_SIZE-CRYSTAL_SIZE)/2 ,
DRAW_MODE_ALPHA);
};
char str[] = "TIME: 999 ";
int time_sec = game.time / 25;
str[6] = '0' + ( (time_sec / 100) % 10);
str[7] = '0' + ( (time_sec / 10) % 10);
str[8] = '0' + ( (time_sec / 1) % 10);
game_textout( 32, 32, 3, str );
char sstr[] = "5C0RE: 000 0F 100 ";
sstr[7] = '0' + ( (game.score / 100) % 10);
sstr[8] = '0' + ( (game.score / 10) % 10);
sstr[9] = '0' + ( (game.score / 1) % 10);
game_textout( 32, GAME_HEIGHT-48, 3, sstr );
// char s[] = "YOUR TIME: 000";
// s[11] = '3';
// s[12] = '9';
// s[13] = '4';
//game_textout( GAME_WIDTH/2 - 192, 260, 0, s );
// texture_draw(&game.framebuffer, &game.tex_ship[0], game.tx-8, game.ty-4, DRAW_MODE_ALPHA);
// texture_draw(&game.framebuffer, &game.tex_ship[1], game.tx-8, game.ty-4, DRAW_MODE_ALPHA);
// texture_draw(&game.framebuffer, &game.tex_ship[2], game.tx, game.ty-4, DRAW_MODE_ALPHA);
// texture_draw(&game.framebuffer, &game.tex_ship[3], game.tx, game.ty-4, DRAW_MODE_ALPHA);
// int i;
// for (i = 0; i < BULLETS_COUNT; i++) {
// if (game.bullet_y[i]) {
// texture_set_pixel(&game.framebuffer, game.bullet_x[i]-4, game.bullet_y[i], 0xFF00BB00);
// texture_set_pixel(&game.framebuffer, game.bullet_x[i]-3, game.bullet_y[i], 0xFF00CC00);
// texture_set_pixel(&game.framebuffer, game.bullet_x[i]-2, game.bullet_y[i], 0xFF00DD00);
// texture_set_pixel(&game.framebuffer, game.bullet_x[i]-1, game.bullet_y[i], 0xFF00EE00);
// texture_set_pixel(&game.framebuffer, game.bullet_x[i]-0, game.bullet_y[i], 0xFF00FF00);
// };
// };
// game_textout( 2, 2, 2, L_TECHDEMO_LINE1 );
// game_textout( 2, 12, 2, L_TECHDEMO_LINE2 );
};
for (i = 0; i < game.explosions_count; i++) {
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_Y0 + CRYSTAL_SIZE*( (game.explosions[i]>>8) & 0xFF) - (EXPLOSION_SIZE-CRYSTAL_SIZE)/2 ,
DRAW_MODE_ALPHA);
};
rskos_draw_area(0, 0, w, h, game.window_scale, game.framebuffer.data, game.scaled_framebuffer);
char str[] = "TIME: 999 ";
int time_sec = game.time / 25;
str[6] = '0' + ( (time_sec / 100) % 10);
str[7] = '0' + ( (time_sec / 10) % 10);
str[8] = '0' + ( (time_sec / 1) % 10);
game_textout( 56, 32, 3, str );
char sstr[] = "5C0RE: 000 0F 100 ";
sstr[7] = '0' + ( (game.score / 100) % 10);
sstr[8] = '0' + ( (game.score / 10) % 10);
sstr[9] = '0' + ( (game.score / 1) % 10);
game_textout( 56, 64, 3, sstr );
};
rskos_draw_area(0, 0, w, h, game.window_scale, game.framebuffer.data, game.scaled_framebuffer);
};
game.need_redraw = 0;
};
void game_textures_init_stage1() {
int i;
texture_init(&game.framebuffer, GAME_WIDTH, GAME_HEIGHT);
// texture_init(&game.tex, 64, 64);
// rs_gen_init(1, 64);
// rs_gen_func_set(0, 0.0);
// rs_gen_func_cell(0, 1200, 10, NULL, 1.0, 1.0, 1.0, 1.0, 0.0, 1.0);
// rs_gen_func_normalize(0, 0.0, 1.0);
// rs_gen_func_posterize(0, 5);
// rs_gen_tex_out_rgba(0, 0, 0, -1, 1.0, 1.0, 1.0, 1.0);
// memcpy(game.tex.data, rs_gen_reg.tex_out, 64*64*4 );
// rs_gen_term();
texture_init(&game.tex_clouds, 128, 128);
rs_gen_init(1, 128);
rs_gen_func_perlin(0, 8, 5, 0.5, 1100);
rs_gen_func_normalize(0, 0.0, 1.0);
rs_gen_func_posterize(0, 6);
rs_gen_func_mult_add_value(0, 0, 0.6, 0.4);
// rs_gen_func_set(0, 1.0);
rs_gen_tex_out_rgba(0, 0, 0, -1, 1.0, 1.0, 1.0, 1.0);
memcpy(game.tex_clouds.data, rs_gen_reg.tex_out, 128*128*4 );
rs_gen_term();
texture_init(&game.tex_logo, GAME_WIDTH, 128);
texture_clear(&game.tex_logo, COLOR_TRANSPARENT);
game_textout_adv( &game.tex_logo, GAME_WIDTH/2 - 192, 3, 1, DRAW_MODE_REPLACE, "MARBLE");
game_textout_adv( &game.tex_logo, GAME_WIDTH/2 - 192, 63, 1, DRAW_MODE_REPLACE, "MATCH3");
texture_draw(&game.tex_logo, &game.tex_clouds, 0, 0, DRAW_MODE_MULT | DRAW_TILED_FLAG);
game_textout_adv( &game.tex_logo, GAME_WIDTH/2 - 192 - 4, 0, 1, DRAW_MODE_MULT, "MARBLE");
game_textout_adv( &game.tex_logo, GAME_WIDTH/2 - 192 - 4, 60, 1, DRAW_MODE_MULT, "MATCH3");
texture_init(&game.tex_bg, 512, 512);
texture_clear(&game.tex_bg, COLOR_SILVER);
texture_init(&game.tex_bg_gameplay, 512, 512);
texture_clear(&game.tex_bg_gameplay, COLOR_SILVER);
texture_init(&game.tex_cursor, CRYSTAL_SIZE, CRYSTAL_SIZE);
rs_gen_init(2, CRYSTAL_SIZE);
rs_gen_func_set(0, 0.0); // inner
rs_gen_func_radial(0, 0.5, 0.5, 0.5, 1.0, 2.0);
rs_gen_func_clamp(0, 0.1, 0.5);
rs_gen_func_normalize(0, 0.0, 1.0);
rs_gen_func_mult_add_value(0, 0, -1.0, 1.0);
rs_gen_func_set(1, 0.0); // outer
rs_gen_func_radial(1, 0.5, 0.5, 0.5, 1.0, 2.0);
rs_gen_func_clamp(1, 0.0, 0.2);
rs_gen_func_normalize(1, 0.0, 1.0);
rs_gen_func_mult(0, 0, 1);
rs_gen_func_set(1, 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, 1.0, 1.0, 1.0, 1.0);
memcpy(game.tex_cursor.data, rs_gen_reg.tex_out, CRYSTAL_SIZE*CRYSTAL_SIZE*4 );
rs_gen_term();
texture_init(&game.tex_field, FIELD_WIDTH*CRYSTAL_SIZE + 7, FIELD_HEIGHT*CRYSTAL_SIZE + 7);
texture_clear(&game.tex_field, 0xAABBBBBB); // 0x66404060 // 0xAACCCCCC
// float cr_r[CRYSTALS_COUNT] = { 0.8, 0.2, 0.1, 0.6, 0.7, 0.0, 0.7 };
// float cr_g[CRYSTALS_COUNT] = { 0.1, 0.6, 0.4, 0.0, 0.6, 0.0, 0.8 };
// float cr_b[CRYSTALS_COUNT] = { 0.1, 0.1, 0.7, 0.7, 0.0, 0.3, 0.9 };
// float cr_r[CRYSTALS_COUNT] = { 0.9, 0.3, 0.1, 0.7, 0.8, 0.0, 0.8 };
// float cr_g[CRYSTALS_COUNT] = { 0.1, 0.8, 0.5, 0.0, 0.7, 0.0, 0.8 };
// float cr_b[CRYSTALS_COUNT] = { 0.0, 0.1, 0.9, 0.8, 0.0, 0.5, 0.9 };
float cr_r[CRYSTALS_COUNT] = { 1.0, 0.4, 0.1, 0.9, 0.9, 0.2, 0.8 };
float cr_g[CRYSTALS_COUNT] = { 0.1, 1.0, 0.6, 0.1, 0.8, 0.2, 0.8 };
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_perlin(2, 33, 4, 0.5, 350+i);
// rs_gen_func_normalize(2, 0.0, 1.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_mult_add_value(1, 1, 0.9, 0.1);
// rs_gen_func_normalmap(2, 3, 3, 1, 1.0);
// rs_gen_func_mult(1, 1, 2);
//rs_gen_tex_out_rgba_set(0.0, 0.0, 0.0, 0.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_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_tex_out_rgba(1, 1, 1, 1, 0.0, 0.0, 0.0, 1.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);
memcpy(game.tex_crystals[i].data, rs_gen_reg.tex_out, CRYSTAL_SIZE*CRYSTAL_SIZE*4 );
};
rs_gen_term();
rs_gen_init(3, EXPLOSION_SIZE);
for (i = 0; i < EXPLOSION_FRAMES_COUNT; i++) {
texture_init(&(game.tex_explosion[i]), EXPLOSION_SIZE, EXPLOSION_SIZE);
rs_gen_func_set(0, 1.0);
// rs_gen_func_radial(0, 0.5, 0.5, 0.3 + 0.5*i/EXPLOSION_FRAMES_COUNT, 0.975, 4.0);
// rs_gen_func_set(0, 1.0);
rs_gen_func_set(1, 0.0);
rs_gen_func_radial(1, 0.5, 0.5, 0.1 + 0.4*i/EXPLOSION_FRAMES_COUNT, 1.0 - 1.0*i/EXPLOSION_FRAMES_COUNT, 2.5 + i%5);
rs_gen_tex_out_rgba_set( 0.0, 0.0, 0.0, 0.0);
rs_gen_tex_out_rgba(0, 0, 0, 1, 1.0, 1.0, 1.0, 1.0);
memcpy(game.tex_explosion[i].data, rs_gen_reg.tex_out, EXPLOSION_SIZE*EXPLOSION_SIZE*4 );
};
rs_gen_term();
};
void game_textures_init_stage2() {
// texture_clear(&game.tex_bg, COLOR_SILVER);
// /*
rs_gen_init(6, 512);
rs_gen_func_perlin(0, 8, 5, 0.5, 1100);
rs_gen_func_normalize(0, 0.0, 1.0);
rs_gen_func_perlin(1, 8, 5, 0.5, 1700);
rs_gen_func_normalize(1, 0.0, 1.0);
rs_gen_func_cell(2, 1118, 50, NULL, 1.0, 0.887, -0.333, 1.0, 0.0, 4.0); // 1360
rs_gen_func_normalize(2, 0.0, 0.5);
rs_gen_func_adr(3, 2, 0, 1, 1.0, 0.3);
rs_gen_func_inv(3, 3, 7.5);
rs_gen_func_normalize(3, 0.0, 1.0);
// signed short c[] = { 0, 250, 250, 0, 500, 250, 250, 500};
signed short c[] = { 0, 0, 0, 512, 512, 0, 512, 512};
// signed short c[] = { 128, 128, 128, 384, 384, 128, 384, 384};
//rs_gen_func_cell(4, 0, 4, c, 0.0, 0.3, 1.0, 0.5, 0.0, 0.30);
rs_gen_func_cell(4, 0, 4, c, 1.0, 0.3, 0.0, 0.95, 0.0, 0.30);
rs_gen_func_normalize(4, 0.0, 1.0);
// rs_gen_func_radial(5, 0.5, 0.5, 0.60, 1.0, 4.0);
// rs_gen_func_add(4, 4, 5, 0.5, 0.5);
//
rs_gen_func_mult(4, 4, 3);
// coloring...
rs_gen_func_mult_add_value(0, 4, 0.8, 0.0);
rs_gen_func_add(0, 4, 1, 0.95, 0.05);
rs_gen_func_add(3, 4, 2, 0.95, 0.05);
rs_gen_tex_out_rgba(4, 0, 3, -1, 0.9, 0.9, 0.9, 1.0);
memcpy(game.tex_bg.data, rs_gen_reg.tex_out, 512*512*4 );
rs_gen_term();
// */
// Background for gameplay
texture_draw( &game.tex_bg_gameplay, &game.tex_bg, 256, 256, DRAW_MODE_REPLACE | DRAW_TILED_FLAG );
// Bevel
texture_draw_vline( &game.tex_bg_gameplay, FIELD_X0 - 5, FIELD_Y0 - 5, FIELD_HEIGHT*CRYSTAL_SIZE + 10, 0xFF404060 );
texture_draw_hline( &game.tex_bg_gameplay, FIELD_X0 - 5, FIELD_Y0 - 5, FIELD_WIDTH*CRYSTAL_SIZE + 10, 0xFF404060 );
texture_draw_vline( &game.tex_bg_gameplay, FIELD_X0 - 4, FIELD_Y0 - 4, FIELD_HEIGHT*CRYSTAL_SIZE + 8, 0xFF606080 );
texture_draw_hline( &game.tex_bg_gameplay, FIELD_X0 - 4, FIELD_Y0 - 4, FIELD_WIDTH*CRYSTAL_SIZE + 8, 0xFF606080 );
texture_draw_vline( &game.tex_bg_gameplay, FIELD_X0 + 4 + FIELD_WIDTH*CRYSTAL_SIZE, FIELD_Y0 - 4, FIELD_HEIGHT*CRYSTAL_SIZE + 8, 0xFFC0C0C0 );
texture_draw_hline( &game.tex_bg_gameplay, FIELD_X0 - 4, FIELD_Y0 + 4 + FIELD_HEIGHT*CRYSTAL_SIZE, FIELD_WIDTH*CRYSTAL_SIZE + 9, 0xFFC0C0C0 );
texture_draw_vline( &game.tex_bg_gameplay, FIELD_X0 + 5 + FIELD_WIDTH*CRYSTAL_SIZE, FIELD_Y0 - 5, FIELD_HEIGHT*CRYSTAL_SIZE + 10, 0xFFE0E0E0 );
texture_draw_hline( &game.tex_bg_gameplay, FIELD_X0 - 5, FIELD_Y0 + 5 + FIELD_HEIGHT*CRYSTAL_SIZE, FIELD_WIDTH*CRYSTAL_SIZE + 11, 0xFFE0E0E0 );
texture_draw( &game.tex_bg_gameplay, &game.tex_field, FIELD_X0 - 3, FIELD_Y0 - 3, DRAW_MODE_ALPHA );
};
void game_textures_free() {
free(game.scaled_framebuffer);
// texture_free(&game.tex_gui_line);
int i;
for (i = 0; i < CRYSTALS_COUNT; i++) {
texture_free(&game.tex_crystals[i]);
};
for (i = 0; i < EXPLOSION_FRAMES_COUNT; i++) {
texture_free(&game.tex_explosion[i]);
};
texture_free(&game.framebuffer);
texture_free(&game.tex_logo);
texture_free(&game.tex_clouds);
texture_free(&game.tex_bg);
texture_free(&game.tex_bg_gameplay);
};

View File

@ -3,6 +3,10 @@
#include "rsgame.h"
void game_textures_init_stage1();
void game_textures_init_stage2();
void game_textures_free();
void game_draw();
void game_loader_draw_mainthread();

View File

@ -335,8 +335,8 @@ void game_font_init() {
float radiuses[4] = { 0.9667, 0.997, 1.2, 0.87 };
float colors_r[4] = { 0.3, 0.997, 1.0, 0.9 };
float colors_g[4] = { 0.2, 0.875, 1.0, 0.6 };
float colors_b[4] = { 0.1, 0.763, 1.0, 0.3 };
float colors_g[4] = { 0.2, 0.875, 1.0, 0.5 };
float colors_b[4] = { 0.1, 0.763, 1.0, 0.1 };
// 1: 0.5, 0.74, 0.79
DEBUG20(":: font init label-a");
@ -448,33 +448,6 @@ void game_font_term() {
};
void game_textout_init(int set_to_ortho, int font_index) {
// CHECK_GL("textout init: start");
//
// glDisable(GL_DEPTH_TEST);
// CHECK_GL("textout init: disable depth test");
//
// rs_sh_use(game.text_shader);
// CHECK_GL("textout init: use text shader");
// glBindTexture(GL_TEXTURE_2D, game.font_texture[font_index]);
// CHECK_GL("textout init: glBindTexture");
// glUniform1i( game.text_shader[RS_SH_SAMPLER0_ID], 0 );
// if (set_to_ortho) {
// rs_mx_ortho1h_proj();
// }
//
// CHECK_GL("textout init: label d");
//
// glUniformMatrix4fv( game.text_shader[RS_SH_PROJ_ID], 1, GL_FALSE, rs_reg.mx_proj );
//
// CHECK_GL("textout init: label e");
//
// glUniform4f( game.text_shader[RS_SH_COLOR_ID], 0.0, 0.0, 0.0, 0.0 );
//
// CHECK_GL("textout init: end");
};
//float game_colors[4*7] = {
@ -503,63 +476,6 @@ void game_textout_adv(rs_texture_t *dest, int x, int y, int font_index, int draw
i++;
};
// for (i = 0; i < 8; i++) {
// texture_draw(&game.framebuffer, &game.tex_font[i], 40+8+game.tx+i*game.tex_font[i].w, 80+game.ty, DRAW_MODE_ALPHA);
// }
// //char *s = "12345_QUICK_BROWN_FOX_JUMPS_OVER_A_LAZY_DOG";
//
// float w = 2.0*h/3.0;
// int len = strlen(s);
//
// x -= (float) align * 0.5 * len * w;
//
// float sx = 0.0;
// float sy = 0.0;
//
//
//
// int i;
// for (i = 0; i < len; i++) {
// unsigned char c = s[i];
//
// if (c == '\n') {
// sx = 0.0;
// sy += h;
// continue;
// };
//
// if (c == ' ') {
// sx += w;
// continue;
// };
//
// c = (c-48)%64;
// float tx = 1.0 / 8.0 * (c % 8);
// float ty = 1.0 / 8.0 * (c / 8);
//
// glUniform4fv( game.text_shader[RS_SH_SCALE_ID], 1, &(game_colors[4*0]) ); // black shadow
// glrsDrawRect_full(sx + x + h/12,
// sy + y-h/2 + h/12,
// sx + x + w + h/12,
// sy + y+h/2 + h/12,
// tx, ty, tx+1.0/8.0, ty+1.0/8.0,
// game.text_shader[RS_SH_POS_ID], game.text_shader[RS_SH_UV_ID],
// 0.0, 0.0, 0.0 );
//
// glUniform4fv( game.text_shader[RS_SH_SCALE_ID], 1, &(game_colors[4*color]) );
//// glUniform3f( game.text_shader[RS_SH_TIME_ID], 1.0, 1.0, 0.0 );
// glrsDrawRect_full(sx + x,
// sy + y-h/2,
// sx + x + w,
// sy + y+h/2,
// tx, ty, tx+1.0/8.0, ty+1.0/8.0,
// game.text_shader[RS_SH_POS_ID], game.text_shader[RS_SH_UV_ID],
// 0.0, 0.0, 0.0 );
// sx += w;
// }
};

View File

@ -30,6 +30,5 @@ void game_font_term();
void game_textout(int x, int y, int font_index, char* s);
void game_textout_adv(rs_texture_t *dest, int x, int y, int font_index, int draw_mode, char* s);
//void game_textout_init(int set_to_ortho, int font_index);
#endif