Vanilla_Fury

delphi_egor

Jun 4th, 2021 (edited)
292
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Delphi 6.76 KB | None | 0 0
  1. unit MainForm;
  2.  
  3. interface
  4.  
  5. uses
  6.     Winapi.Windows, Winapi.Messages, System.SysUtils, System.Variants,
  7.     System.Classes, Vcl.Graphics,
  8.     Vcl.Controls, Vcl.Forms, Vcl.Dialogs, Vcl.ExtCtrls, Vcl.StdCtrls, Vcl.Menus;
  9.  
  10. type
  11.     TAnimeForm = class(TForm)
  12.         Timer1: TTimer;
  13.     ImageCanvas: TImage;
  14.     LabelSpeed: TLabel;
  15.         MainMenu1: TMainMenu;
  16.         N5: TMenuItem;
  17.         LabelToMeasureScreenOfUser: TLabel;
  18.     Label1: TLabel;
  19.         procedure FormCreate(Sender: TObject);
  20.         procedure Timer1Timer(Sender: TObject);
  21.         procedure FormKeyDown(Sender: TObject; var Key: Word;
  22.           Shift: TShiftState);
  23.         procedure N5Click(Sender: TObject);
  24.     private
  25.         MultPix: Single;
  26.     public
  27.         function MultPixels(PixQuant: Integer): Integer;
  28.     end;
  29.  
  30. const
  31.     My300 = 300;
  32.     My500 = 500;
  33.  
  34. var
  35.     AnimeForm: TAnimeForm;
  36.     BackGround: TBitMap;
  37.     Ship: TBitMap;
  38.     Can: TBitMap;
  39.     Bomb: TBitMap;
  40.     X, Y, X1, Y1: Integer;
  41.     Shx, ShXBmb, ShYBmb, Time: Integer;
  42.     Num: Integer;
  43.     Speed: Integer;
  44.     BallIsFlying: Boolean;
  45.  
  46. procedure MyMessageBoxInfo(Form: TForm; CaptionWindow, TextMessage: String; IsWarning: Boolean = False); external 'Dll_MyMessageBox.dll';
  47. function MyMessageBoxYesNo(Form: TForm; CaptionWindow, TextMessage: String; IsWarning: Boolean = False) : Boolean; external 'Dll_MyMessageBox.dll';
  48.  
  49. implementation
  50.  
  51. {$R *.dfm}
  52.  
  53. procedure TAnimeForm.FormCreate(Sender: TObject);
  54. begin
  55.     MultPix := LabelToMeasureScreenOfUser.Width / 100;
  56.  
  57.     BallIsFlying := False;
  58.  
  59.     Shx := Random(4) + 1;
  60.  
  61.     Time := 0;
  62.     X := -My300;
  63.     Y1 := My500;
  64.     Y := 80;
  65.     X1 := 1000;
  66.     ShYBmb := 0;
  67.     ShXBmb := 1;
  68.     Speed := 1;
  69.     BackGround := TBitMap.Create;
  70.     Ship := TBitMap.Create;
  71.     Can := TBitMap.Create;
  72.     Bomb := TBitMap.Create;
  73.  
  74.     BackGround.LoadFromFile('more9.bmp');
  75.  
  76.     Ship.LoadFromFile('shipp5.bmp');
  77.     Can.LoadFromFile('cn1.bmp');
  78.     Ship.transparent := true;
  79.     Can.transparent := true;
  80.     Bomb.transparent := true;
  81.  
  82.     ImageCanvas.Canvas.Draw(0, 0, BackGround);
  83.     ImageCanvas.Canvas.Draw(X, 80, Ship);
  84.     ImageCanvas.Canvas.Draw(My300, My300, Can);
  85.     Num := 0;
  86. end;
  87.  
  88. procedure ChangeCannnon(Num: Integer);
  89. Begin
  90.     case Num of
  91.         0:
  92.             Can.LoadFromFile('cn1.bmp');
  93.         1:
  94.             Can.LoadFromFile('cn2.bmp');
  95.         -1:
  96.             Can.LoadFromFile('cn4.bmp');
  97.     end;
  98. End;
  99.  
  100. procedure TAnimeForm.FormKeyDown(Sender: TObject; var Key: Word;
  101.   Shift: TShiftState);
  102. begin
  103.     if not BallIsFlying then
  104.     begin
  105.         case Key of
  106.             49, 97:
  107.                 begin
  108.                     Speed := 1;
  109.                 end;
  110.             50, 98:
  111.                 begin
  112.                     Speed := 2;
  113.                 end;
  114.             51, 99:
  115.                 begin
  116.                     Speed := 3;
  117.                 end;
  118.             52, 100:
  119.                 begin
  120.                     Speed := 4;
  121.                 end;
  122.             53, 101:
  123.                 begin
  124.                     Speed := 5;
  125.                 end;
  126.             54, 102:
  127.                 begin
  128.                     Speed := 6;
  129.                 end;
  130.             55, 103:
  131.                 begin
  132.                     Speed := 7;
  133.                 end;
  134.             56, 104:
  135.                 begin
  136.                     Speed := 8;
  137.                 end;
  138.             57, 105:
  139.                 begin
  140.                     Speed := 9;
  141.                 end;
  142.         end;
  143.         LabelSpeed.Caption := 'Скорость снаряда: ' + IntToStr(Speed);
  144.         ShXBmb := Speed;
  145.         ShYBmb := Speed;
  146.         if Num <> -1 then
  147.             if Key = 37 then
  148.             Begin
  149.                 Dec(Num);
  150.                 X1 := 2000;
  151.             End;
  152.         if Num <> 1 then
  153.             if Key = 39 then
  154.             begin
  155.                 Inc(Num);
  156.                 X1 := 2000;
  157.             end;
  158.         ChangeCannnon(Num);
  159.         if ((Key = 13) or (Key = 32)) then
  160.         Begin
  161.             BallIsFlying := True;
  162.             Y1 := 520;
  163.             case Num of
  164.                 0:
  165.                     Begin
  166.                         Y1 := My500;
  167.                         X1 := 450;
  168.                     End;
  169.                 1:
  170.                     X1 := 540;
  171.                 -1:
  172.                     X1 := 390;
  173.             end;
  174.             Bomb.LoadFromFile('bomb12.bmp');
  175.         End;
  176.     end;
  177. end;
  178.  
  179. procedure TAnimeForm.N5Click(Sender: TObject);
  180. begin
  181.     MyMessageBoxInfo(AnimeForm, 'Справка', 'Данная программа представляет собой игру, целью которой стоит уничтожение плывущего корабля.'
  182.       + #10#10 +
  183.       'Управление пушкой происходит с помощью стрелок на клавиатуре.'
  184.       + #10 + 'Кнопки от 1 до 9 задают скорость снаряда.' + #10#10 +
  185.       'Для выстрела нажмите Enter или Пробел' + #10#10 +
  186.       'Автор: Панев Александр, гр. 051007' + #10 + 'Минск, 2021');
  187. end;
  188.  
  189. procedure TAnimeForm.Timer1Timer(Sender: TObject);
  190. begin
  191.     X := X + Shx;
  192.     Y1 := Y1 - ShYBmb;
  193.     if X > 950 then
  194.     begin
  195.         X := -600;
  196.         ShYBmb := 0;
  197.         Y1 := 1000;
  198.     end;
  199.     Label1.Caption := IntToStr(X1);
  200.     ImageCanvas.Canvas.Draw(0, 0, BackGround);
  201.     ImageCanvas.Canvas.Draw(X, Y, Ship);
  202.     ImageCanvas.Canvas.Draw(-170, 30, Can);
  203.     Y1 := Y1 - ShYBmb;
  204.     if Num = 1 then
  205.     Begin
  206.         X1 := X1 + ShXBmb;
  207.     End;
  208.     if Num = -1 then
  209.     Begin
  210.         X1 := X1 - ShXBmb;
  211.     End;
  212.     ImageCanvas.Canvas.Draw(X1, Y1, Bomb);
  213.     if ((Y1 < 195) and ((X1 - X) < My300) And ((X1 - X) > 0)) then
  214.     Begin
  215.         Ship.LoadFromFile('boom10.bmp');
  216.         Shx := 0;
  217.         Time := 0;
  218.         BallIsFlying := False;
  219.     End;
  220.     if Y1 < 195 then
  221.         X1 := 2000;
  222.     if Shx = 0 then
  223.         Inc(Time);
  224.     if Time = 50 then
  225.         Y := 1000;
  226.     if Time = 70 then
  227.     begin
  228.         case MessageDlg('Отличный выстрел, хотите попробовать снова?',
  229.           mtConfirmation, [mbYes, mbNo], 0) of
  230.             mrYes:
  231.                 Begin
  232.                     Ship.LoadFromFile('shipp5.bmp');
  233.                     Y := 80;
  234.                     ShXBmb := 1;
  235.                     Speed := 1;
  236.                     X := -My300;
  237.                     LabelSpeed.Caption := 'Скорость снаряда: 1';
  238.                     Shx := Random(4) + 1;
  239.                 End;
  240.             mrNo:
  241.                 AnimeForm.Close;
  242.         end;
  243.     end;
  244. end;
  245.  
  246. function TAnimeForm.MultPixels(PixQuant: Integer): Integer;
  247. begin
  248.     Result := Round(PixQuant * MultPix);
  249. end;
  250.  
  251. end.
Add Comment
Please, Sign In to add comment