Subversion Repositories Kolibri OS

Rev

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