Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- Unit Unit6Laba61;
- Interface
- Uses
- Winapi.Windows,
- Winapi.Messages,
- System.SysUtils,
- System.Variants,
- System.Classes,
- Vcl.Graphics,
- Vcl.Controls,
- Vcl.Forms,
- Vcl.Dialogs,
- Vcl.ExtCtrls,
- Vcl.Imaging.Jpeg,
- Vcl.Imaging.Pngimage,
- Math,mmsystem,
- Vcl.StdCtrls, Vcl.Menus, Vcl.Imaging.GIFImg, Vcl.MPlayer;
- Type
- TMainFireForm = Class(TForm)
- FireTimer: TTimer;
- MainTimer: TTimer;
- GayTimer: TTimer;
- Gun: TImage;
- Bullet: TImage;
- Target: TImage;
- Wall: TImage;
- Svofard: TImage;
- LabelSpeedBullet: TLabel;
- LabelFactsSpeedBullet: TLabel;
- Explosion: TImage;
- TimerGif: TTimer;
- TargetVisibilityTimer: TTimer;
- MainMenuGame: TMainMenu;
- Instruction: TMenuItem;
- Developer: TMenuItem;
- MediaPlayer: TMediaPlayer;
- Procedure FormCreate(Sender: TObject);
- Procedure FormKeyDown(Sender: TObject; Var Key: Word; Shift: TShiftState);
- Procedure GunFire(Sender: TObject);
- Procedure GayTimerTimer(Sender: TObject);
- Procedure FireTimerTimer(Sender: TObject);
- Procedure ExplodeWall(Sender: TObject);
- Procedure MainTimerTimer(Sender: TObject);
- Procedure ExplodeTarget(Sender: TObject);
- Procedure TimerGifTimer(Sender: TObject);
- Procedure TargetVisibilityTimerTimer(Sender: TObject);
- procedure InstructionClick(Sender: TObject);
- procedure DeveloperClick(Sender: TObject);
- Private
- { Private declarations }
- Public
- { Public declarations }
- End;
- Var
- MainFireForm: TMainFireForm;
- WallSpeed: Integer;
- BulletSpeed: Integer;
- IsBulletFire: Boolean;
- Implementation
- {$R *.dfm}
- Procedure TMainFireForm.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 TMainFireForm.GayTimerTimer(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 TMainFireForm.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 TMainFireForm.InstructionClick(Sender: TObject);
- Var
- MessageBoxCaption: String;
- MessageBoxText: String;
- IsMessageShow: Boolean;
- Begin
- IsMessageShow := False;
- if not IsMessageShow then
- Begin
- IsMessageShow := True;
- MessageBoxCaption := 'Инструкция';
- MessageBoxText :=
- '1) Скорость выстрела можно изменять при нажатии на клавиши цифр.'#10'2)
- Чтобы произвести выстрел, нажмите Enter.'#10'3) Чтобы передвигать
- оружие вверх и вниз, используйте клавиши ↑ и ↓, а так же W и S';
- MessageBox(Handle, PChar(MessageBoxText),
- PChar(MessageBoxCaption), MB_OK);
- End;
- IsMessageShow := False;
- end;
- Procedure TMainFireForm.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 TMainFireForm.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 TMainFireForm.TimerGifTimer(Sender: TObject);
- Begin
- Svofard.SendToBack;
- (Svofard.Picture.Graphic As TGIFImage).Animate := True;
- End;
- Procedure TMainFireForm.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 TMainFireForm.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;
- GayTimer.Enabled := True;
- FireTimer.Enabled := False;
- MediaPlayer.FileName := 'C:\Users\Даниил\Downloads\pukane-4.wav';
- MediaPlayer.Open;
- MediaPlayer.Play;
- End;
- procedure TMainFireForm.DeveloperClick(Sender: TObject);
- Var
- MessageBoxCaption: String;
- MessageBoxText: String;
- IsMessageShow: Boolean;
- Begin
- IsMessageShow := False;
- if not IsMessageShow then
- Begin
- IsMessageShow := True;
- MessageBoxCaption := 'О разработчике';
- MessageBoxText :=
- 'Машевский Даниил Витальевич, группа 351003, Лабораторная
- №6.1.'#10''#10'Задача:'#10'Произвести анимацию выстрела из оружия в мишень
- с движущимся препятствием, в виде стены';
- MessageBox(Handle, PChar(MessageBoxText),
- PChar(MessageBoxCaption), MB_OK);
- End;
- IsMessageShow := False;
- end;
- Procedure TMainFireForm.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;
- GayTimer.Enabled := True;
- FireTimer.Enabled := False;
- MediaPlayer.FileName := 'C:\Users\Даниил\Desktop\8\Мое-видео.wav';
- MediaPlayer.Open;
- MediaPlayer.Play;
- Wall.Height := RandomRange(50, 200);
- End;
- Procedure TMainFireForm.FormCreate(Sender: TObject);
- Begin
- Randomize;
- TimerGif.Enabled := True;
- TargetVisibilityTimer.Interval := 3000;
- TargetVisibilityTimer.Enabled := True;
- WallSpeed := RandomRange(4, 15);
- BulletSpeed := 10;
- IsBulletFire := False;
- Gun.Left := 0;
- Gun.Top := (ClientHeight - Gun.Height) Div 2;
- Svofard.SendToBack;
- (Svofard.Picture.Graphic As TGIFImage).Animate := True;
- Wall.Left := 430;
- Wall.Top := ClientHeight;
- End;
- End.
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement