ARCAN.PAS 4.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204
  1. Uses CRT,Graph;
  2. Type Block = record
  3. x,y:Integer;
  4. End;
  5. Var
  6. MainX,MainY,Beg_of_pad,x0,x,y,y0 : Integer;
  7. BallPos,LastPos :PointType;
  8. AddX,AddY,count_of_bricks,NUM:Integer;
  9. Side:boolean;
  10. blocks : array [1..84] of block;
  11. size:word;
  12. b,p,brick:pointer;
  13. {----------------------------------------------------------------------}
  14. Procedure DrawPad;forward;
  15. Procedure GamOvr;
  16. Begin
  17. ClearDevice;
  18. SetTextStyle(3,0,8);
  19. OutTextXY(100,180,'Game Over');
  20. ReadLn;
  21. CloseGraph;
  22. Halt(1);
  23. End;{GamOvr}
  24. {----------------------------------}
  25. Function TestBricks:Boolean;
  26. Var
  27. i:Integer;
  28. Begin
  29. TestBricks:=false;
  30. For i := 1 to 84 do
  31. begin
  32. With blocks[i] do
  33. begin
  34. if blocks[i].X <> 0 then
  35. begin
  36. if (BallPos.X+6 > X) and (BallPos.X < X + 30) then
  37. if (BallPos.Y+6>Y) and (BallPos.Y<y+15) then
  38. begin
  39. TestBricks:=True;
  40. AddX:=X;
  41. AddY:=Y;
  42. Num:=I;
  43. if (LastPos.X+6>X)and(LastPos.X<X+30) then
  44. Side:=false
  45. else
  46. Side:=True;
  47. end;
  48. end;
  49. end;
  50. End;
  51. End;{TestBricks}
  52. {-----------------------------------}
  53. Procedure DrawBlocks;
  54. Var
  55. i,j:Byte;
  56. Begin
  57. SetFillStyle(BkSlashFill,Magenta);
  58. Bar3d(100,100,130,115,0,false);
  59. Size:=ImageSize(100,100,130,115);
  60. GetMem(Brick,size);
  61. GetImage(100,100,130,115,Brick^);
  62. PutImage(100,100,Brick^,XORPut);
  63. AddX:=17;
  64. AddY:=15;
  65. for i := 0 to 6 do
  66. begin
  67. For j := 1 to 12 do
  68. begin
  69. PutImage(AddX,AddY,Brick^,XorPut);
  70. With blocks[i*12+j] do
  71. begin
  72. x := AddX;
  73. y := AddY;
  74. end;
  75. AddX:=AddX+35
  76. end;
  77. AddX:=17;
  78. AddY:=AddY+20
  79. end;
  80. End;{DrawBlocks}
  81. {------------------------------}
  82. Procedure Initg;
  83. Var
  84. Gd,Gm:Integer;
  85. Begin
  86. Gd := Detect;
  87. InitGraph(Gd, Gm, '');
  88. if GraphResult <> grOk then
  89. Halt(1);
  90. SetLineStyle(SolidLn,1,123);
  91. SetColor(Blue);
  92. Rectangle(0,0,450,GetMaxY);
  93. Rectangle(1,1,449,GetMaxY-1);
  94. SetColor(Green);
  95. Rectangle(451,0,GetMaxX,GetMaxY);
  96. Rectangle(452,1,GetMaxX-1,GetMaxY-1);
  97. SetColor(LightGreen);
  98. Circle(100,100,3);
  99. SetColor(LightBlue);
  100. Circle(100,100,2);
  101. SetColor(LightMagenta);
  102. Circle(100,100,1);
  103. Size:=ImageSize(97,97,103,103);
  104. GetMem(B,Size);
  105. GetImage(97,97,103,103,b^);
  106. PutImage(97,97,B^,XORPut);
  107. Beg_of_pad := 155;
  108. BallPos.X := 190;
  109. BallPos.Y := 455;
  110. MainX:=2;
  111. MainY:=-2;
  112. DrawPad;
  113. Size:=ImageSize(155,460,225,470);
  114. GetMem(P,Size);
  115. GetImage(155,460,225,470,P^);
  116. PutImage(BallPos.x,BallPos.Y,B^,XORPut);
  117. DrawBlocks;
  118. End;{initg}
  119. {---------------------------------------}
  120. Procedure DrawPad;
  121. Begin
  122. SetFillStyle(1,LightGreen);
  123. Bar(Beg_of_pad,460,Beg_of_pad+70,470);
  124. SetFillStyle(1,Yellow);
  125. Bar(Beg_of_pad+5,463,Beg_of_pad+65,467);
  126. End;{DrawPad}
  127. {-----------------------------------------------}
  128. Procedure MovePad(value:Integer);
  129. Begin
  130. PutImage(Beg_of_pad,460,P^,XORPut);
  131. if Beg_of_pad + value >= 377
  132. then Beg_of_pad:=377
  133. else
  134. if Beg_of_pad + value <= 2
  135. then Beg_of_pad := 2
  136. else Beg_of_pad:=Beg_of_pad+value;
  137. PutImage(Beg_of_pad,460,P^,XORPut);
  138. End;{MovePad}
  139. {------------------------------------}
  140. Procedure MoveBall;
  141. Begin
  142. PutImage(BallPos.X,BallPos.Y,B^,XORPut);
  143. case BallPos.Y of
  144. 456 .. 480 : begin
  145. if (BallPos.X>Beg_of_pad-6)and(BallPos.X<Beg_of_pad+70)
  146. then begin
  147. MainY:=-(random(2)+1);
  148. if MainX > 0 then MainX := random(2)+1
  149. else MainX := -(random(2)+1);
  150. End;
  151. if (BallPos.X < Beg_of_pad-2) or (BallPos.X > Beg_of_pad+70) then GamOvr;
  152. end;
  153. 0 .. 2 : begin
  154. MainY := Random(2)+1;
  155. if MainX > 0 then MainX := Random(2)+1
  156. else MainX := -(Random(2)+1);
  157. end;
  158. end;
  159. if (BallPos.X < 3) or (BallPos.X > 442) then MainX:=-MainX;
  160. if TestBricks then
  161. begin
  162. PutImage(AddX,AddY,Brick^,XORPut);
  163. blocks[NUM].X:=0;
  164. Dec(Count_of_bricks);
  165. if side then MainX:=-MainX else MainY:=-MainY;
  166. end;
  167. LastPos.X:=BallPos.X;
  168. LastPos.Y:=BallPos.Y;
  169. BallPos.X:=BallPos.X+MainX;
  170. BallPos.Y:=BallPos.Y+MainY;
  171. PutImage(BallPos.X,BallPos.Y,B^,XORPut);
  172. Delay(170);
  173. End;{MoveBall}
  174. {---------------------------------}
  175. Procedure Play;
  176. Var
  177. w:word;
  178. c:char;
  179. Begin
  180. Count_of_bricks:=82;
  181. readkey;
  182. repeat
  183. moveball;
  184. if keypressed then
  185. begin
  186. c := readkey;
  187. if c = #27 then GamOvr;
  188. if c = #0 then w := ord(readkey);
  189. case w of
  190. 77 : movepad(15);
  191. 75 : movepad(-15);
  192. end;
  193. end;
  194. until false;
  195. End;{Play}
  196. {--------------------------------------}
  197. Begin
  198. Randomize;
  199. Initg;
  200. Play;
  201. End.