Subversion Repositories Kolibri OS

Rev

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