Advertisement
CyberPascal

Kill

Feb 2nd, 2014
80
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Pascal 4.72 KB | None | 0 0
  1. uses ABCObjects,Events,GraphABC,Timers,Utils;
  2.  
  3. var
  4.   kLeftKey,kRightKey: boolean;
  5.   kSpaceKey: integer;
  6.   Player: RectangleABC;
  7.   t: integer;
  8.   EndOfGame: boolean;
  9.   Enemies: TextABC;
  10.   StaticObjectsCount: integer;
  11.   NewGame: TextABC;
  12.   Wins,Falls: integer;
  13.   WinsABC,FallsABC: TextABC;
  14.   r1: RectangleABC;
  15.  
  16. type
  17.   KeysType=(kLeft,kRight);
  18.   Pulya=class(CircleABC)
  19.     constructor Create(x,y: integer);
  20.     begin
  21.       inherited Create(x,y,5,clRed);
  22.       dx:=0; dy:=-5;
  23.     end;
  24.     procedure Move;
  25.     var j: integer;
  26.     begin
  27.       inherited Move;
  28.       if Top<0 then
  29.         Visible:=False;
  30.       for j:=StaticObjectsCount+1 to ObjectsCount do
  31.         if (Objects[j]<>Self) and Intersect(Objects[j]) then
  32.         begin
  33.           Objects[j].Visible:=False;
  34.           Visible:=False;
  35.         end;
  36.     end;
  37.   end;
  38.   Enemy=class(RectangleABC)
  39.     constructor Create(x,y,w: integer);
  40.     begin
  41.       inherited Create(x,y,w,20,clRandom);
  42.       if Random(2)=0 then
  43.         dx:=5
  44.       else dx:=-5;
  45.       dy:=0;
  46.     end;
  47.     procedure Move;
  48.     begin
  49.       if Random(2)<>0 then Exit;
  50.       if Random(10)=0 then dy:=5;
  51.       if (Left<0) or (Left+Width>WindowWidth) or (Random(30)=0) then
  52.         dx:=-dx;
  53.       inherited Move;
  54.       if dy<>0 then dy:=0;
  55.       if Top>WindowHeight-50 then
  56.         EndOfGame:=True;
  57.     end;
  58.   end;
  59.  
  60. function NumberOfEnemies: integer;
  61. var i: integer;
  62. begin
  63.   Result:=0;
  64.   for i:=1 to ObjectsCount do
  65.     if Objects[i] is Enemy then
  66.       Inc(Result);
  67. end;
  68.  
  69. procedure CreateObjects;
  70. var
  71.   i: integer;
  72.   r1: RectangleABC;
  73. begin
  74.   Player:=RectangleABC.Create(280,WindowHeight-30,100,20,clTeal);
  75.   for i:=1 to 100 do
  76.   begin
  77.     r1:=Enemy.Create(Random(WindowWidth-50),40+Random(10),50);
  78.     r1.TextVisible:=True;
  79.     r1.Number:=i;
  80.   end;
  81. end;
  82.  
  83. procedure DestroyObjects;
  84. var i: integer;
  85. begin
  86.   for i:=ObjectsCount downto StaticObjectsCount+1 do
  87.     Objects[i].Destroy;
  88. end;
  89.  
  90. procedure MoveObjects;
  91. var i: integer;
  92. begin
  93.   for i:=StaticObjectsCount+2 to ObjectsCount do
  94.     Objects[i].Move;
  95. end;
  96.  
  97. procedure DestroyKilledObjects;
  98. var i: integer;
  99. begin
  100.   for i:=ObjectsCount downto StaticObjectsCount+2 do
  101.     if not Objects[i].Visible then
  102.       Objects[i].Destroy;
  103. end;
  104.  
  105. procedure KeyDown(Key: integer);
  106. begin
  107.   case Key of
  108. vk_Left:  kLeftKey:=True;
  109. vk_Right: kRightKey:=True;
  110. vk_Space: if kSpaceKey=2 then kSpaceKey:=1;
  111.   end;
  112. end;
  113.  
  114. procedure KeyUp(Key: integer);
  115. begin
  116.   case Key of
  117. vk_Left:  kLeftKey:=False;
  118. vk_Right: kRightKey:=False;
  119. vk_Space: kSpaceKey:=2;
  120.   end;
  121. end;
  122.  
  123. procedure Timer1;
  124. var
  125.   i,j,n: integer;
  126.   p: Pulya;
  127. begin
  128.   if kLeftKey and (Player.Left>0) then
  129.     Player.MoveOn(-10,0);
  130.   if kRightKey and (Player.Left+Player.Width<WindowWidth) then
  131.     Player.MoveOn(10,0);
  132.   if kSpaceKey=1 then
  133.   begin
  134.     p:=Pulya.Create(Player.Left+Player.Width div 2,Player.Top-10);
  135.     kSpaceKey:=0;
  136.   end;
  137.   MoveObjects;
  138.   DestroyKilledObjects;
  139.   RedrawObjects;
  140.   n:=NumberOfEnemies;
  141.   Enemies.Text:='Âðàãîâ: '+IntToStr(n);
  142.   if n=0 then
  143.     EndOfGame:=True;
  144.   if EndOfGame then
  145.   begin
  146.     StopTimer(t);
  147.     if n>0 then
  148.     begin
  149.       Inc(Falls);
  150.       FallsABC.Text:='Ïîðàæåíèé: '+IntToStr(Falls);
  151.       RedrawObjects;
  152.       ShowMessage('Âû ïðîèãðàëè!');
  153.       DestroyObjects;
  154.       Enemies.Text:='Âðàãîâ: '+IntToStr(NumberOfEnemies);
  155.       RedrawObjects;
  156.     end
  157.     else
  158.     begin
  159.       Inc(Wins);
  160.       WinsABC.Text:='Ïîáåä: '+IntToStr(Wins);
  161.       RedrawObjects;
  162.       ShowMessage('Âû âûèãðàëè!');
  163.       DestroyObjects;
  164.       Enemies.Text:='Âðàãîâ: '+IntToStr(NumberOfEnemies);
  165.       RedrawObjects;
  166.     end;
  167.   end;
  168. end;
  169.  
  170. procedure MouseUp(x,y,mb: integer);
  171. begin
  172.   if NewGame.PTInside(x,y) then
  173.     StartTimer(t);
  174. end;
  175.  
  176. procedure KeyPress(Key: char);
  177. begin
  178.   if ((UpCase(Key)='G') or (UpCase(Key)='Ï')) and EndOfGame then
  179.   begin
  180.     EndOfGame:=False;
  181.     StartTimer(t);
  182.     CreateObjects;
  183.     kSpaceKey:=2;
  184.     kLeftKey:=False;
  185.     kRightKey:=False;
  186.   end;
  187. end;
  188.  
  189. begin
  190.   LockDrawingObjects;
  191.   EndOfGame:=True;
  192.   r1:=RectangleABC.Create(0,0,WindowWidth,38,clWhite);
  193.   NewGame:=TextABC.Create(WindowWidth-180,5,14,clBlack,'G - Íîâàÿ èãðà');
  194.   Enemies:=TextABC.Create(10,5,14,clRed,'Âðàãîâ: '+IntToStr(NumberOfEnemies));
  195.   WinsABC:=TextABC.Create(150,5,14,clRed,'Ïîáåä: '+IntToStr(Wins));
  196.   FallsABC:=TextABC.Create(280,5,14,clRed,'Ïîðàæåíèé: '+IntToStr(Falls));
  197.   StaticObjectsCount:=ObjectsCount;
  198.   Enemies.Text:='Âðàãîâ: '+IntToStr(NumberOfEnemies);
  199.   OnKeyDown:=KeyDown;
  200.   OnKeyPress:=KeyPress;
  201.   OnKeyUp:=KeyUp;
  202.   OnMouseUp:=MouseUp;
  203.   t:=CreateTimer(10,Timer1);
  204.   StopTimer(t);
  205.   RedrawObjects;
  206. end.
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement