1. #include<stdio.h>
    2. #include <graphics.h> // “˝”√Õº–Œø‚Õ∑Œƒº˛
    3. #include <conio.h>
    4. #include <windows.h>
    5. #include <stdlib.h>
    6. int hight=504;
    7. int width=1008;
    8. int rwhight=131;
    9. int rwwidth=134;
    10. int holdback[10320][504]={0};//…Ë÷√µÿÕº…œµƒ’œ∞≠ŒÔµƒ∂˛Œ¨ ˝◊È
    11. int red[504][10320];
    12. int gllow[504][10320];
    13. int blue[504][10320];
    14. char i=0;//”√¿¥∂®“¬̿Ô∞¬∑ΩœÚ
    15. char j=0;//”√¿¥ÃÂœ÷¬Ì¿Ô∞¬‘À∂Ø∏–
    16. float v=0;//¬Ì¿Ô∞¬µƒ…œ…˝ÀŸ∂»
    17. float v1=0;//¬Ì¿Ô∞¬µƒœ¬ΩµÀŸ∂»
    18. float rw_x,rw_y;
    19. float bj_x;
    20. IMAGE img_rw2,img_gw2;//∂®“±≥æ∞£¨»ÀŒÔ£¨π÷ŒÔÕº∆¨µƒ’⁄’÷Õº
    21. IMAGE img_bk,img_rw,img_gw;//∂®“±≥æ∞£¨»ÀŒÔ£¨π÷ŒÔÕº∆¨
    22. IMAGE img_redbj;
    23. void updatewithpeople();//”Δ√ªß ‰»Î”–πÿµƒ∫Ø ˝
    24. void updatewithoutpeople();//”Δ√ªß ‰»ÎŒfiπÿµƒ∫Ø ˝
    25. void star();//≥ı ºªØ∫Ø ˝
    26. void show();//œ‘ æ∫Ø ˝
    27. void gameover();//”Œœ∑Ω· ¯
    28. int main()
    29. {
    30. star();
    31. while(1)
    32. {
    33. updatewithpeople();
    34. updatewithoutpeople();
    35. show();
    36. }
    37. return 0;
    38. }
    39. void updatewithpeople()
    40. {
    41. int x,x1,y;
    42. x=(int)rw_x;
    43. x1=(int)bj_x;
    44. y=(int)rw_y;//Ω¯––«ø÷∆¿‡–Õ◊™ªª£¨“ÚŒ™ ˝◊È «int–Õ
    45. if((GetAsyncKeyState(0x41)&0x8000))//œÚ◊Û“∆∂Ø
    46. {
    47. if(holdback[x+x1-1][y]==0)
    48. {
    49. i=0;
    50. j=!j;
    51. rw_x-=0.5;
    52. if(rw_x<0&&bj_x>1)
    53. {
    54. rw_x=0;
    55. bj_x-=0.5;
    56. }
    57. }
    58. }
    59. if((GetAsyncKeyState(0x44)&0x8000))//œÚ”““∆∂Ø
    60. {
    61. if(holdback[x+x1+66][y]==0)
    62. {
    63. i=1;
    64. j=!j;
    65. rw_x+=0.5;
    66. if(rw_x>504&&bj_x<10320-1008)//“∆∂صΩ÷–º‰£¨±≥æ∞ø™ º“∆∂Ø
    67. {
    68. rw_x=504;
    69. bj_x+=0.5;
    70. }
    71. }
    72. }
    73. if((GetAsyncKeyState(VK_SPACE)&0x8000))
    74. {
    75. if(holdback[x+x1+33][y+66]==1)//¬˙◊„¬Ì¿Ô∞¬¬‰µÿ∫Û£¨≤≈ƒ‹Ã¯‘浃Ãıº˛
    76. v=300;
    77. }
    78. }
    79. void updatewithoutpeople()//”ÎÕʺ“Œfiπÿµƒ∫Ø ˝
    80. {
    81. int x,x1,y;
    82. x=(int)rw_x;
    83. x1=(int)bj_x;
    84. y=(int)rw_y;//Ω¯––«ø÷∆¿‡–Õ◊™ªª£¨“ÚŒ™ ˝◊È «int–Õ
    85. if(v>0) //¬Ì¿Ô∞¬…œ…˝øÿ÷∆
    86. {
    87. rw_y-=1;
    88. v--;
    89. if(rw_y==0)//µΩ¥Ô∂•≤ø£¨Õ£÷π…œ…˝
    90. {
    91. v=0;
    92. }
    93. }
    94. if(v<=0&&holdback[x+x1+33][y+66]==0)//¬Ì¿Ô∞¬œ¬Ωµøÿ÷∆
    95. {
    96. rw_y+=1;
    97. if(rw_y>=500)
    98. {
    99. gameover();
    100. }
    101. }
    102. }
    103. void star()//≥ı ºªØ∫Ø ˝
    104. {
    105. int i,j;
    106. int x=0,y;
    107. initgraph(width, hight); // ¥¥Ω®ªÊÕº¥∞ø⁄£¨¥Û–°Œ™ 1008x504 œÒÀÿ
    108. loadimage(&img_bk,_T("C:\\game\\Õº∆¨Àÿ≤ƒ\\±≥æ∞.jpg"));
    109. loadimage(&img_rw,_T("C:\\game\\Õº∆¨Àÿ≤ƒ\\¬Ì¿Ô∞¬.jpg"));
    110. loadimage(&img_rw2,_T("C:\\game\\Õº∆¨Àÿ≤ƒ\\¬Ì¿Ô∞¬—⁄¬ÎÕº.jpg"));
    111. loadimage(&img_gw,_T("C:\\game\\Õº∆¨Àÿ≤ƒ\\“∞π÷2.jpg"));
    112. loadimage(&img_gw2,_T("C:\\game\\Õº∆¨Àÿ≤ƒ\\“∞π÷2—⁄¬ÎÕº.jpg"));
    113. //≥ı ºªØ¬Ì¿Ô∞¬µƒ◊¯±Í
    114. rw_x=33;
    115. rw_y=300;
    116. //≥ı ºªØ’œ∞≠ŒÔ◊¯±Í£¨”√∫Ø ˝Ã·»°Õº∆¨÷–µƒ∫Ï…´«¯”Ú◊¯±Í£¨‘ŸΩ¯––∏≥÷µ
    117. loadimage(&img_redbj,_T("C:\\game\\Õº∆¨Àÿ≤ƒ\\red±≥æ∞.jpg"));
    118. DWORD*pic;
    119. pic=GetImageBuffer(&img_redbj);
    120. for(i=0;i<504;i++)
    121. for(j=0;j<10320;j++)
    122. {
    123. red[i][j]=GetRValue(pic[x]);
    124. gllow[i][j]=GetGValue(pic[x]);
    125. blue[i][j]=GetBValue(pic[x]);
    126. x++;
    127. }
    128. for(i=0;i<504;i++)
    129. for(j=0;j<10320;j++)
    130. {
    131. if(red[i][j]==0&&blue[i][j]>=250&&gllow[i][j]==0)
    132. {
    133. holdback[j][i]=1;
    134. }
    135. }
    136. }
    137. void show()
    138. {
    139. BeginBatchDraw();
    140. putimage(0,0,width,hight,&img_bk,bj_x,0);// ‰≥ˆ±≥æ∞Õº∆¨
    141. if(i==1)
    142. {
    143. if(j==0)
    144. {
    145. putimage(rw_x,rw_y,rwwidth/2,rwhight/2,&img_rw2,0,0,NOTSRCERASE);// ‰≥ˆœÚ”“±fl◊flµƒ¬Ì¿Ô∞¬
    146. putimage(rw_x,rw_y,rwwidth/2,rwhight/2,&img_rw,0,0,SRCINVERT);
    147. }
    148. else
    149. {
    150. putimage(rw_x,rw_y,rwwidth/2,rwhight/2,&img_rw2,rwwidth/2,0,NOTSRCERASE);// ‰≥ˆ¬Ì¿Ô∞¬
    151. putimage(rw_x,rw_y,rwwidth/2,rwhight/2,&img_rw,rwwidth/2,0,SRCINVERT);
    152. }
    153. }
    154. else
    155. {
    156. if(j==0)
    157. {
    158. putimage(rw_x,rw_y,rwwidth/2,rwhight/2,&img_rw2,0,rwhight/2,NOTSRCERASE);// ‰≥ˆœÚ◊Û◊flµƒ¬Ì¿Ô∞¬
    159. putimage(rw_x,rw_y,rwwidth/2,rwhight/2,&img_rw,0,rwhight/2,SRCINVERT);
    160. }
    161. else
    162. {
    163. putimage(rw_x,rw_y,rwwidth/2,rwhight/2,&img_rw2,rwwidth/2,rwhight/2,NOTSRCERASE);// ‰≥ˆ¬Ì¿Ô∞¬
    164. putimage(rw_x,rw_y,rwwidth/2,rwhight/2,&img_rw,rwwidth/2,rwhight/2,SRCINVERT);
    165. }
    166. }
    167. FlushBatchDraw();
    168. }
    169. void gameover()//Ω· ¯’˚∏ˆ”Œœ∑
    170. {
    171. _getch(); // ∞¥»Œ“‚º¸ºÃ–¯
    172. closegraph(); // πÿ±’ªÊÕº¥∞ø⁄
    173. printf("you lose");
    174. Sleep(4000);
    175. exit(0);
    176. }