?login_element?

Subversion Repositories NedoOS

Rev

Blame | Last modification | View Log | Download | RSS feed

  1. #include <evo.h>
  2. #include "resources.h"
  3.  
  4. #define lcor 8
  5. #define ucor 1
  6. #define score_y 3 //2
  7. #define score_x 33 //1
  8. #define hiscore_y 8 //2
  9. #define hiscore_x 33
  10. #define n31 31
  11. #define n32 32
  12. #define nbig 96 //128
  13. #define nsmall 160
  14. #define wintile 10 //5 for "64", 10 for "2048"
  15.  
  16. //Єхъє∙шх ъююЁфшэрЄ√ т√тюфр ЄхъёЄр
  17.  
  18. static u8 key;
  19. static u8 keys[40];
  20. static u8 output_x,output_xt;
  21. static u8 output_y,output_yt;
  22. static u8 tile;
  23. static u8 t_tile;
  24. static u16 output_tile;
  25. static u8 board[4][4]; //+(n*32) = new tile
  26. static u8 oldboard[4][4];
  27. static u8 screenboard[4][4];
  28. static u8 oldscreenboard[4][4];
  29. static u32 score,screenscore,oldscreenscore;
  30. static u32 hiscore,screenhiscore,oldscreenhiscore;
  31. static char i,j;
  32. static u8 joy;
  33. static u8 gameover;
  34. static u8 win; //increases at each wintile
  35. static u8 nmoves;
  36. static u8 t;
  37.  
  38. static char tscore[7]="012345";
  39.  
  40. const u32 tilescore[]={
  41.         2,4,8,16,32,64,
  42.         128,256,512,1024,2048,4096,8192,16384,32768ul,65536ul,131072ul,262144ul
  43. };
  44.  
  45.  
  46. //т√тюф юфэюую ёшьтюыр эр ¤ъЁрэ ё ртЄюьрЄшўхёъшь шчьхэхэшхь
  47. //яючшЎшш т√тюфр, Єръцх ёшьтюы '\n' яхЁхтюфшЄ ёЄЁюъє
  48. void put_char(u8 n)
  49. {
  50.         if(n>=' '&&n<='Z')
  51.         {
  52.                 draw_tile(output_x,output_y,n-' ');
  53.                 draw_tile(output_x,output_y+1,n-' '+64);
  54.         }
  55.  
  56.         ++output_x;
  57.  
  58.         if(output_x==40||n=='\n')
  59.         {
  60.                 output_x=1;
  61.                
  62.                 ++output_y;
  63.                
  64.                 if(output_y==24) output_y=1;
  65.         }
  66. }
  67.  
  68. void put_char_key(u8 n)
  69. {
  70.         if(n>=' '&&n<='Z')
  71.         {
  72.                 draw_tile_key(output_x,output_y,n-' ');
  73.                 draw_tile_key(output_x,output_y+1,n-' '+64);
  74.         }
  75.  
  76.         ++output_x;
  77.  
  78.         if(output_x==40||n=='\n')
  79.         {
  80.                 output_x=1;
  81.                
  82.                 ++output_y;
  83.                
  84.                 if(output_y==24) output_y=1;
  85.         }
  86. }
  87.  
  88. //т√тюф ёЄЁюъш ёшьтюыют
  89. void put_str(u8* str)
  90. {
  91.         u8 i;
  92.  
  93.         while(1)
  94.         {
  95.                 i=*str++;
  96.  
  97.                 if(!i) break;
  98.  
  99.                 put_char(i);
  100.         }
  101. }
  102.  
  103. void put_str_key(u8* str)
  104. {
  105.         u8 i;
  106.  
  107.         while(1)
  108.         {
  109.                 i=*str++;
  110.  
  111.                 if(!i) break;
  112.  
  113.                 put_char_key(i);
  114.         }
  115. }
  116.  
  117.  
  118.  
  119. void init_screen_board()
  120. {
  121. char i,j;
  122. for(i=0;i<4;++i)
  123. {
  124.         for(j=0;j<4;++j)
  125.         {
  126.                 screenboard[i][j]=255;
  127.                 oldscreenboard[i][j]=30;
  128.         }
  129. }
  130. }
  131.  
  132. void init_board()
  133. {
  134. char i,j;
  135. for(i=0;i<4;++i)
  136. {
  137.         for(j=0;j<4;++j)
  138.         {
  139.                 board[i][j]=0;
  140.         }
  141. }
  142. init_screen_board();
  143. }
  144.  
  145. u8 spare_squares()
  146. {
  147. char i,j;
  148. u8 nsq;
  149. nsq=0;
  150. for(i=0;i<4;++i)
  151.         for(j=0;j<4;++j)
  152.                 if (board[i][j]==0)
  153.                 ++nsq;
  154. return nsq;
  155. }
  156.  
  157. void add_rnd()
  158. {
  159. u8 nsq;
  160. //find number of spare squares
  161. //find rnd
  162. nsq=rand16()%spare_squares();
  163. //put tile 2 or 4 in random square
  164. for(i=0;i<4;++i)
  165.         for(j=0;j<4;++j)
  166.                 if (board[i][j]==0)
  167.                 {
  168.                         if (nsq==0) board[i][j]=(rand16()%10)?1+nsmall:2+nsmall;
  169.                         --nsq;
  170.                 }
  171. }
  172.  
  173. void put_tile()
  174. {
  175.         t_tile=0;
  176.         if(tile&0xe0)
  177.         {
  178.                 if(tile>=nsmall) t_tile=16;
  179.                 else t_tile=8;
  180.         }
  181.         tile=tile&n31;
  182.         output_yt=output_y;
  183.         for(i=0;i<6;++i)
  184.         {
  185.                 output_tile=((u16)tile<<8) | t_tile;
  186.                 output_xt=output_x;
  187.                 //for(j=0;j<6;++j)
  188.                 {
  189.                         //draw_tile(output_xt++,output_y,output_tile);
  190.                         //output_tile++;
  191.                         __asm
  192.                         ld      hl,(_output_tile)
  193.                         push    hl
  194.                         ld      a,(_output_yt)
  195.                         ld      b,a
  196.                         ld      hl,#_output_xt
  197.                         ld      c,(hl)
  198.                         inc     (hl)
  199.                         push    bc
  200.                         call    _draw_tile
  201.                         pop     af
  202.                         pop     af
  203.                         ld      hl,#_output_tile
  204.                         inc     (hl)
  205.                         ld      hl,(_output_tile)
  206.                         push    hl
  207.                         ld      a,(_output_yt)
  208.                         ld      b,a
  209.                         ld      hl,#_output_xt
  210.                         ld      c,(hl)
  211.                         inc     (hl)
  212.                         push    bc
  213.                         call    _draw_tile
  214.                         pop     af
  215.                         pop     af
  216.                         ld      hl,#_output_tile
  217.                         inc     (hl)
  218.                         ld      hl,(_output_tile)
  219.                         push    hl
  220.                         ld      a,(_output_yt)
  221.                         ld      b,a
  222.                         ld      hl,#_output_xt
  223.                         ld      c,(hl)
  224.                         inc     (hl)
  225.                         push    bc
  226.                         call    _draw_tile
  227.                         pop     af
  228.                         pop     af
  229.                         ld      hl,#_output_tile
  230.                         inc     (hl)
  231.                         ld      hl,(_output_tile)
  232.                         push    hl
  233.                         ld      a,(_output_yt)
  234.                         ld      b,a
  235.                         ld      hl,#_output_xt
  236.                         ld      c,(hl)
  237.                         inc     (hl)
  238.                         push    bc
  239.                         call    _draw_tile
  240.                         pop     af
  241.                         pop     af
  242.                         ld      hl,#_output_tile
  243.                         inc     (hl)
  244.                         ld      hl,(_output_tile)
  245.                         push    hl
  246.                         ld      a,(_output_yt)
  247.                         ld      b,a
  248.                         ld      hl,#_output_xt
  249.                         ld      c,(hl)
  250.                         inc     (hl)
  251.                         push    bc
  252.                         call    _draw_tile
  253.                         pop     af
  254.                         pop     af
  255.                         ld      hl,#_output_tile
  256.                         inc     (hl)
  257.                         ld      hl,(_output_tile)
  258.                         push    hl
  259.                         ld      a,(_output_yt)
  260.                         ld      b,a
  261.                         ld      hl,#_output_xt
  262.                         ld      c,(hl)
  263.                         //inc   (hl)
  264.                         push    bc
  265.                         call    _draw_tile
  266.                         pop     af
  267.                         pop     af
  268.                         //ld    hl,#_output_tile
  269.                         //inc   (hl)
  270.                         __endasm;
  271.                 };
  272.                 ++output_yt;
  273.                 t_tile+=32;
  274.         }
  275. }
  276.  
  277.  
  278. void clear_anim()
  279. {
  280. board[0][0]&=n31;
  281. board[0][1]&=n31;
  282. board[0][2]&=n31;
  283. board[0][3]&=n31;
  284. board[1][0]&=n31;
  285. board[1][1]&=n31;
  286. board[1][2]&=n31;
  287. board[1][3]&=n31;
  288. board[2][0]&=n31;
  289. board[2][1]&=n31;
  290. board[2][2]&=n31;
  291. board[2][3]&=n31;
  292. board[3][0]&=n31;
  293. board[3][1]&=n31;
  294. board[3][2]&=n31;
  295. board[3][3]&=n31;
  296. }
  297.  
  298. void put_board()
  299. {
  300. select_image(IMG_TILES2);
  301. pal_select(PAL_TILES2);
  302. output_y=ucor+ 0;
  303. tile=board[0][0]; if (tile!=oldscreenboard[0][0]) {output_x=lcor+ 0; put_tile();};
  304. tile=board[0][1]; if (tile!=oldscreenboard[0][1]) {output_x=lcor+ 6; put_tile();};
  305. tile=board[0][2]; if (tile!=oldscreenboard[0][2]) {output_x=lcor+12; put_tile();};
  306. tile=board[0][3]; if (tile!=oldscreenboard[0][3]) {output_x=lcor+18; put_tile();};
  307. output_y=ucor+ 6;
  308. tile=board[1][0]; if (tile!=oldscreenboard[1][0]) {output_x=lcor+ 0; put_tile();};
  309. tile=board[1][1]; if (tile!=oldscreenboard[1][1]) {output_x=lcor+ 6; put_tile();};
  310. tile=board[1][2]; if (tile!=oldscreenboard[1][2]) {output_x=lcor+12; put_tile();};
  311. tile=board[1][3]; if (tile!=oldscreenboard[1][3]) {output_x=lcor+18; put_tile();};
  312. output_y=ucor+ 12;
  313. tile=board[2][0]; if (tile!=oldscreenboard[2][0]) {output_x=lcor+ 0; put_tile();};
  314. tile=board[2][1]; if (tile!=oldscreenboard[2][1]) {output_x=lcor+ 6; put_tile();};
  315. tile=board[2][2]; if (tile!=oldscreenboard[2][2]) {output_x=lcor+12; put_tile();};
  316. tile=board[2][3]; if (tile!=oldscreenboard[2][3]) {output_x=lcor+18; put_tile();};
  317. output_y=ucor+ 18;
  318. tile=board[3][0]; if (tile!=oldscreenboard[3][0]) {output_x=lcor+ 0; put_tile();};
  319. tile=board[3][1]; if (tile!=oldscreenboard[3][1]) {output_x=lcor+ 6; put_tile();};
  320. tile=board[3][2]; if (tile!=oldscreenboard[3][2]) {output_x=lcor+12; put_tile();};
  321. tile=board[3][3]; if (tile!=oldscreenboard[3][3]) {output_x=lcor+18; put_tile();};
  322. memcpy(oldscreenboard,screenboard,16);
  323. memcpy(screenboard,board,16);
  324. //clear_anim();
  325. for(i=0;i<4;++i)
  326. {
  327.         for(j=0;j<4;++j)
  328.         {
  329.                 t=board[i][j];
  330.                 if(t&0xe0)
  331.                 {
  332.                         if(t>=nsmall) board[i][j]=t&31;
  333.                         else board[i][j]-=n32;
  334.                 }
  335.         }
  336. }
  337. if(score!=oldscreenscore)
  338. {
  339.         select_image(IMG_FONT);
  340.         tscore[0]='0'+score/100000;
  341.         tscore[1]='0'+(score%100000)/10000;
  342.         tscore[2]='0'+(score%10000)/1000;
  343.         tscore[3]='0'+(score%1000)/100;
  344.         tscore[4]='0'+(score%100)/10;
  345.         tscore[5]='0'+(score%10);
  346.         output_x=score_x;
  347.         output_y=score_y;
  348.         put_str(tscore);
  349.         oldscreenscore=screenscore;
  350.         screenscore=score;
  351. }
  352. if(hiscore!=oldscreenhiscore)
  353. {
  354.         select_image(IMG_FONT);
  355.         tscore[0]='0'+hiscore/100000;
  356.         tscore[1]='0'+(hiscore%100000)/10000;
  357.         tscore[2]='0'+(hiscore%10000)/1000;
  358.         tscore[3]='0'+(hiscore%1000)/100;
  359.         tscore[4]='0'+(hiscore%100)/10;
  360.         tscore[5]='0'+(hiscore%10);
  361.         output_x=hiscore_x;
  362.         output_y=hiscore_y;
  363.         put_str(tscore);
  364.         oldscreenhiscore=screenhiscore;
  365.         screenhiscore=hiscore;
  366. }
  367. swap_screen();
  368. }
  369.  
  370. void store_oldboard()
  371. {
  372. memcpy(oldboard,board,16);
  373. //for(i=0;i<4;++i)
  374. //      for(j=0;j<4;++j)
  375. //              oldboard[i][j]=board[i][j];
  376. }
  377.  
  378. //returns !=0 if comething changed
  379. u8 compare_boards()
  380. {
  381. //t=0;
  382. //for(i=0;i<4;++i)
  383. //      for(j=0;j<4;++j)
  384. //              if((board[i][j]&31)!=(oldboard[i][j]&31))
  385. //              ++nsq;
  386. __asm //max tile=15, 4x4 times never overflow
  387.         ld      c,#31
  388.         ld      hl,#_board
  389.         ld      de,#_oldboard
  390.         ld      a,(de) ;0
  391.         xor     (hl)
  392.         and     c
  393.         //add   a,b
  394.         ld      b,a
  395.         inc     hl
  396.         inc     de
  397.         ld      a,(de)
  398.         xor     (hl)
  399.         and     c
  400.         add     a,b
  401.         ld      b,a
  402.         inc     hl
  403.         inc     de
  404.         ld      a,(de)
  405.         xor     (hl)
  406.         and     c
  407.         add     a,b
  408.         ld      b,a
  409.         inc     hl
  410.         inc     de
  411.         ld      a,(de)
  412.         xor     (hl)
  413.         and     c
  414.         add     a,b
  415.         ld      b,a
  416.         inc     hl
  417.         inc     de
  418.         ld      a,(de) ;4
  419.         xor     (hl)
  420.         and     c
  421.         add     a,b
  422.         ld      b,a
  423.         inc     hl
  424.         inc     de
  425.         ld      a,(de)
  426.         xor     (hl)
  427.         and     c
  428.         add     a,b
  429.         ld      b,a
  430.         inc     hl
  431.         inc     de
  432.         ld      a,(de)
  433.         xor     (hl)
  434.         and     c
  435.         add     a,b
  436.         ld      b,a
  437.         inc     hl
  438.         inc     de
  439.         ld      a,(de)
  440.         xor     (hl)
  441.         and     c
  442.         add     a,b
  443.         ld      b,a
  444.         inc     hl
  445.         inc     de
  446.         ld      a,(de) ;8
  447.         xor     (hl)
  448.         and     c
  449.         add     a,b
  450.         ld      b,a
  451.         inc     hl
  452.         inc     de
  453.         ld      a,(de)
  454.         xor     (hl)
  455.         and     c
  456.         add     a,b
  457.         ld      b,a
  458.         inc     hl
  459.         inc     de
  460.         ld      a,(de)
  461.         xor     (hl)
  462.         and     c
  463.         add     a,b
  464.         ld      b,a
  465.         inc     hl
  466.         inc     de
  467.         ld      a,(de)
  468.         xor     (hl)
  469.         and     c
  470.         add     a,b
  471.         ld      b,a
  472.         inc     hl
  473.         inc     de
  474.         ld      a,(de) ;12
  475.         xor     (hl)
  476.         and     c
  477.         add     a,b
  478.         ld      b,a
  479.         inc     hl
  480.         inc     de
  481.         ld      a,(de)
  482.         xor     (hl)
  483.         and     c
  484.         add     a,b
  485.         ld      b,a
  486.         inc     hl
  487.         inc     de
  488.         ld      a,(de)
  489.         xor     (hl)
  490.         and     c
  491.         add     a,b
  492.         ld      b,a
  493.         inc     hl
  494.         inc     de
  495.         ld      a,(de)
  496.         xor     (hl)
  497.         and     c
  498.         add     a,b
  499.         ld      b,a
  500.         //inc   hl
  501.         //inc   de
  502.         ld      hl,#_t
  503.         ld      (hl),b
  504. __endasm;
  505. return t;
  506. }
  507.  
  508. void move_end()
  509. {
  510.         if (score>hiscore) hiscore=score;
  511.         //add tile
  512.         add_rnd();
  513.         put_board();
  514.         put_board();
  515.         do {
  516.                 vsync();
  517.         } while(joystick()&joy); //for joystick
  518. }
  519.  
  520.  
  521. void move_left_move()
  522. {
  523. for(i=0;i<4;++i)
  524.         for(j=0;j<3;++j)
  525.                 if(board[i][j]==0)
  526.                 {
  527.                         board[i][j]=board[i][j+1];
  528.                         board[i][j+1]=0;
  529.                 };
  530. }
  531.  
  532. void move_right_move()
  533. {
  534. for(i=0;i<4;++i)
  535.         for(j=3;j>0;--j)
  536.                 if(board[i][j]==0)
  537.                 {
  538.                         board[i][j]=board[i][j-1];
  539.                         board[i][j-1]=0;
  540.                 };
  541. }
  542.  
  543. void move_up_move()
  544. {
  545. for(i=0;i<4;++i)
  546.         for(j=0;j<3;++j)
  547.                 if(board[j][i]==0)
  548.                 {
  549.                         board[j][i]=board[j+1][i];
  550.                         board[j+1][i]=0;
  551.                 };
  552. }
  553.  
  554. void move_down_move()
  555. {
  556. for(i=0;i<4;++i)
  557.         for(j=3;j>0;--j)
  558.                 if(board[j][i]==0)
  559.                 {
  560.                         board[j][i]=board[j-1][i];
  561.                         board[j-1][i]=0;
  562.                 };
  563. }
  564.  
  565. u8 compare_boards_put_board()
  566. {
  567. u8 nsq;
  568.         nsq=compare_boards();
  569.         if(nsq)
  570.         {
  571.                 put_board();
  572.                 nmoves++;
  573.         }
  574. return nsq;
  575. }
  576.  
  577. void move_left()
  578. {
  579. char i,j;
  580. u8 dest;
  581. u8 t;
  582. nmoves=0;
  583. clear_anim();
  584. //move everything to the leftmost position
  585. do {
  586.         store_oldboard();
  587.         move_left_move();
  588. } while (compare_boards_put_board()); //nmoves++
  589. //join tiles from the left
  590. store_oldboard();
  591. for(i=0;i<4;++i)
  592. {
  593.         dest=0;
  594.         for(j=0;j<3;++j)
  595.         {
  596.                 t=board[i][j];
  597.                 if(t&&(board[i][j+1]==t))
  598.                 {
  599.                         board[i][j]+=nbig+1;
  600.                         board[i][j+1]=0;
  601.                         score+=tilescore[t&n31];
  602.                         if((t&n31)==wintile)win++;
  603.                 };
  604.         }
  605. }
  606. compare_boards_put_board(); //nmoves++
  607. //move everything to the leftmost position
  608. do {
  609.         store_oldboard();
  610.         move_left_move();
  611. } while (compare_boards_put_board()); //nmoves++
  612. if(nmoves) move_end();
  613. }
  614.  
  615. void move_right()
  616. {
  617. char i,j;
  618. u8 dest;
  619. u8 t;
  620. nmoves=0;
  621. clear_anim();
  622. //move everything to the rightmost position
  623. do {
  624.         store_oldboard();
  625.         move_right_move();
  626. } while (compare_boards_put_board()); //nmoves++
  627. //join tiles from the right
  628. store_oldboard();
  629. for(i=0;i<4;++i)
  630. {
  631.         dest=0;
  632.         for(j=3;j>0;--j)
  633.         {
  634.                 t=board[i][j];
  635.                 if(t&&(board[i][j-1]==t))
  636.                 {
  637.                         board[i][j]+=nbig+1;
  638.                         board[i][j-1]=0;
  639.                         score+=tilescore[t&n31];
  640.                         if((t&n31)==wintile)win++;
  641.                 };
  642.         }
  643. }
  644. compare_boards_put_board(); //nmoves++
  645. //move everything to the rightmost position
  646. do {
  647.         store_oldboard();
  648.         move_right_move();
  649. } while (compare_boards_put_board()); //nmoves++
  650. if(nmoves) move_end();
  651. }
  652.  
  653. void move_up()
  654. {
  655. char i,j;
  656. u8 dest;
  657. u8 t;
  658. nmoves=0;
  659. clear_anim();
  660. //move everything to the topmost position
  661. do {
  662.         store_oldboard();
  663.         move_up_move();
  664. } while (compare_boards_put_board()); //nmoves++
  665. //join tiles from the top
  666. store_oldboard();
  667. for(i=0;i<4;++i)
  668. {
  669.         dest=0;
  670.         for(j=0;j<3;++j)
  671.         {
  672.                 t=board[j][i];
  673.                 if(t&&(board[j+1][i]==t))
  674.                 {
  675.                         board[j][i]+=nbig+1;
  676.                         board[j+1][i]=0;
  677.                         score+=tilescore[t&n31];
  678.                         if((t&n31)==wintile)win++;
  679.                 };
  680.         }
  681. }
  682. compare_boards_put_board(); //nmoves++
  683. //move everything to the topmost position
  684. do {
  685.         store_oldboard();
  686.         move_up_move();
  687. } while (compare_boards_put_board()); //nmoves++
  688. if(nmoves) move_end();
  689. }
  690.  
  691. void move_down()
  692. {
  693. char i,j;
  694. u8 dest;
  695. u8 t;
  696. nmoves=0;
  697. clear_anim();
  698. //move everything to the bottommost position
  699. do {
  700.         store_oldboard();
  701.         move_down_move();
  702. } while (compare_boards_put_board()); //nmoves++
  703. //join tiles from the bottom
  704. store_oldboard();
  705. for(i=0;i<4;++i)
  706. {
  707.         dest=0;
  708.         for(j=3;j>0;--j)
  709.         {
  710.                 t=board[j][i];
  711.                 if(t&&(board[j-1][i]==t))
  712.                 {
  713.                         board[j][i]+=nbig+1;
  714.                         board[j-1][i]=0;
  715.                         score+=tilescore[t&n31];
  716.                         if((t&n31)==wintile)win++;
  717.                 };
  718.         }
  719. }
  720. compare_boards_put_board(); //nmoves++
  721. //move everything to the bottommost position
  722. do {
  723.         store_oldboard();
  724.         move_down_move();
  725. } while (compare_boards_put_board()); //nmoves++
  726. if(nmoves) move_end();
  727. }
  728.  
  729.  
  730. u8 hor_moves()
  731. {
  732. u8 nsq;
  733. nsq=0;
  734. for(i=0;i<4;++i)
  735.         for(j=0;j<3;++j)
  736.                 if((board[i][j+1]&31)==(board[i][j]&31))
  737.                 ++nsq;
  738. return nsq;
  739. }
  740.  
  741. u8 ver_moves()
  742. {
  743. u8 nsq;
  744. nsq=0;
  745. for(i=0;i<4;++i)
  746.         for(j=0;j<3;++j)
  747.                 if((board[j+1][i]&31)==(board[j][i]&31))
  748.                 ++nsq;
  749. return nsq;
  750. }
  751.  
  752.  
  753. u8 check_gameover()
  754. {
  755. u8 c_gameover;
  756. c_gameover=0;
  757. //check no free space
  758. if (spare_squares()==0)
  759.         //check no tiles to combine horizontally
  760.         if (hor_moves()==0)
  761.                 //check no tiles to combine vertically
  762.                 if (ver_moves()==0)
  763.                 c_gameover=1;
  764. return c_gameover;
  765. }
  766.  
  767.  
  768. void do_gameover()
  769. {
  770. u8 i;
  771. gameover=1;
  772. for(i=0;i<2;i++)
  773. {
  774.         select_image(IMG_FONT);
  775.         output_x=15;
  776.         output_y=10;
  777.         put_str_key("GAME OVER!");
  778.         output_x=14;
  779.         output_y=12;
  780.         put_str_key("R TO RESTART");
  781.         swap_screen();
  782. }
  783. music_stop();
  784. sample_play(1);
  785. }
  786.  
  787. void do_win()
  788. {
  789. u8 i;
  790. for(i=0;i<2;i++)
  791. {
  792.         select_image(IMG_FONT);
  793.         output_x=16;
  794.         output_y=10;
  795.         put_str_key("YOU WIN!");
  796.         output_x=14;
  797.         output_y=12;
  798.         put_str_key("C TO CONTINUE");
  799.         swap_screen();
  800. };
  801. music_stop();
  802. sample_play(0);
  803. do {
  804.         keyboard(keys);
  805.         vsync(); //for joystick
  806. } while ((keys[KEY_C]&KEY_PRESS) == 0);
  807. init_screen_board();
  808. music_play(MUS_2ATSTSTR);
  809. }
  810.  
  811. void draw_bg()
  812. {
  813.         select_image(IMG_TILES2);
  814.         for(i=8;i<(40-8);i++)
  815.                         draw_tile(i,0,31);
  816.         for(j=0;j<25;j++)
  817.         {
  818.                 for(i=0;i<8;i++)
  819.                         draw_tile(i,j,((256/8)*32)+16+(j<<5)+i);
  820.                 for(i=0;i<8;i++)
  821.                         draw_tile(i+(40-8),j,((256/8)*32)+24+(j<<5)+i);
  822.         };
  823.         swap_screen();
  824. }
  825.  
  826.  
  827. void new_game()
  828. {
  829. u8 i;
  830. music_play(MUS_2ATSTSTR);
  831. if (score>hiscore) hiscore=score;
  832.  
  833. //шэшЎшрышчрЎш  яхЁхьхээ√ї
  834. score=0;
  835. screenscore=65535;
  836. oldscreenscore=65533;
  837. screenhiscore=65535;
  838. oldscreenhiscore=65533;
  839. gameover=0;
  840. win=0;
  841.  
  842. init_board();
  843. draw_bg();
  844. draw_bg();
  845. add_rnd();
  846. add_rnd();
  847.  
  848. for(i=0;i<2;i++)
  849. {
  850.         put_board();
  851.         //т√сюЁ шчюсЁрцхэш  фы  т√тюфр Єрщыют
  852. /*
  853.         select_image(IMG_FONT);
  854.         output_x=score_x;
  855.         output_y=0;
  856.         put_str("SCORE");
  857.         output_x=hiscore_x;
  858.         output_y=0;
  859.         put_str(" BEST");
  860. */
  861.         //tscore[0]='0'+hiscore/100000;
  862.         //tscore[1]='0'+(hiscore%100000)/10000;
  863.         //tscore[2]='0'+(hiscore%10000)/1000;
  864.         //tscore[3]='0'+(hiscore%1000)/100;
  865.         //tscore[4]='0'+(hiscore%100)/10;
  866.         //tscore[5]='0'+(hiscore%10);
  867.         //output_x=hiscore_x;
  868.         //output_y=2;
  869.         //put_str(tscore);
  870. }
  871. }
  872.  
  873.  
  874. void main(void)
  875. {
  876. //sample_play(1);
  877.         color_key(15);
  878.  
  879.         //ў╕Ёэ√щ ¤ъЁрэ эр тЁхь  яюфуюЄютъш
  880.  
  881.         pal_select(PAL_TILES2);
  882.         pal_bright(BRIGHT_MIN);
  883.  
  884.         //юўшёЄър Єхэхтюую ¤ъЁрэр ш єёЄрэютър ярышЄЁ√
  885.  
  886.         clear_screen(12);
  887.         border(12);
  888.  
  889.         //яхЁхъы■ўхэшх ¤ъЁрэют, ЄхяхЁ№ Їюэ эр тшфшьюь ¤ъЁрэх
  890.  
  891.         swap_screen();
  892.         clear_screen(12);
  893.         swap_screen();
  894.  
  895.         //єёЄрэютър эюЁьры№эющ  ЁъюёЄш
  896.  
  897.         pal_bright(BRIGHT_MID);
  898.  
  899.  
  900.         //ёяЁрщЄ√ т ¤Єюь яЁшьхЁх эх шёяюы№чє■Єё , эю яЁш ЁрчЁх°╕ээ√ї ёяЁрщЄрї
  901.         //ртЄюьрЄшўхёъш т√яюыэ хЄё  ъюяшЁютрэшх т√тюфшьющ уЁрЇшъш т фтр ¤ъЁрэр,
  902.         //ўЄю яючтюы хЄ єяЁюёЄшЄ№ ¤ЄюЄ яЁшьхЁ
  903.  
  904.         //sprites_start();
  905.  
  906.         hiscore=0;
  907.  
  908.         //т√сюЁ шчюсЁрцхэш  фы  т√тюфр Єрщыют
  909.         select_image(IMG_FONT);
  910.         output_x=13;
  911.         output_y=10;
  912.         put_str_key("USE THE ARROWS");
  913.         output_x=14;
  914.         output_y=12;
  915.         put_str_key("R TO RESTART");
  916.         swap_screen();
  917.  
  918.         while(joystick()==0) {vsync();rand16();} //for joystick
  919.         while(joystick()) {vsync();rand16();} //for joystick
  920.  
  921.         new_game();
  922.  
  923.  
  924.         //уыртэ√щ Ўшъы
  925.         while(1)
  926.         {
  927.                 //яюыєўхэшх ёюёЄю эш  ъыртш°
  928.  
  929.                 keyboard(keys);
  930.                 vsync(); //for joystick
  931.                 joy=joystick();
  932.  
  933.                 if(gameover==0)
  934.                 {
  935.                         if(joy&JOY_LEFT) { joy=JOY_LEFT; move_left();}
  936.                         if(joy&JOY_RIGHT) { joy=JOY_RIGHT; move_right();}
  937.                         if(joy&JOY_UP) { joy=JOY_UP; move_up();}
  938.                         if(joy&JOY_DOWN) { joy=JOY_DOWN; move_down();}
  939.  
  940.                         //юсэютыхэшх ¤ъЁрэр
  941.                         if(joy==0) put_board();
  942.  
  943.                         if (check_gameover()!=0) do_gameover();
  944.  
  945.                         if (win==1) {win++; do_win();};
  946.  
  947.                 }
  948.  
  949.                 if(keys[KEY_R]&KEY_PRESS) new_game();
  950.  
  951.                 //if(keys[KEY_LEFTARROW]&KEY_PRESS) move_left();
  952.                 //if(keys[KEY_RIGHTARROW]&KEY_PRESS) move_right();
  953.                 //if(keys[KEY_UPARROW]&KEY_PRESS) move_up();
  954.                 //if(keys[KEY_DOWNARROW]&KEY_PRESS) move_down();
  955.  
  956.         }
  957.  
  958. }