Subversion Repositories Kolibri OS

Rev

Rev 1811 | Blame | Compare with Previous | Last modification | View Log | Download | RSS feed

  1.  
  2. #include "system/kolibri.h"
  3. #include "system/stdlib.h"
  4. #include "system/string.h"
  5.  
  6. #include "system/gblib.h"
  7.  
  8. #include "car_01.h"
  9. #include "car_02.h"
  10. #include "donkey_01.h"
  11. #include "donkey_02.h"
  12. #include "az.h"
  13.  
  14. char STR_DONKEY[] = {"D O N K E Y  0.8"};
  15.  
  16. int start, paintbg, pause;
  17. int dox, doy;
  18. int drx, dry;
  19.  
  20. int drn, don;
  21.  
  22. int speed;
  23.  
  24. char snd_ok[]={0x08, 0x89, 0x0f, 0};
  25. char snd_game_over[]={0x08, 0xa9, 0x0f, 0x09, 0x99, 0x0f, 0x11, 0x59, 0x0f, 0};
  26.  
  27.  
  28. GB_BMP screen, font, car01, car02, donkey01, donkey02, az;
  29.  
  30.  
  31. void az_putc(unsigned char c, int x, int y)
  32. {
  33. gb_image_set_t(&screen, x, y, &az, (c-'!')*11, 0, 11, 16, 0);
  34. }
  35.  
  36.  
  37.  
  38. void az_puts(unsigned char *s, int x, int y)
  39. {
  40. unsigned i;
  41. i = 0;
  42. while (*(s+i))
  43.         {
  44.         az_putc(*(s+i), x+i*11, y);
  45.         i++;
  46.         }
  47.  
  48. }
  49.  
  50.  
  51.  
  52. void game_start()
  53. {
  54. drx = -1;
  55. dry = 0;
  56. doy = random(40)+130;
  57.  
  58. dox = random(1);
  59. if (0 == dox)
  60.         dox--;
  61.  
  62. drn = don = 0;
  63. paintbg = 1;
  64.  
  65. speed = 0;
  66.  
  67. kol_sleep(30);
  68. }
  69.  
  70.  
  71. void screen_back()
  72. {
  73.  
  74. gb_bar(&screen, 0, 0, 320, 200, 0x888888);
  75.  
  76. gb_bar(&screen, 6, 6, 97-6, 195-6, 0x488888);
  77. gb_bar(&screen, 183, 6, 305-183, 195-6, 0x488888);
  78.  
  79. az_puts("Donkey", 6, 30);
  80. az_puts("Driver", 189, 30);
  81.  
  82. az_putc (don+'0', 5, 48);
  83. az_putc (drn/10+'0', 189, 48);
  84.  
  85. az_puts("Keys:", 189, 95);
  86. az_puts("Space Bar", 189, 116);
  87. az_puts("Enter", 189, 132);
  88. az_puts("Esc", 189, 148);
  89.  
  90.  
  91. gb_line(&screen, 100, 0, 100, 199, 0xffffff);
  92. gb_line(&screen, 180, 0, 180, 199, 0xffffff);
  93.  
  94. paintbg = 0;
  95. }
  96.  
  97.  
  98.  
  99. void screen_draw()
  100. {
  101.  
  102. int y;
  103.  
  104. if (-1 == pause)
  105.         {
  106.         screen_back();
  107.  
  108.         gb_bar(&screen, 4, 20, 255, 60, 0xee0000);
  109.         az_puts ("P A U S E", 5, 30);
  110.         az_puts ("Press Enter to continue", 5, 60);
  111.  
  112.         kol_screen_wait_rr();
  113.         kol_paint_image( 0, 0, 320, 200, screen.bmp);
  114.  
  115.         paintbg = 1;
  116.         return;
  117.         }
  118.  
  119. if (don > 9)
  120.         {
  121.         gb_bar(&screen, 0, 0, 320, 200, 0x880000);
  122.         az_puts ("G A M E    O V E R", 5, 30);
  123.  
  124.         kol_screen_wait_rr();
  125.         kol_paint_image( 0, 0, 320, 200, screen.bmp);
  126.  
  127.         kol_sleep(150);
  128.         game_start();
  129.         start = 1;
  130.         }
  131.  
  132. if (drn > 99)
  133.         {
  134.         gb_bar(&screen, 0, 0, 320, 200, 0x88);
  135.         az_puts ("CONGRATULATIONS !!!", 5, 30);
  136.  
  137.         kol_screen_wait_rr();
  138.         kol_paint_image( 0, 0, 320, 200, screen.bmp);
  139.  
  140.         kol_sleep(150);
  141.         game_start();
  142.         start = 1;
  143.         }
  144.  
  145. if (drn > 9)
  146.         speed = 1;
  147.  
  148. if (drn > 84)
  149.         speed = 2;
  150.  
  151.  
  152. if (start)
  153.         {
  154.         if (!paintbg)
  155.                 return;
  156.  
  157.         gb_bar(&screen, 0, 0, 320, 200, 0x55);
  158.  
  159.         az_puts ( STR_DONKEY, 5, 30);
  160.         az_puts ("remake for KolibriOS", 5, 78);
  161.         az_puts ("by Albom", 5, 78+16);
  162.  
  163.         az_puts ("Press Space Bar", 5, 140);
  164.         az_puts ("to continue", 5, 156);
  165.  
  166.  
  167.         kol_screen_wait_rr();
  168.         kol_paint_image( 0, 0, 320, 200, screen.bmp);
  169.         paintbg = 0;
  170.         return;
  171.         }
  172.  
  173. if (paintbg)
  174.         screen_back();
  175. else
  176.         gb_bar(&screen, 102, 0, 180-102, 200, 0x888888);
  177.  
  178. for (y=10; y<180; y+=20)
  179.         gb_line(&screen, 140, y-10*(doy%2), 140, y+10-10*(doy%2), 0xffffff);
  180.  
  181. doy-=5;
  182. if (doy < -50)
  183.         {
  184.  
  185.         dox = random(1);
  186.         if (0 == dox)
  187.                 dox--;
  188.  
  189.         doy = random(40)+130;
  190.         dry += 10;
  191.         drn++;
  192.         if (0 == drn%10)
  193.                 dry = 0;
  194.         paintbg = 1;
  195.         }
  196.  
  197. if ((drx == dox)&&(dry > doy-15)&&(dry < doy+15))
  198.         {
  199.         kol_sound_speaker(snd_game_over);
  200.         don++;
  201.         dry = 0;
  202.         drn /= 10;
  203.         drn *= 10;
  204.         for (y = 0; y<2; y++)
  205.                 {
  206.                 kol_sleep(8);
  207.                 screen_back();
  208.                 az_puts("BOOM!", 6, 120);
  209.  
  210.                 gb_image_set_t(&screen, 140-13-(y+1)*20, 120-dry+(y+1)*20, &car01, 0, 0, 13, 34, 0x888888);
  211.                 gb_image_set_t(&screen, 120+(y+3)*20, 120-dry+(y+1)*20, &car02, 0, 0, 13, 34, 0x888888);
  212.  
  213.                 gb_image_set_t(&screen, 140-17-(y+1)*20, 120-(y+1)*20, &donkey01, 0, 0, 17, 17, 0x888888);
  214.                 gb_image_set_t(&screen, 140+(y+3)*20, 120-(y+1)*20, &donkey02, 0, 0, 13, 17, 0x888888);
  215.  
  216.                 kol_screen_wait_rr();
  217.                 kol_paint_image(0, 0, 320, 200, screen.bmp);
  218.                 }
  219.  
  220.         dox = random(1);
  221.         if (0 == dox)
  222.                 dox--;
  223.  
  224.         doy = random(40)+130;
  225.         paintbg = 1;
  226.         }
  227.  
  228. gb_image_set_t(&screen, 140-13-drx*20, 130-dry, &car01, 0, 0, 13, 34, 0x888888);
  229. gb_image_set_t(&screen, 140-drx*20, 130-dry, &car02, 0, 0, 13, 34, 0x888888);
  230.  
  231. gb_image_set_t(&screen, 140-17-dox*20, 130-doy, &donkey01, 0, 0, 17, 17, 0x888888);
  232. gb_image_set_t(&screen, 140-dox*20, 130-doy, &donkey02, 0, 0, 13, 17, 0x888888);
  233.  
  234. kol_screen_wait_rr();
  235. kol_paint_image(0, 0, 320, 200, screen.bmp);
  236.  
  237. }
  238.  
  239.  
  240.  
  241. void wnd_draw()
  242. {
  243. kol_paint_start();
  244. kol_wnd_define(280, 200, 328, 204+kol_skin_height(), 0x34888888, 0x34888888, STR_DONKEY);
  245. screen_draw();
  246. kol_paint_end();
  247. }
  248.  
  249.  
  250.  
  251.  
  252. void kol_main()
  253. {
  254.  
  255. unsigned event;
  256. unsigned key;
  257.  
  258. srand(kol_system_time_get()<<8);
  259. start = 1;
  260. paintbg = 1;
  261.  
  262. pause = 1;
  263.  
  264. speed = 0;
  265.  
  266. screen.bmp = malloc(320*200*3);
  267. screen.w = 320;
  268. screen.h = 200;
  269.  
  270. car01.bmp = CAR_01;
  271. car01.w = 13;
  272. car01.h = 34;
  273.  
  274. car02.bmp = CAR_02;
  275. car02.w = 13;
  276. car02.h = 34;
  277.  
  278. donkey01.bmp = DONKEY_01;
  279. donkey01.w = 17;
  280. donkey01.h = 17;
  281.  
  282. donkey02.bmp = DONKEY_02;
  283. donkey02.w = 13;
  284. donkey02.h = 17;
  285.  
  286. az.bmp = AZ;
  287. az.w = 1012;
  288. az.h = 16;
  289.  
  290.  
  291. wnd_draw();
  292.  
  293. for (;;)
  294.         {
  295.  
  296.         kol_sleep(6-speed);
  297.         screen_draw();
  298.         event = kol_event_check();
  299.  
  300.         switch (event)
  301.                 {
  302.                 case 1:
  303.                         paintbg = 1;
  304.                         wnd_draw();
  305.                         break;
  306.  
  307.                 case 2:
  308.                         key = (kol_key_get() & 0xff00)>>8;
  309.                         if (start && (32==key))
  310.                                 {
  311.                                 start = 0;
  312.                                 game_start();
  313.                                 screen_draw();
  314.                                 break;
  315.                                 }
  316.  
  317.                         if (27 == key)
  318.                                 {
  319.                                 if (-1 == pause)
  320.                                         break;
  321.                                 start = 1;
  322.                                 paintbg = 1;
  323.                                 break;
  324.                                 }
  325.  
  326.                         if (32 == key)
  327.                                 {
  328.                                 if (-1 == pause)
  329.                                         break;
  330.  
  331.                                 kol_sound_speaker(snd_ok);
  332.  
  333.                                 drx *= -1;
  334.                                 screen_draw();
  335.                                 }
  336.  
  337.                         if ((!start) && (13 == key))
  338.                                 {
  339.                                 pause *= -1;
  340.                                 screen_draw();
  341.                                 }
  342.  
  343.  
  344.                         break;
  345.  
  346.                 case 3:
  347.                         if ( 1 == (kol_btn_get() & 0xff00)>>8 )
  348.                                 kol_exit();
  349.                         break;
  350.  
  351.                 };
  352.         }
  353.  
  354. }
  355.