Subversion Repositories Kolibri OS

Rev

Rev 5243 | Go to most recent revision | Blame | Compare with Previous | Last modification | View Log | Download | RSS feed

  1. #include "rsgamedraw.h"
  2. #include "rsgametext.h"
  3. #include "rsgamemenu.h"
  4.  
  5. #include "rsgentex.h"
  6. #include "rs/rsplatform.h"
  7.  
  8. #include "rskos.h"
  9.  
  10. #include "rsnoise.h"
  11.  
  12. #include "strings.h"
  13.  
  14.  
  15. void game_draw() {
  16.  
  17.         int w = GAME_WIDTH;
  18.         int h = GAME_HEIGHT;
  19.        
  20.         int continue_need_redraw = 0;
  21.        
  22.         if (game.need_redraw) {
  23. //    if (1) {
  24.    
  25.        
  26.  
  27.         if ( (game.status == STATUS_MENU) || (game.status == STATUS_LOADING) ) {
  28.                
  29.             texture_draw(&game.framebuffer, &game.tex_bg, 0, 0, DRAW_MODE_REPLACE);
  30.            
  31.                  
  32.             if (game.status == STATUS_LOADING) {
  33.                 game_textout_at_center( 0, 240, 0, L_LOADING );
  34.                 game_textout_at_center( -3, 240-2, 3, L_LOADING );
  35.             }
  36.             else {
  37.  
  38.                 texture_draw( &game.framebuffer, &game.tex_logo, 0, 50, DRAW_MODE_ALPHA );
  39.  
  40.                 if (game.score) {
  41.                    
  42.                    
  43.                     game_textout_at_center( 0, 230, 0, L_GAME_OVER );
  44.                     game_textout_at_center( -3, 230-2, 3, L_GAME_OVER );
  45.                    
  46.                     char s[] = L_SCORE;
  47.                     char *str_num;
  48.                     str_num = strchr(s, 'x');
  49.                     str_num[0] = '0' + ( (game.score / 100) % 10);
  50.                     str_num[1] = '0' + ( (game.score / 10) % 10);
  51.                     str_num[2] = '0' + ( (game.score / 1) % 10);
  52.                    
  53.                     game_textout_at_center( 0, 260, 0, s );
  54.                     game_textout_at_center( -3, 260-2, 3, s );
  55.  
  56.                 };
  57.                
  58.                 if (!game.menu_replay_timeout) {
  59.                     game_textout_at_center( 0, 300, 0, L_START );
  60.                     game_textout_at_center( -3, 300-2, 3, L_START );
  61.                 };
  62.                
  63.                
  64.             };
  65.            
  66.             game_textout( 2, GAME_HEIGHT-10, 2,  L_BOTTOM_LINE_DEVELOPER_INFO);
  67.  
  68.        
  69.         }
  70.         else {
  71.                
  72.             texture_draw(&game.framebuffer, &game.tex_bg_gameplay, 0, 0, DRAW_MODE_REPLACE);
  73.            
  74.             int i, j, y_shift;
  75.             for (i = 0; i < FIELD_HEIGHT; i++) {
  76.                 for (j = 0; j < FIELD_WIDTH; j++) {
  77.                     if ( IS_BIT_SET( game.field[i*FIELD_WIDTH + j], CRYSTAL_VISIBLE_BIT )) {
  78.                         y_shift = 0;
  79.                         if ( IS_BIT_SET( game.field[i*FIELD_WIDTH + j], CRYSTAL_MOVING_BIT ) ) {
  80.                             y_shift = -CRYSTAL_SIZE + CRYSTAL_SIZE*(game.process_timer+1)/(ANIMATION_PROCESS_TIMER_LIMIT+1);
  81.                             continue_need_redraw = 1;
  82.                         };
  83.                         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 );
  84.                     };
  85.                 };
  86.             };
  87.            
  88.             if (game.selected) {
  89.                 texture_draw( &game.framebuffer, &game.tex_cursor, FIELD_X0+ game.selected_x*CRYSTAL_SIZE, FIELD_Y0+ game.selected_y*CRYSTAL_SIZE, DRAW_MODE_ALPHA );
  90.             };
  91.            
  92.            
  93.             for (i = 0; i < game.explosions_count; i++) {
  94.                 texture_draw( &game.framebuffer, &(game.tex_explosion[  (game.explosions[i]>>16) & 0xFF  ]),
  95.                     FIELD_X0 + CRYSTAL_SIZE*( game.explosions[i] & 0xFF) - (EXPLOSION_SIZE-CRYSTAL_SIZE)/2 ,
  96.                     FIELD_Y0 + CRYSTAL_SIZE*( (game.explosions[i]>>8) & 0xFF) - (EXPLOSION_SIZE-CRYSTAL_SIZE)/2 ,
  97.                     DRAW_MODE_ALPHA);
  98.             };
  99.  
  100.  
  101.  
  102.             int blink_visible = 0;
  103.             if (game.time > 10*25) {
  104.                 blink_visible = 1;
  105.             }
  106.             else if (game.time > 5*25) {
  107.                 blink_visible = (game.time / 8) & 1;
  108.                 continue_need_redraw = 1;
  109.             }
  110.             else {
  111.                 blink_visible = (game.time / 4) & 1;
  112.                 continue_need_redraw = 1;
  113.             };
  114.            
  115.             char *str_num;
  116.             if (blink_visible) {
  117.  
  118.                 char str[] = L_TIME;
  119.                 int time_sec = game.time / 25;
  120.                 str_num = strchr(str, 'x');
  121.                 str_num[0] = '0' + ( (time_sec / 10) % 10);
  122.                 str_num[1] = '0' + ( (time_sec / 1) % 10);
  123. //                str_num[2] = '0' + ( (time_sec / 1) % 10);
  124.                
  125.                 game_textout( 56+3, 32+2, 0, str );
  126.                 game_textout( 56, 32, 3, str );
  127.             };
  128.            
  129.            
  130.             char sstr[] = L_SCORE;
  131.             str_num = strchr(sstr, 'x');
  132.             str_num[0] = '0' + ( (game.score / 100) % 10);
  133.             str_num[1] = '0' + ( (game.score / 10) % 10);
  134.             str_num[2] = '0' + ( (game.score / 1) % 10);
  135.            
  136.             game_textout( 56+3, 64+2, 0, sstr );
  137.             game_textout( 56, 64, 3, sstr );
  138.    
  139.         };
  140.  
  141.  
  142. //        rskos_draw_area(0, 0, w, h, game.window_scale, game.framebuffer.data, NULL, RSKOS_BGRA);
  143.         rskos_draw_area(0, 0, w, h, 1, game.framebuffer.data, game.bgr_framebuffer, 0);
  144.         };
  145.        
  146.         if (!continue_need_redraw) {
  147.         game.need_redraw = 0;
  148.         };
  149.  
  150. };
  151.  
  152.  
  153.  
  154. void game_textures_init_stage1() {
  155.    
  156.     int i;
  157.    
  158.     texture_init(&game.framebuffer, GAME_WIDTH, GAME_HEIGHT);
  159.    
  160. //    texture_init(&game.tex, 64, 64);
  161. //    rs_gen_init(1, 64);
  162. //    rs_gen_func_set(0, 0.0);
  163. //    rs_gen_func_cell(0, 1200, 10, NULL, 1.0, 1.0, 1.0, 1.0, 0.0, 1.0);
  164. //    rs_gen_func_normalize(0, 0.0, 1.0);
  165. //    rs_gen_func_posterize(0, 5);
  166. //    rs_gen_tex_out_rgba(0, 0, 0, -1, 1.0, 1.0, 1.0, 1.0);
  167. //    memcpy(game.tex.data, rs_gen_reg.tex_out, 64*64*4 );
  168. //    rs_gen_term();
  169.    
  170.     texture_init(&game.tex_clouds, 128, 128);
  171.     rs_gen_init(1, 128);
  172.     rs_gen_func_perlin(0, 8, 5, 0.5, 1100);
  173.     rs_gen_func_normalize(0, 0.0, 1.0);
  174.     rs_gen_func_posterize(0, 6);
  175.     rs_gen_func_mult_add_value(0, 0, 0.6, 0.4);
  176. //    rs_gen_func_set(0, 1.0);
  177.     rs_gen_tex_out_rgba(0, 0, 0, -1, 1.0, 1.0, 1.0, 1.0);
  178.     memcpy(game.tex_clouds.data, rs_gen_reg.tex_out, 128*128*4 );
  179.     rs_gen_term();
  180.  
  181.  
  182.     rs_texture_t tex_shadow;
  183.     texture_init(&tex_shadow, 64, 64);
  184.     rs_gen_init(1, 64);
  185.     rs_gen_func_perlin(0, 21, 6, 0.5, 1000);
  186.     rs_gen_func_normalize(0, 0.0, 0.5);
  187.     rs_gen_tex_out_rgba(0, 0, 0, -1, 1.0, 1.0, 1.0, 1.0);
  188.     memcpy(tex_shadow.data, rs_gen_reg.tex_out, 64*64*4 );
  189.     rs_gen_term();
  190.    
  191.    
  192.  
  193.     texture_init(&game.tex_logo, GAME_WIDTH, 128);
  194.     texture_clear(&game.tex_logo, COLOR_TRANSPARENT);
  195.    
  196.     game_textout_adv( &game.tex_logo, GAME_WIDTH/2 - 192, 4, 1, DRAW_MODE_REPLACE, "MARBLE");
  197.     game_textout_adv( &game.tex_logo, GAME_WIDTH/2 - 192, 63, 1, DRAW_MODE_REPLACE, "MATCH3");
  198.     texture_draw(&game.tex_logo, &tex_shadow, 0, 0, DRAW_MODE_MULT | DRAW_TILED_FLAG);
  199.     game_textout_adv( &game.tex_logo, GAME_WIDTH/2 - 192 - 5, 0, 1, DRAW_MODE_ALPHA, "MARBLE");
  200.     game_textout_adv( &game.tex_logo, GAME_WIDTH/2 - 192 - 4, 60, 1, DRAW_MODE_ALPHA, "MATCH3");
  201.     texture_draw(&game.tex_logo, &game.tex_clouds, 0, 0, DRAW_MODE_MULT | DRAW_TILED_FLAG);
  202.    
  203.     texture_free(&tex_shadow);
  204.  
  205.    
  206.     texture_init(&game.tex_bg, 512, 512);
  207.     texture_clear(&game.tex_bg, COLOR_SILVER);
  208.  
  209.     texture_init(&game.tex_bg_gameplay, 512, 512);
  210.     texture_clear(&game.tex_bg_gameplay, COLOR_SILVER);
  211.    
  212.     texture_init(&game.tex_cursor, CRYSTAL_SIZE, CRYSTAL_SIZE);
  213.     rs_gen_init(2, CRYSTAL_SIZE);
  214.    
  215.     rs_gen_func_set(0, 0.0); // inner
  216.     rs_gen_func_radial(0, 0.5, 0.5, 0.5, 1.0, 2.0);
  217.     rs_gen_func_clamp(0, 0.1, 0.5);
  218.     rs_gen_func_normalize(0, 0.0, 1.0);
  219.     rs_gen_func_mult_add_value(0, 0, -1.0, 1.0);
  220.  
  221.     rs_gen_func_set(1, 0.0); // outer
  222.     rs_gen_func_radial(1, 0.5, 0.5, 0.5, 1.0, 2.0);
  223.     rs_gen_func_clamp(1, 0.0, 0.2);
  224.     rs_gen_func_normalize(1, 0.0, 1.0);
  225.    
  226.     rs_gen_func_mult(0, 0, 1);
  227.  
  228.     rs_gen_func_set(1, 1.0);
  229. //    rs_gen_tex_out_rgba_set(0.0, 0.0, 0.0, 0.0);
  230.     rs_gen_tex_out_rgba(1, 1, 1, 0, 1.0, 1.0, 1.0, 1.0);
  231.     memcpy(game.tex_cursor.data, rs_gen_reg.tex_out, CRYSTAL_SIZE*CRYSTAL_SIZE*4 );
  232.     rs_gen_term();
  233.  
  234.     texture_init(&game.tex_field, FIELD_WIDTH*CRYSTAL_SIZE + 7, FIELD_HEIGHT*CRYSTAL_SIZE + 7);
  235.     texture_clear(&game.tex_field, 0xAABBBBBB); // 0x66404060 // 0xAACCCCCC
  236.  
  237.    
  238. //    float cr_r[CRYSTALS_COUNT] = { 0.8, 0.2, 0.1, 0.6, 0.7, 0.0, 0.7 };
  239. //    float cr_g[CRYSTALS_COUNT] = { 0.1, 0.6, 0.4, 0.0, 0.6, 0.0, 0.8 };
  240. //    float cr_b[CRYSTALS_COUNT] = { 0.1, 0.1, 0.7, 0.7, 0.0, 0.3, 0.9 };
  241.  
  242. //    float cr_r[CRYSTALS_COUNT] = { 0.9, 0.3, 0.1, 0.7, 0.8, 0.0, 0.8 };
  243. //    float cr_g[CRYSTALS_COUNT] = { 0.1, 0.8, 0.5, 0.0, 0.7, 0.0, 0.8 };
  244. //    float cr_b[CRYSTALS_COUNT] = { 0.0, 0.1, 0.9, 0.8, 0.0, 0.5, 0.9 };
  245.    
  246.     float cr_r[CRYSTALS_COUNT] = { 1.0, 0.4, 0.10, 0.9, 1.0, 0.2, 0.8 };
  247.     float cr_g[CRYSTALS_COUNT] = { 0.1, 1.0, 0.75, 0.1, 0.9, 0.2, 0.8 };
  248.     float cr_b[CRYSTALS_COUNT] = { 0.0, 0.1, 1.00, 1.0, 0.1, 0.9, 0.9 };
  249.    
  250.  
  251. //    rs_gen_init(5, CRYSTAL_SIZE);
  252. //    for (i = 0; i < CRYSTALS_COUNT; i++) {
  253. //        texture_init(&(game.tex_crystals[i]), CRYSTAL_SIZE, CRYSTAL_SIZE);
  254. //        
  255. //        rs_gen_func_set(0, 0.0);
  256. //        rs_gen_func_radial(0, 0.5, 0.5, 0.5, 0.75, 10.0);
  257. //        
  258. //        rs_gen_func_set(1, 0.0);
  259. //        rs_gen_func_cell(1, 110+100*i, 7+i, NULL, 1.0, 1.0, 0.0, 1.0, 0.0, 1.0);
  260. //        rs_gen_func_normalize(1, 0.0, 1.0);
  261. //        
  262. //        rs_gen_tex_out_rgba_set(0.0, 0.0, 0.0, 0.0);
  263. //        rs_gen_tex_out_rgba(1, 1, 1, 0, cr_b[i], cr_g[i], cr_r[i], 1.0);
  264. //
  265. //        memcpy(game.tex_crystals[i].data, rs_gen_reg.tex_out, CRYSTAL_SIZE*CRYSTAL_SIZE*4 );
  266. //    };
  267. //    rs_gen_term();
  268.    
  269.     rs_gen_init(5, CRYSTAL_SIZE);
  270.     for (i = 0; i < CRYSTALS_COUNT; i++) {
  271.         texture_init(&(game.tex_crystals[i]), CRYSTAL_SIZE, CRYSTAL_SIZE);
  272.        
  273.         rs_gen_func_set(0, 0.0);
  274.         rs_gen_func_radial(0, 0.5, 0.5, 0.5, 0.75, 10.0);
  275.        
  276.         rs_gen_func_set(1, 1.0);
  277.         rs_gen_func_cell(1, 310+100*i, 5, NULL, -0.5, 1.0, 1.0, 0.0, -2.0, 2.0);
  278.         rs_gen_func_normalize(1, 0.0, 1.0);
  279.        
  280.         rs_gen_func_normalmap(2, 3, 4, 1, 1.0);
  281.         rs_gen_func_mult_add_value(3, 3, -1.0, 1.0);
  282.        
  283.         rs_gen_func_clamp(2, 0.5, 1.0);
  284.         rs_gen_func_normalize(2, 0.0, 1.0);
  285.         rs_gen_func_clamp(3, 0.5, 1.0);
  286.         rs_gen_func_normalize(3, 0.0, 1.0);
  287.        
  288.         rs_gen_func_add(4, 2, 3, 0.5, 0.5);
  289.         rs_gen_func_mult(1, 1, 4);
  290.         rs_gen_func_normalize(1, 0.0, 1.0);
  291.        
  292.         rs_gen_tex_out_rgba_set(0.0, 0.0, 0.0, 0.0);
  293.         rs_gen_tex_out_rgba(1, 1, 1, 0, cr_b[i], cr_g[i], cr_r[i], 1.0);
  294. //        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);
  295. //        rs_gen_tex_out_rgba(1, 1, 1, 0, 1.0, 1.0, 1.0, 1.0);
  296.  
  297.         memcpy(game.tex_crystals[i].data, rs_gen_reg.tex_out, CRYSTAL_SIZE*CRYSTAL_SIZE*4 );
  298.     };
  299.     rs_gen_term();
  300.    
  301.    
  302.    
  303.     rs_gen_init(3, EXPLOSION_SIZE);
  304.     for (i = 0; i < EXPLOSION_FRAMES_COUNT; i++) {
  305.            
  306.         texture_init(&(game.tex_explosion[i]), EXPLOSION_SIZE, EXPLOSION_SIZE);
  307.  
  308.         rs_gen_func_set(0, 1.0);
  309. //        rs_gen_func_radial(0, 0.5, 0.5, 0.3 + 0.5*i/EXPLOSION_FRAMES_COUNT, 0.975, 4.0);
  310. //        rs_gen_func_set(0, 1.0);
  311.  
  312.         rs_gen_func_set(1, 0.0);
  313.         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);
  314.  
  315.         rs_gen_tex_out_rgba_set( 0.0, 0.0, 0.0, 0.0);
  316.         rs_gen_tex_out_rgba(0, 0, 0, 1, 1.0, 1.0, 1.0, 1.0);
  317.  
  318.         memcpy(game.tex_explosion[i].data, rs_gen_reg.tex_out, EXPLOSION_SIZE*EXPLOSION_SIZE*4 );
  319.     };
  320.     rs_gen_term();
  321. };
  322.  
  323. void game_textures_init_stage2() {
  324.      
  325. //            texture_clear(&game.tex_bg, COLOR_SILVER);
  326. //             /*
  327.        
  328.     rs_gen_init(6, 512);
  329.     rs_gen_func_perlin(0, 8, 5, 0.5, 1100);
  330.     rs_gen_func_normalize(0, 0.0, 1.0);
  331.     rs_gen_func_perlin(1, 8, 5, 0.5, 1700);
  332.     rs_gen_func_normalize(1, 0.0, 1.0);
  333.     rs_gen_func_cell(2, 1118, 50, NULL, 1.0, 0.887, -0.333, 1.0, 0.0, 4.0); // 1360
  334.     rs_gen_func_normalize(2, 0.0, 0.5);
  335.  
  336.     rs_gen_func_adr(3, 2, 0, 1, 1.0, 0.3);
  337.    
  338.     rs_gen_func_inv(3, 3, 7.5);
  339.     rs_gen_func_normalize(3, 0.0, 1.0);
  340.  
  341. //            signed short c[] = { 0, 250, 250, 0, 500, 250, 250, 500};
  342.     signed short c[] = { 0, 0, 0, 512, 512, 0, 512, 512};
  343. //            signed short c[] = { 128, 128, 128, 384, 384, 128, 384, 384};
  344.     //rs_gen_func_cell(4, 0, 4, c, 0.0, 0.3, 1.0, 0.5, 0.0, 0.30);
  345.     rs_gen_func_cell(4, 0, 4, c, 1.0, 0.3, 0.0, 0.95, 0.0, 0.30);
  346.     rs_gen_func_normalize(4, 0.0, 1.0);
  347.  
  348. //            rs_gen_func_radial(5, 0.5, 0.5, 0.60, 1.0, 4.0);
  349. //            rs_gen_func_add(4, 4, 5, 0.5, 0.5);
  350. //
  351.     rs_gen_func_mult(4, 4, 3);
  352.    
  353.     // coloring...
  354.     rs_gen_func_mult_add_value(0, 4, 0.8, 0.0);
  355.     rs_gen_func_add(0, 4, 1, 0.95, 0.05);
  356.     rs_gen_func_add(3, 4, 2, 0.95, 0.05);
  357.  
  358.    
  359.     rs_gen_tex_out_rgba(4, 0, 3, -1, 0.9, 0.9, 0.9, 1.0);
  360.     memcpy(game.tex_bg.data, rs_gen_reg.tex_out, 512*512*4 );
  361.     rs_gen_term();
  362.    
  363.     // */
  364.    
  365.     // Background for gameplay
  366.    
  367.     texture_draw( &game.tex_bg_gameplay, &game.tex_bg, 256, 256, DRAW_MODE_REPLACE | DRAW_TILED_FLAG );
  368.     // Bevel
  369.     texture_draw_vline( &game.tex_bg_gameplay, FIELD_X0 - 5, FIELD_Y0 - 5, FIELD_HEIGHT*CRYSTAL_SIZE + 10, 0xFF404060 );
  370.     texture_draw_hline( &game.tex_bg_gameplay, FIELD_X0 - 5, FIELD_Y0 - 5, FIELD_WIDTH*CRYSTAL_SIZE + 10, 0xFF404060 );
  371.     texture_draw_vline( &game.tex_bg_gameplay, FIELD_X0 - 4, FIELD_Y0 - 4, FIELD_HEIGHT*CRYSTAL_SIZE + 8, 0xFF606080 );
  372.     texture_draw_hline( &game.tex_bg_gameplay, FIELD_X0 - 4, FIELD_Y0 - 4, FIELD_WIDTH*CRYSTAL_SIZE + 8, 0xFF606080 );
  373.    
  374.     texture_draw_vline( &game.tex_bg_gameplay, FIELD_X0 + 4 + FIELD_WIDTH*CRYSTAL_SIZE, FIELD_Y0 - 4, FIELD_HEIGHT*CRYSTAL_SIZE + 8, 0xFFC0C0C0 );
  375.     texture_draw_hline( &game.tex_bg_gameplay, FIELD_X0 - 4, FIELD_Y0 + 4 + FIELD_HEIGHT*CRYSTAL_SIZE, FIELD_WIDTH*CRYSTAL_SIZE + 9, 0xFFC0C0C0 );
  376.     texture_draw_vline( &game.tex_bg_gameplay, FIELD_X0 + 5 + FIELD_WIDTH*CRYSTAL_SIZE, FIELD_Y0 - 5, FIELD_HEIGHT*CRYSTAL_SIZE + 10, 0xFFE0E0E0 );
  377.     texture_draw_hline( &game.tex_bg_gameplay, FIELD_X0 - 5, FIELD_Y0 + 5 + FIELD_HEIGHT*CRYSTAL_SIZE, FIELD_WIDTH*CRYSTAL_SIZE + 11, 0xFFE0E0E0 );
  378.    
  379.     texture_draw( &game.tex_bg_gameplay, &game.tex_field, FIELD_X0 - 3, FIELD_Y0 - 3, DRAW_MODE_ALPHA );
  380.    
  381.    
  382. };
  383.  
  384. void game_textures_free() {
  385.     free(game.bgr_framebuffer);
  386.    
  387.     //    texture_free(&game.tex_gui_line);
  388.    
  389.     int i;
  390.     for (i = 0; i < CRYSTALS_COUNT; i++) {
  391.         texture_free(&game.tex_crystals[i]);
  392.     };
  393.    
  394.     for (i = 0; i < EXPLOSION_FRAMES_COUNT; i++) {
  395.         texture_free(&game.tex_explosion[i]);
  396.     };
  397.    
  398.     texture_free(&game.framebuffer);
  399.    
  400.     texture_free(&game.tex_logo);
  401.     texture_free(&game.tex_clouds);
  402.    
  403.     texture_free(&game.tex_bg);
  404.     texture_free(&game.tex_bg_gameplay);
  405. };
  406.