Subversion Repositories Kolibri OS

Rev

Rev 5243 | Rev 5298 | 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 "rskos.h"
  6.  
  7. #include "rsnoise.h"
  8.  
  9. #include "strings.h"
  10.  
  11.  
  12. void game_draw() {
  13.  
  14.         int w = 320;
  15.         int h = 180;
  16.        
  17.  
  18.         int kk = 20; // (rskos_get_time()/1) % 160;
  19. //     
  20. //      unsigned char *c = game.framebuffer.data;
  21. //     
  22. //      int i;
  23. //      for (i = 0; i < w*h*4; i+=4) {
  24. //          c[i+0] = 10; //  i/w/3;
  25. //          c[i+1] = (( (1*i)*(i + kk)/70) & 5) ? 70 : 0;
  26. //          c[i+2] = 50;
  27. //          c[i+3] = i % 128;
  28. //      };
  29.  
  30.  
  31.     texture_clear(&game.framebuffer, COLOR_BLACK);
  32. //    texture_clear(&game.tex);
  33.    
  34. //    texture_draw(&game.framebuffer, &game.tex, 40, 40, DRAW_MODE_ADDITIVE);
  35. //    texture_draw(&game.framebuffer, &game.tex, 70, 50, DRAW_MODE_ADDITIVE);
  36. //    texture_draw(&game.framebuffer, &game.tex, 20, 60, DRAW_MODE_ADDITIVE);
  37. //    texture_draw(&game.framebuffer, &game.tex, 60, 70, DRAW_MODE_ADDITIVE);
  38. //    
  39. //    texture_draw(&game.framebuffer, &game.tex, 111, 150, DRAW_MODE_ADDITIVE);
  40.  
  41.     int i, c, c2, c3;
  42.     for (i = 0; i < 100; i++) {
  43. //        DEBUG10f("i = %d, v1 = %.4f, v2 = %.4f \n", i, rs_noise(kk+100, kk+i)*10, rs_noise(kk+200, kk+i+300)*10);
  44.         c = (0.5+0.45*rs_noise(kk+150, kk+i))*255;
  45.         c2 = c + 0.05*rs_noise(kk+150, kk+i)*255;
  46.         c3 = c2; // (0.5+0.49*rs_noise(kk+150, kk+i+2))*255;
  47.         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,
  48.                           c + (c2<<8) + (c3<<16) + 0xFF000000);
  49.     };
  50.  
  51.     texture_clear(&game.tex_ground, COLOR_TRANSPARENT);
  52.     rs_perlin_configure(47, 4, 0.5, 1000, 256);
  53.     for (i = 0; i < game.tex_ground.w; i++) {
  54.         texture_draw_vline(&game.tex_ground, i, 25 + rs_perlin(0,i+game.tz)*25, 2, 0xFF113300);
  55.         texture_draw_vline(&game.tex_ground, i, 25 + rs_perlin(0,i+game.tz)*25 + 2, 999, 0xFF000000);
  56.     };
  57.    
  58.    
  59.  
  60.     if (game.status == STATUS_MENU) {
  61.  
  62.         char **title = menu_titles[game.menu_index];
  63.         int y = (game.menu_index == MENU_MAIN) ? 80 : 50;
  64.         texture_draw(&game.framebuffer, &game.tex_gui_line, 0, y+15*game.menu_item_index, DRAW_MODE_ALPHA);
  65.         while (*title) {
  66.             game_textout(20, y, (*(title))[0]==' ' ? 3 : 0 , (*(title))+1 );  // first (zero) char defines action, title starts from second (1st) char
  67.             title++;
  68.             y+=15;
  69.         };
  70.        
  71.         if (game.menu_index == MENU_MAIN) {
  72.                
  73.             for (i = 0; i < 3; i++) {
  74.                 texture_draw(&game.framebuffer, &game.tex_rocks[i], 250+80*rs_noise(i,150), 60+60*rs_noise(i,1110), DRAW_MODE_ADDITIVE );
  75.             };
  76.                
  77.             game_textout( GAME_WIDTH/2 - 100, 40, 1,  "HELI0THRYX");
  78. //            game_textout( GAME_WIDTH/2 - 8, 58, 3,  "TECHDEM0");
  79.             game_textout( 2, GAME_HEIGHT-10, 2,  L_BOTTOM_LINE_DEVELOPER_INFO);
  80.         };
  81.    
  82.     }
  83.     else {
  84.        
  85.         int i, j;
  86.         game_obj_t *obj;
  87.         for (i = 0; i < game.objs_count; i++) {
  88.             obj = &(game.objs[i]);
  89.            
  90.             if (obj->obj_type == OBJ_BULLET) {
  91.                    
  92.                 texture_set_pixel(&game.framebuffer, obj->x-4, obj->y, 0xFF00BB00);
  93.                 texture_set_pixel(&game.framebuffer, obj->x-3, obj->y, 0xFF00CC00);
  94.                 texture_set_pixel(&game.framebuffer, obj->x-2, obj->y, 0xFF00DD00);
  95.                 texture_set_pixel(&game.framebuffer, obj->x-1, obj->y, 0xFF00EE00);
  96.                 texture_set_pixel(&game.framebuffer, obj->x-0, obj->y, 0xFF00FF00);
  97.                
  98.             }
  99.             else if (obj->obj_type == OBJ_RED_BULLET) {
  100.                    
  101.                 texture_set_pixel(&game.framebuffer, obj->x-1, obj->y-0, 0xFFFF0000);
  102.                 texture_set_pixel(&game.framebuffer, obj->x-1, obj->y-1, 0xFFFF6600);
  103.                 texture_set_pixel(&game.framebuffer, obj->x-1, obj->y-0, 0xFFFF0000);
  104.                 texture_set_pixel(&game.framebuffer, obj->x-0, obj->y-1, 0xFFFF0000);
  105.                 texture_set_pixel(&game.framebuffer, obj->x-0, obj->y-0, 0xFFFF6600);
  106.                 texture_set_pixel(&game.framebuffer, obj->x+1, obj->y-1, 0xFFFF0000);
  107.                 texture_set_pixel(&game.framebuffer, obj->x+1, obj->y-0, 0xFFFF6600);
  108.                
  109.             }
  110.             else if (obj->obj_type == OBJ_EXPLOSION) {
  111.                
  112. //                char s[] = "00 ";
  113. //                s[0] += obj->t / 10;
  114. //                s[1] += obj->t % 10;
  115. //                game_textout( obj->x, obj->y, 0, s );
  116.  
  117.                 texture_draw( &game.framebuffer, &game.tex_explosions[ obj->t ], obj->x - obj->radius, obj->y - obj->radius, DRAW_MODE_ALPHA );
  118.                
  119.             }
  120.             else if (obj->obj_type == OBJ_ROCK) {
  121.                 texture_draw( &game.framebuffer, &game.tex_rocks[ obj->tag ], obj->x - obj->radius, obj->y - obj->radius, DRAW_MODE_ALPHA );
  122.             }
  123.             else if (obj->obj_type == OBJ_MINIROCK) {
  124.                 texture_draw( &game.framebuffer, &game.tex_minirocks[ obj->tag ], obj->x - obj->radius, obj->y - obj->radius, DRAW_MODE_ALPHA );
  125.             }
  126.             else if (obj->obj_type == OBJ_TURRET) {
  127.                 texture_draw( &game.framebuffer, &game.tex_rocks[ 0 ], obj->x - obj->radius, obj->y - obj->radius, DRAW_MODE_ALPHA );
  128.                 texture_draw( &game.framebuffer, &game.tex_rocks[ 0 ], obj->x - obj->radius, obj->y - obj->radius, DRAW_MODE_ADDITIVE );
  129.                
  130.                 for (j = 0; j < 1 + (obj->tag)/6; j++) {
  131.                     texture_draw_vline(&game.framebuffer, obj->x - obj->radius + j*4 + 0, obj->y - obj->radius - 16, 8, 0xFF993333 );
  132.                     texture_draw_vline(&game.framebuffer, obj->x - obj->radius + j*4 + 1, obj->y - obj->radius - 16, 8, 0xFF993333 );
  133.                     texture_draw_vline(&game.framebuffer, obj->x - obj->radius + j*4 + 2, obj->y - obj->radius - 16, 8, 0xFF993333 );
  134.                 };
  135.                
  136.             }
  137.  
  138.         };
  139.        
  140.  
  141.         texture_draw(&game.framebuffer, &game.tex_ship[0], game.player_x-8, game.player_y-4, DRAW_MODE_ALPHA);
  142.         texture_draw(&game.framebuffer, &game.tex_ship[1], game.player_x-8, game.player_y-4, DRAW_MODE_ALPHA);
  143.         texture_draw(&game.framebuffer, &game.tex_ship[2], game.player_x, game.player_y-4, DRAW_MODE_ALPHA);
  144.         texture_draw(&game.framebuffer, &game.tex_ship[3], game.player_x, game.player_y-4, DRAW_MODE_ALPHA);
  145.        
  146.        
  147.         if ( game.stage == 0 ) {
  148.             game_textout_at_center( 0, GAME_HEIGHT + 50 - game.stage_timer*(GAME_HEIGHT+50)/50, 1, "LEVEL 1" );
  149.             game_textout_at_center( 0, GAME_HEIGHT*2/3, 2, L_TECHDEMO_LINE1 );
  150.         }
  151.         else {
  152.            
  153.             char s_score[] = "000";
  154.             s_score[0] += game.score / 100;
  155.             s_score[1] += (game.score / 10) % 10;
  156.             s_score[2] += (game.score / 1) % 10;
  157.            
  158.             game_textout_at_center(0, 10, 3, s_score);
  159.            
  160.            
  161.         };
  162.        
  163.        
  164.        
  165.        
  166.         char s_health[] = "HEALTH: 0 ";
  167.         char s_ammo[] = "AMM0: 00 ";
  168.        
  169.         s_health[8] += game.health;
  170.         s_ammo[6] += game.ammo / 10;
  171.         s_ammo[7] += game.ammo % 10;
  172.        
  173.         game_textout(8, 8, 2, s_health);
  174.         game_textout(GAME_WIDTH - 12 - GAME_AMMO_MAX*2 - 1, 8, 2, s_ammo);
  175.        
  176.         for (i = 0; i < game.ammo; i++) {
  177.             texture_draw_vline(&game.framebuffer, GAME_WIDTH - 12 - GAME_AMMO_MAX*2 + i*2, 20, 8, 0xFF3366FF );
  178.         };
  179.        
  180.         int health_color = 0xFF339933;
  181.         if (game.health < 5) {
  182.             health_color = 0xFF808010;
  183.         };
  184.         if (game.health < 3) {
  185.             health_color = 0xFFFF3300;
  186.         };
  187.  
  188.         for (i = 0; i < game.health; i++) {
  189.             texture_draw_vline(&game.framebuffer, 8 + i*4 + 0, 20, 8, health_color  );
  190.             texture_draw_vline(&game.framebuffer, 8 + i*4 + 1, 20, 8, health_color  );
  191.             texture_draw_vline(&game.framebuffer, 8 + i*4 + 2, 20, 8, health_color  );
  192.         };
  193.        
  194.  
  195.        
  196.        
  197. //        game_textout( 2, 12, 2, L_TECHDEMO_LINE2 );
  198.        
  199.     };
  200.  
  201.     texture_draw(&game.tex_ground, &game.tex_clouds, game.tz, 0, /* game.tx, game.ty, */ DRAW_MODE_ADDITIVE | DRAW_TILED_FLAG );
  202.     texture_draw(&game.framebuffer, &game.tex_ground, 0, GAME_HEIGHT-50, DRAW_MODE_ALPHA);
  203.  
  204.  
  205.         rskos_draw_area(0, 0, w, h, game.window_scale, game.framebuffer.data, game.scaled_framebuffer);
  206.  
  207. };
  208.  
  209.