Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- unit MainForm;
- interface
- uses
- Winapi.Windows, Winapi.Messages, System.SysUtils, System.Variants, System.Classes, Vcl.Graphics,
- Vcl.Controls, Vcl.Forms, Vcl.Dialogs, Vcl.ExtCtrls, Vcl.StdCtrls, Vcl.Menus;
- const
- scr_width = 767;
- scr_height = 526;
- type
- TAnimeForm = class(TForm)
- Timer1: TTimer;
- Image1: TImage;
- Label1: TLabel;
- MainMenu1: TMainMenu;
- N5: TMenuItem;
- procedure FormCreate(Sender: TObject);
- procedure Timer1Timer(Sender: TObject);
- procedure FormKeyDown(Sender: TObject; var Key: Word; Shift: TShiftState);
- procedure N5Click(Sender: TObject);
- procedure FormCloseQuery(Sender: TObject; var CanClose: Boolean);
- private
- { Private declarations }
- public
- { Public declarations }
- end;
- var
- AnimeForm: TAnimeForm;
- Fon: TBitMap;
- Korb: TBitMap;
- Can: TBitMap;
- Bomb: TBitMap;
- X, Y, X1, Y1: Integer;
- Shx, ShxBmb, ShYBmb, Time: Integer;
- Num: Integer;
- Speed: Integer;
- implementation
- {$R *.dfm}
- procedure TAnimeForm.FormCloseQuery(Sender: TObject; var CanClose: Boolean);
- begin
- CanClose := MessageDlg('Вы уверены, что хотите покинуть игру?' ,
- mtConfirmation, [mbYes, mbNo], 0) = mrYes;
- end;
- procedure TAnimeForm.FormCreate(Sender: TObject);
- begin
- shx:= Random(4) + 1;
- //
- Time := 0;
- x := -300;
- Y1 := 500;
- Y := 80;
- X1 := 1000;
- ShYBmb := 0;
- ShXBmb := 1;
- Speed := 1;
- fon:=tbitmap.Create;
- korb:=tbitmap.Create;
- Can := TBitMap.Create;
- Bomb := TBitmap.Create;
- //
- fon.LoadFromFile('more9.bmp');
- //
- korb.LoadFromFile('shipp5.bmp');
- can.LoadFromFile('cn1.bmp');
- korb.transparent := true;
- can.transparent := true;
- Bomb.Transparent := True;
- //
- image1.Canvas.Draw(0,0,fon);//
- image1.Canvas.Draw(x,80,korb);//
- image1.Canvas.Draw(300, 300, can);
- Num := 0;
- end;
- procedure ChangeCannnon(Num: Integer);
- Begin
- case Num of
- 0: can.LoadFromFile('cn1.bmp');
- 1: can.LoadFromFile('cn2.bmp');
- -1: can.LoadFromFile('cn4.bmp');
- end;
- End;
- procedure TAnimeForm.FormKeyDown(Sender: TObject; var Key: Word;
- Shift: TShiftState);
- begin
- case Key of
- 49, 97:
- begin
- Speed := 1;
- end;
- 50, 98:
- begin
- Speed := 2;
- end;
- 51, 99:
- begin
- Speed := 3;
- end;
- 52, 100:
- begin
- Speed := 4;
- end;
- 53, 101:
- begin
- Speed := 5;
- end;
- 54, 102:
- begin
- Speed := 6;
- end;
- 55, 103:
- begin
- Speed := 7;
- end;
- 56, 104:
- begin
- Speed := 8;
- end;
- 57, 105:
- begin
- Speed := 9;
- end;
- end;
- Label1.Caption := 'Скорость снаряда: '+ IntToStr(Speed);
- ShxBmb := Speed;
- ShYBmb := Speed;
- if Num <> -1 then
- if key=37 then
- Begin
- Dec(Num);
- Y1 := -200;
- End;
- if Num <> 1 then
- if key=39 then
- begin
- Inc(Num);
- Y1 := -200;
- end;
- ChangeCannnon(Num);
- if Key = 13 then
- Begin
- Y1 := 520;
- case Num of
- 0:
- Begin
- Y1 := 500;
- X1 := 450;
- End;
- 1: X1 := 540;
- -1: X1 := 390;
- end;
- Bomb.LoadFromFile('bomb12.bmp');
- End;
- end;
- procedure TAnimeForm.N5Click(Sender: TObject);
- begin
- ShowMessage
- ('Данная программа представляет собой игру, целью которой стоит уничтожение плывущего корабля.'
- + #10 + #10 + 'Корабль двигается с постоянной случайной скоростью.'
- + #10 + 'Управление пушкой происходит с помощью кнопок управления курсором.'
- + #10 + 'Кнопки от 1 до 9 задают скорость снаряда'
- + #10 + #10 + 'Для выстрела нажмите Enter');
- end;
- procedure TAnimeForm.Timer1Timer(Sender: TObject);
- begin
- x:=x+shx;
- Y1 := Y1 - ShYBmb;
- if x > 950 then
- begin
- x := -600;
- ShYBmb := 0;
- Y1 := 1000;
- end;
- image1.Canvas.Draw(0,0,fon);
- image1.Canvas.Draw(x, Y,korb);
- image1.Canvas.Draw(-170, 30, can);
- Y1 := Y1 - ShYBmb;
- if Num = 1 then
- Begin
- X1 := X1 + ShxBmb;
- End;
- if Num = -1 then
- Begin
- X1 := X1 - ShxBmb;
- End;
- image1.Canvas.Draw(X1, Y1, Bomb);
- if ((Y1 < 195) and ((X1 - X) < 300) And ((X1 - X) > 0)) then
- Begin
- korb.LoadFromFile('boom10.bmp');
- Shx := 0;
- End;
- if Y1 < 195 then
- X1 := 2000;
- if Shx = 0 then
- Inc(Time);
- if Time = 50 then
- Y := 1000;
- end;
- end.
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement