Subversion Repositories Kolibri OS

Rev

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