STAR.PAS 9.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322
  1. Uses CRT, Graph;
  2. Const
  3. otn = 3;
  4. sizeofplane = 30;
  5. numofbullets = 50;
  6. typeofstar = 5;
  7. NumOfTargets = 3;
  8. NumOfStars = 3;
  9. {---------------------------------}
  10. Type TStar = record
  11. x,y,radius,color,ang : integer;
  12. end;
  13. Type TPlane = record
  14. x,y,ang : integer;
  15. end;
  16. Type TFire = record
  17. x,y,ang : integer;
  18. isfired : boolean;
  19. end;
  20. Var
  21. i : integer;
  22. stars : array [1..numofstars] of Tstar;
  23. plane : Tplane;
  24. crash : boolean;
  25. shots : array [1..numofbullets] of TFire;
  26. LeftShot : boolean;
  27. GunL : array [1..3] of pointtype;
  28. GunR : array [1..3] of pointtype;
  29. Targets : array [1..numoftargets] of pointtype;
  30. Score : longint;
  31. {---------------------------------------}
  32. Function FreeShot : byte;
  33. var i,rc : byte;
  34. begin
  35. rc := 0;
  36. for i := 1 to numofbullets do if not shots[i].isfired then rc :=i;
  37. FreeShot := rc;
  38. end;{FreeShot}
  39. {--------------------------}
  40. Procedure WriteTarget(index : integer);
  41. Var i : integer;
  42. Begin
  43. SetColor(White);
  44. for i := 5 downto 1 do
  45. if i mod 2 = 1 then begin
  46. SetFillStyle(SolidFill,Red);
  47. FillEllipse(targets[index].x,targets[index].y,i*4,i*4);
  48. end
  49. else
  50. begin
  51. SetFillStyle(SolidFill,White);
  52. FillEllipse(targets[index].x,targets[index].y,i*4,i*4);
  53. end;
  54. End;{WriteTarget}
  55. {-----------------------------------}
  56. Procedure Star(x,y,radius,Color,a0: integer);
  57. Var
  58. dx,dy,i,a : integer;
  59. Begin
  60. SetColor(color);
  61. MoveTO(x+round((radius div otn)*cos(pi*a0/180)),
  62. y+round((radius div otn)*sin(pi*a0/180)));
  63. for i := 1 to typeofstar * 2 do begin
  64. a := i*(360 div (typeofstar*2))+a0;
  65. if i mod 2 = 1 then
  66. begin
  67. dx := round(radius*cos((Pi*a)/180));
  68. dy := round(radius*sin((Pi*a)/180))
  69. end
  70. else
  71. begin
  72. dx := round((radius div otn)*cos((Pi*a)/180));
  73. dy := round((radius div otn)*sin((Pi*a)/180))
  74. end;
  75. LineTo(x+dx,y+dy);
  76. end;
  77. End;{Star}
  78. {-------------------------}
  79. Procedure INITG;
  80. Var
  81. grDriver: Integer;
  82. grMode: Integer;
  83. begin
  84. grDriver := Detect;
  85. InitGraph(grDriver, grMode,'');
  86. SetWriteMode(XORPUT);
  87. randomize;
  88. for i :=1 to numofbullets do
  89. with shots[i] do
  90. begin
  91. x := 0;
  92. y := 0;
  93. ang := 0;
  94. isfired := false;
  95. end;
  96. for i :=1 to numoftargets do
  97. with targets[i] do
  98. begin
  99. x := random(640);
  100. y := random(480);
  101. end;
  102. for i :=1 to numofstars do
  103. with stars[i] do
  104. begin
  105. x := random(640);
  106. y := random(480);
  107. radius := random(155)+10;
  108. color := random(14)+1;
  109. ang :=0;
  110. end;
  111. with plane do
  112. begin
  113. x := 100;
  114. y := 240;
  115. ang := 0;
  116. end;
  117. End;{INITG}
  118. {-------------------------------------}
  119. Procedure ShowPlane(x0,y0,ang:integer);
  120. Var
  121. pl : array [1..3] of PointType;
  122. wings : array [1..3] of pointtype;
  123. ls : array [1..3] of pointtype;
  124. Begin
  125. SetColor(Green);
  126. with pl[1] do
  127. begin
  128. x := round(x0+(sizeofplane div 2)*cos((Pi*ang)/180));
  129. y := round(y0-(sizeofplane div 2)*sin((Pi*ang)/180));
  130. end;
  131. with pl[2] do
  132. begin
  133. x := round(x0-(sizeofplane div 2)*cos((Pi*ang)/180)-(sizeofplane div 10)*cos((Pi*(90-ang))/180));
  134. y := round(y0+(sizeofplane div 2)*sin((Pi*ang)/180)-(sizeofplane div 10)*sin((Pi*(90-ang))/180));
  135. end;
  136. with pl[3] do
  137. begin
  138. x := round(x0-(sizeofplane div 2)*cos((Pi*ang)/180)+(sizeofplane div 10)*cos((Pi*(90-ang))/180));
  139. y := round(y0+(sizeofplane div 2)*sin((Pi*ang)/180)+(sizeofplane div 10)*sin((Pi*(90-ang))/180));
  140. end;
  141. with wings[1] do
  142. begin
  143. x := round(x0+(sizeofplane div 4)*cos((Pi*ang)/180));
  144. y := round(y0-(sizeofplane div 4)*sin((Pi*ang)/180));
  145. end;
  146. with wings[2] do
  147. begin
  148. x := round(x0-(sizeofplane div 2)*cos((Pi*(90-ang))/180));
  149. y := round(y0-(sizeofplane div 2)*sin((Pi*(90-ang))/180));
  150. end;
  151. with wings[3] do
  152. begin
  153. x := round(x0+(sizeofplane div 2)*cos((Pi*(90-ang))/180));
  154. y := round(y0+(sizeofplane div 2)*sin((Pi*(90-ang))/180));
  155. end;
  156. with ls[1] do
  157. begin
  158. x := round(x0-(sizeofplane div 3)*cos((Pi*ang)/180));
  159. y := round(y0+(sizeofplane div 3)*sin((Pi*ang)/180));
  160. end;
  161. with ls[2] do
  162. begin
  163. x := round(x0-(sizeofplane div 2)*cos((Pi*ang)/180)-(sizeofplane div 4)*cos((Pi*(90-ang))/180));
  164. y := round(y0+(sizeofplane div 2)*sin((Pi*ang)/180)-(sizeofplane div 4)*sin((Pi*(90-ang))/180));
  165. end;
  166. with ls[3] do
  167. begin
  168. x := round(x0-(sizeofplane div 2)*cos((Pi*ang)/180)+(sizeofplane div 4)*cos((Pi*(90-ang))/180));
  169. y := round(y0+(sizeofplane div 2)*sin((Pi*ang)/180)+(sizeofplane div 4)*sin((Pi*(90-ang))/180));
  170. end;
  171. with GunL[1] do
  172. begin
  173. x := round(x0-((sizeofplane div 4)-(sizeofplane div 32))*cos((Pi*(90-ang))/180));
  174. y := round(y0-((sizeofplane div 4)-(sizeofplane div 32))*sin((Pi*(90-ang))/180));
  175. end;
  176. with GunL[2] do
  177. begin
  178. x := round(x0-((sizeofplane div 4)+(sizeofplane div 32))*cos((Pi*(90-ang))/180));
  179. y := round(y0-((sizeofplane div 4)+(sizeofplane div 32))*sin((Pi*(90-ang))/180));
  180. end;
  181. with GunL[3] do
  182. begin
  183. x := round(GunL[2].X+(sizeofplane div 4)*cos((Pi*ang)/180));
  184. y := round(GunL[2].Y-(sizeofplane div 4)*sin((Pi*ang)/180));
  185. end;
  186. with GunR[1] do
  187. begin
  188. x := round(x0+((sizeofplane div 4)-(sizeofplane div 32))*cos((Pi*(90-ang))/180));
  189. y := round(y0+((sizeofplane div 4)-(sizeofplane div 32))*sin((Pi*(90-ang))/180));
  190. end;
  191. with GunR[2] do
  192. begin
  193. x := round(x0+((sizeofplane div 4)+(sizeofplane div 32))*cos((Pi*(90-ang))/180));
  194. y := round(y0+((sizeofplane div 4)+(sizeofplane div 32))*sin((Pi*(90-ang))/180));
  195. end;
  196. with Gunr[3] do
  197. begin
  198. x := round(GunR[2].X+(sizeofplane div 4)*cos((Pi*ang)/180));
  199. y := round(GunR[2].Y-(sizeofplane div 4)*sin((Pi*ang)/180));
  200. end;
  201. SetColor(LightGray);
  202. SetFillStyle(SolidFill,blue);
  203. FillPoly(3,pl);
  204. SetFillStyle(SolidFill,Green);
  205. FillPoly(3,GunR);
  206. FillPoly(3,GunL);
  207. SetFillStyle(Solidfill,magenta);
  208. FillPoly(3,wings);
  209. SetFillStyle(Solidfill,Red);
  210. FillPoly(3,ls);
  211. End;{ShowPlane}
  212. {-------------------------------}
  213. Procedure ShowStars;
  214. Var
  215. i : integer;
  216. Begin
  217. ClearDevice;
  218. for i := 1 to numofstars do
  219. with stars[i] do star(x,y,radius,color,ang);
  220. ShowPlane(plane.x,plane.y,plane.ang);
  221. end;
  222. {---------------------------}
  223. Procedure MoveStars;
  224. Var i,j : byte;shooted:boolean;
  225. Begin
  226. for i := 1 to numofstars do
  227. begin
  228. stars[i].x := stars[i].x+round(stars[i].radius/5);
  229. inc(stars[i].ang,stars[i].radius div 10);
  230. if stars[i].ang = 360 then stars[i].ang := 0;
  231. if stars[i].x+stars[i].radius > 630 then
  232. with stars[i] do
  233. begin
  234. y := random(480);
  235. radius := random(55)+5;
  236. color := random(14)+1;
  237. x := radius;
  238. ang := 0;
  239. end;
  240. end;
  241. for i := 1 to numofbullets do
  242. if shots[i].isfired then
  243. begin
  244. SetColor(Yellow);
  245. Line(shots[i].x,shots[i].y,
  246. shots[i].x+round(20*cos(pi*shots[i].ang/180)),
  247. shots[i].y-round(20*sin(pi*shots[i].ang/180)));
  248. shots[i].x := shots[i].x+round((sizeofplane/6)*cos(pi*shots[i].ang/180));
  249. Shots[i].y := shots[i].y-round((sizeofplane/6)*sin(pi*shots[i].ang/180));
  250. if (Shots[i].y<2)or(Shots[i].y>478)or(Shots[i].x<2)or(Shots[i].x > 638) then
  251. Shots[i].isfired := false;
  252. end;
  253. { for i := 1 to numoftargets do
  254. begin
  255. inc(targets[i].x,sizeofplane div 8);
  256. if (targets[i].x+20 > 640) then
  257. begin
  258. shooted := false;
  259. targets[i].x:=20;
  260. targets[i].y:=random(440)+20;
  261. end
  262. else
  263. WriteTarget(i);
  264. end;}
  265. End;{MoveStars}
  266. {------------------------------}
  267. Procedure movePlane(ang:integer);
  268. Begin
  269. if (plane.x+round((sizeofplane div 12)*cos(pi*plane.ang/180))-(sizeofplane div 2) > 1) and
  270. (plane.x+round((sizeofplane div 12)*cos(pi*plane.ang/180))+(sizeofplane div 2) < 640)then
  271. plane.x := plane.x+round((sizeofplane div 12)*cos(pi*plane.ang/180)) else crash := true;
  272. if (plane.y-round((sizeofplane div 12)*sin(pi*plane.ang/180))-(sizeofplane div 2) > 1) and
  273. (plane.y-round((sizeofplane div 12)*sin(pi*plane.ang/180))+(sizeofplane div 2) < 480 ) then
  274. plane.y := plane.y-round((sizeofplane div 12)*sin(pi*plane.ang/180)) else crash := true;
  275. End;
  276. {---------------------------------------------}
  277. Procedure Game;
  278. Var
  279. ch : char;
  280. ifexit : boolean;
  281. Begin
  282. ifexit := false;
  283. crash := false;
  284. repeat
  285. if keypressed then
  286. begin
  287. ch := readkey;
  288. if ch = #0 then ch :=readkey;
  289. case ch of
  290. #75 : inc(plane.ang,5);
  291. #77 : dec(plane.ang,5);
  292. #27,#13 : ifexit := true;
  293. #32 : if freeshot <> 0 then
  294. begin
  295. if leftshot then begin
  296. shots[Freeshot].x:=gunl[3].X;
  297. shots[Freeshot].y:=gunl[3].Y;
  298. Leftshot := false;
  299. end
  300. else begin
  301. shots[Freeshot].x:=gunr[3].X;
  302. shots[Freeshot].y:=gunr[3].Y;
  303. leftshot := true;
  304. end;
  305. shots[FreeShot].ang := plane.ang;
  306. shots[FreeShot].isfired := true;
  307. end;
  308. end;
  309. end;
  310. MovePlane(plane.ang);
  311. MoveStars;
  312. showstars;
  313. until ifexit or crash;
  314. End;{Game}
  315. {---------------------------------}
  316. Begin
  317. Initg;
  318. Game;
  319. CloseGraph;
  320. End.