Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- unit Unit1;
- interface
- uses
- Winapi.Windows, Winapi.Messages, System.SysUtils, System.Variants, System.Classes,
- Vcl.Graphics, Vcl.Controls, Vcl.Forms, Vcl.Dialogs, Vcl.ExtCtrls, Vcl.StdCtrls, Math,
- Vcl.Imaging.GIFImg, Vcl.Imaging.PngImage, Vcl.Imaging.Jpeg, MMsystem;
- type
- TMainForm = class(TForm)
- Gun: TImage;
- Target: TImage;
- Bullet: TImage;
- Wall: TImage;
- Explosion: TImage;
- WallTimer: TTimer;
- MainTimer: TTimer;
- FireTimer: TTimer;
- InfoLabel: TLabel;
- SpeedLabel: TLabel;
- TargetVisibilityTimer: TTimer;
- LabelFactsSpeedBullet: TLabel;
- procedure FormCreate(Sender: TObject);
- procedure FormKeyDown(Sender: TObject; var Key: Word; Shift: TShiftState);
- Procedure GunFire(Sender: TObject);
- procedure WallTimerTimer(Sender: TObject);
- procedure FireTimerTimer(Sender: TObject);
- Procedure ExplodeWall(Sender: TObject);
- procedure MainTimerTimer(Sender: TObject);
- Procedure ExplodeTarget(Sender: TObject);
- procedure TargetVisibilityTimerTimer(Sender: TObject);
- private
- { Private declarations }
- public
- { Public declarations }
- end;
- var
- WallSpeed: Integer;
- BulletSpeed: Integer;
- IsBulletFire: Boolean;
- implementation
- {$R *.dfm}
- Procedure TMainForm.FormKeyDown(Sender: TObject; Var Key: Word; Shift: TShiftState);
- Begin
- If (Key = VK_UP) or (Key = Ord('W')) Then
- Gun.Top := Math.Max(Gun.Top - 10, 0)
- Else If (Key = VK_DOWN) or (Key = Ord('S')) Then
- Gun.Top := Math.Min(Gun.Top + 10, ClientHeight - Gun.Height)
- Else If Key = VK_RETURN Then
- Begin
- If Not IsBulletFire Then
- GunFire(Sender);
- End
- Else If Key In [Ord('1') .. Ord('9')] Then
- Begin
- If Not IsBulletFire Then
- Begin
- BulletSpeed := (Key - Ord('0')) * 10;
- LabelFactsSpeedBullet.Caption := IntToStr(BulletSpeed Div 10);
- End;
- End;
- End;
- procedure TMainForm.WallTimerTimer(Sender: TObject);
- Begin
- Wall.Top := Wall.Top - WallSpeed;
- If Wall.Top + Wall.Height < 0 Then
- Begin
- WallSpeed := RandomRange(4, 15);
- Wall.Top := ClientHeight;
- End;
- End;
- Procedure TMainForm.GunFire(Sender: TObject);
- Begin
- IsBulletFire := True;
- Bullet.Left := Gun.Left + Gun.Width;
- Bullet.Top := Gun.Top + (Gun.Height - Bullet.Height) Div 2;
- Bullet.Visible := True;
- FireTimer.Enabled := True;
- End;
- procedure TMainForm.FireTimerTimer(Sender:TObject);
- Begin
- If IsBulletFire Then
- Begin
- Bullet.Left := Bullet.Left + BulletSpeed;
- If Bullet.Left > ClientWidth Then
- Begin
- IsBulletFire := False;
- Bullet.Visible := False;
- End
- Else
- If Bullet.BoundsRect.IntersectsWith(Wall.BoundsRect) Then
- ExplodeWall(Sender);
- If Bullet.BoundsRect.IntersectsWith(Target.BoundsRect) Then
- ExplodeTarget(Sender);
- End;
- End;
- procedure TMainForm.MainTimerTimer(Sender: TObject);
- Begin
- Explosion.Visible := False;
- MainTimer.Enabled := False;
- (Explosion.Picture.Graphic As TGIFImage).Animate := False;
- IsBulletFire := False;
- Bullet.Visible := False;
- FireTimer.Enabled := True;
- End;
- procedure TMainForm.TargetVisibilityTimerTimer(Sender: TObject);
- Begin
- If Target.Visible Then
- Begin
- Target.Visible := False;
- Target.Left := ClientWidth - Target.Width - RandomRange(10, 100);
- Target.Top := RandomRange(10, ClientHeight - Target.Height - 10);
- End
- Else
- Target.Visible := True;
- End;
- Procedure TMainForm.ExplodeWall(Sender: TObject);
- Begin
- Explosion.Left := Wall.Left + (Wall.Width - Explosion.Width) Div 2;
- Explosion.Top := Wall.Top + (Wall.Height - Explosion.Height) Div 2;
- Explosion.Visible := True;
- (Explosion.Picture.Graphic As TGIFImage).Animate := True;
- MainTimer.Enabled := True;
- WallTimer.Enabled := True;
- FireTimer.Enabled := False;
- End;
- Procedure TMainForm.ExplodeTarget(Sender: TObject);
- Begin
- Explosion.Left := Target.Left + (Target.Width - Explosion.Width) Div 2;
- Explosion.Top := Target.Top + (Target.Height - Explosion.Height) Div 2;
- Explosion.Visible := True;
- (Explosion.Picture.Graphic As TGIFImage).Animate := True;
- MainTimer.Enabled := True;
- WallTimer.Enabled := True;
- FireTimer.Enabled := False;
- Wall.Height := RandomRange(50, 200);
- End;
- Procedure TMainForm.FormCreate(Sender: TObject);
- Begin
- Randomize;
- TargetVisibilityTimer.Interval := 3000;
- TargetVisibilityTimer.Enabled := True;
- WallSpeed := RandomRange(4, 15);
- BulletSpeed := 10;
- IsBulletFire := False;
- Gun.Left := 0;
- Gun.Top := (ClientHeight - Gun.Height) Div 2;
- Wall.Top := ClientHeight;
- End;
- end.
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement