Advertisement
gguuppyy

61my

Apr 20th, 2024
14
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 4.79 KB | None | 0 0
  1. unit Unit1;
  2.  
  3. interface
  4.  
  5. uses
  6. Winapi.Windows, Winapi.Messages, System.SysUtils, System.Variants, System.Classes,
  7. Vcl.Graphics, Vcl.Controls, Vcl.Forms, Vcl.Dialogs, Vcl.ExtCtrls, Vcl.StdCtrls, Math,
  8. Vcl.Imaging.GIFImg, Vcl.Imaging.PngImage, Vcl.Imaging.Jpeg, MMsystem;
  9.  
  10. type
  11. TMainForm = class(TForm)
  12. Gun: TImage;
  13. Target: TImage;
  14. Bullet: TImage;
  15. Wall: TImage;
  16. Explosion: TImage;
  17. WallTimer: TTimer;
  18. MainTimer: TTimer;
  19. FireTimer: TTimer;
  20. InfoLabel: TLabel;
  21. SpeedLabel: TLabel;
  22. TargetVisibilityTimer: TTimer;
  23. LabelFactsSpeedBullet: TLabel;
  24. procedure FormCreate(Sender: TObject);
  25. procedure FormKeyDown(Sender: TObject; var Key: Word; Shift: TShiftState);
  26. Procedure GunFire(Sender: TObject);
  27. procedure WallTimerTimer(Sender: TObject);
  28. procedure FireTimerTimer(Sender: TObject);
  29. Procedure ExplodeWall(Sender: TObject);
  30. procedure MainTimerTimer(Sender: TObject);
  31. Procedure ExplodeTarget(Sender: TObject);
  32. procedure TargetVisibilityTimerTimer(Sender: TObject);
  33. private
  34. { Private declarations }
  35. public
  36. { Public declarations }
  37. end;
  38.  
  39. var
  40. WallSpeed: Integer;
  41. BulletSpeed: Integer;
  42. IsBulletFire: Boolean;
  43.  
  44. implementation
  45.  
  46. {$R *.dfm}
  47.  
  48. Procedure TMainForm.FormKeyDown(Sender: TObject; Var Key: Word; Shift: TShiftState);
  49. Begin
  50. If (Key = VK_UP) or (Key = Ord('W')) Then
  51. Gun.Top := Math.Max(Gun.Top - 10, 0)
  52. Else If (Key = VK_DOWN) or (Key = Ord('S')) Then
  53. Gun.Top := Math.Min(Gun.Top + 10, ClientHeight - Gun.Height)
  54. Else If Key = VK_RETURN Then
  55. Begin
  56. If Not IsBulletFire Then
  57. GunFire(Sender);
  58. End
  59. Else If Key In [Ord('1') .. Ord('9')] Then
  60. Begin
  61. If Not IsBulletFire Then
  62. Begin
  63. BulletSpeed := (Key - Ord('0')) * 10;
  64. LabelFactsSpeedBullet.Caption := IntToStr(BulletSpeed Div 10);
  65. End;
  66. End;
  67. End;
  68.  
  69.  
  70. procedure TMainForm.WallTimerTimer(Sender: TObject);
  71. Begin
  72. Wall.Top := Wall.Top - WallSpeed;
  73.  
  74. If Wall.Top + Wall.Height < 0 Then
  75. Begin
  76. WallSpeed := RandomRange(4, 15);
  77. Wall.Top := ClientHeight;
  78. End;
  79. End;
  80.  
  81. Procedure TMainForm.GunFire(Sender: TObject);
  82. Begin
  83. IsBulletFire := True;
  84. Bullet.Left := Gun.Left + Gun.Width;
  85. Bullet.Top := Gun.Top + (Gun.Height - Bullet.Height) Div 2;
  86. Bullet.Visible := True;
  87. FireTimer.Enabled := True;
  88. End;
  89.  
  90. procedure TMainForm.FireTimerTimer(Sender:TObject);
  91. Begin
  92. If IsBulletFire Then
  93. Begin
  94. Bullet.Left := Bullet.Left + BulletSpeed;
  95. If Bullet.Left > ClientWidth Then
  96. Begin
  97. IsBulletFire := False;
  98. Bullet.Visible := False;
  99. End
  100. Else
  101. If Bullet.BoundsRect.IntersectsWith(Wall.BoundsRect) Then
  102. ExplodeWall(Sender);
  103. If Bullet.BoundsRect.IntersectsWith(Target.BoundsRect) Then
  104. ExplodeTarget(Sender);
  105. End;
  106. End;
  107.  
  108. procedure TMainForm.MainTimerTimer(Sender: TObject);
  109. Begin
  110. Explosion.Visible := False;
  111. MainTimer.Enabled := False;
  112. (Explosion.Picture.Graphic As TGIFImage).Animate := False;
  113. IsBulletFire := False;
  114. Bullet.Visible := False;
  115. FireTimer.Enabled := True;
  116. End;
  117.  
  118.  
  119. procedure TMainForm.TargetVisibilityTimerTimer(Sender: TObject);
  120. Begin
  121. If Target.Visible Then
  122. Begin
  123. Target.Visible := False;
  124. Target.Left := ClientWidth - Target.Width - RandomRange(10, 100);
  125. Target.Top := RandomRange(10, ClientHeight - Target.Height - 10);
  126. End
  127. Else
  128. Target.Visible := True;
  129. End;
  130.  
  131. Procedure TMainForm.ExplodeWall(Sender: TObject);
  132. Begin
  133. Explosion.Left := Wall.Left + (Wall.Width - Explosion.Width) Div 2;
  134. Explosion.Top := Wall.Top + (Wall.Height - Explosion.Height) Div 2;
  135. Explosion.Visible := True;
  136. (Explosion.Picture.Graphic As TGIFImage).Animate := True;
  137. MainTimer.Enabled := True;
  138. WallTimer.Enabled := True;
  139. FireTimer.Enabled := False;
  140. End;
  141.  
  142. Procedure TMainForm.ExplodeTarget(Sender: TObject);
  143. Begin
  144. Explosion.Left := Target.Left + (Target.Width - Explosion.Width) Div 2;
  145. Explosion.Top := Target.Top + (Target.Height - Explosion.Height) Div 2;
  146. Explosion.Visible := True;
  147. (Explosion.Picture.Graphic As TGIFImage).Animate := True;
  148. MainTimer.Enabled := True;
  149. WallTimer.Enabled := True;
  150. FireTimer.Enabled := False;
  151. Wall.Height := RandomRange(50, 200);
  152. End;
  153.  
  154. Procedure TMainForm.FormCreate(Sender: TObject);
  155. Begin
  156. Randomize;
  157. TargetVisibilityTimer.Interval := 3000;
  158. TargetVisibilityTimer.Enabled := True;
  159. WallSpeed := RandomRange(4, 15);
  160. BulletSpeed := 10;
  161. IsBulletFire := False;
  162. Gun.Left := 0;
  163. Gun.Top := (ClientHeight - Gun.Height) Div 2;
  164. Wall.Top := ClientHeight;
  165. End;
  166.  
  167. end.
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement