Advertisement
Guest User

Untitled

a guest
Mar 15th, 2019
88
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Delphi 4.66 KB | None | 0 0
  1. unit MainForm;
  2.  
  3. interface
  4.  
  5. uses
  6.     Winapi.Windows, Winapi.Messages, System.SysUtils, System.Variants, System.Classes, Vcl.Graphics,
  7.     Vcl.Controls, Vcl.Forms, Vcl.Dialogs, Vcl.Menus, Vcl.StdCtrls, Vcl.ExtDlgs,
  8.   Vcl.ExtCtrls;
  9.  
  10. type
  11.     TMainForm = class(TForm)
  12.     MainMenu: TMainMenu;
  13.     FileItem: TMenuItem;
  14.     HelpItem: TMenuItem;
  15.     ExitItem: TMenuItem;
  16.     AboutItem: TMenuItem;
  17.     MainPanel: TPanel;
  18.     PaintBox: TPaintBox;
  19.     procedure FormCloseQuery(Sender: TObject; var CanClose: Boolean);
  20.     procedure ExitItemClick(Sender: TObject);
  21.     procedure AboutItemClick(Sender: TObject);
  22.     procedure FormCreate(Sender: TObject);
  23.     procedure FormPaint(Sender: TObject);
  24.     procedure FormKeyDown(Sender: TObject; var Key: Word; Shift: TShiftState);
  25.  
  26.     private
  27.         Shift: ShortInt;
  28.  
  29.         SkyBmp, PlaneBmp, PlaneLeft, PlaneRight: TBitmap;
  30.  
  31.         procedure Right;
  32.         procedure Up;
  33.         procedure Down;
  34.         procedure Left;
  35.     end;
  36.  
  37. resourcestring
  38.     QuitMessage = 'Are you sure you want to exit?';
  39.     AboutMessage = 'This program';
  40.     InvalidExtensionMessage = 'Invalid file type. Text file expected';
  41.  
  42. var
  43.     _MainForm: TMainForm;
  44.  
  45. implementation
  46.  
  47. {$R *.dfm}
  48.  
  49. procedure TMainForm.AboutItemClick(Sender: TObject);
  50. begin
  51.     MessageDlg(AboutMessage, mtInformation, [mbOk], 0);
  52. end;
  53.  
  54. procedure TMainForm.Down;
  55. var
  56.     TempBmp: TBitmap;
  57. begin
  58.     TempBmp := TBitmap.Create;
  59.     TempBmp.Width := 640;
  60.     TempBmp.Height := 480;
  61.     TempBmp.Canvas.CopyRect(Rect(0, 0, 640, 480 - Shift), SkyBmp.Canvas, Rect(0, Shift, 640, 480));
  62.     TempBmp.Canvas.CopyRect(Rect(0, 480 - Shift, 640, 480), SkyBmp.Canvas, Rect(0, 0, 640, Shift));
  63.  
  64.     SkyBmp.Canvas.Draw(0, 0, TempBmp);
  65.  
  66.     TempBmp.Canvas.Draw(0, 0, SkyBmp);
  67.     TempBmp.Canvas.Draw(200, 200, PlaneBmp);
  68.  
  69.     PaintBox.Canvas.Draw(0, 0, TempBmp);
  70.  
  71.     TempBmp.Free;
  72. end;
  73.  
  74. procedure TMainForm.ExitItemClick(Sender: TObject);
  75. begin
  76.     Close;
  77. end;
  78.  
  79. procedure TMainForm.FormCloseQuery(Sender: TObject; var CanClose: Boolean);
  80. begin
  81.     if MessageDlg(QuitMessage, mtConfirmation, mbYesNo, 0) = mrNo then
  82.         CanClose := False;
  83. end;
  84.  
  85. procedure TMainForm.FormCreate(Sender: TObject);
  86. begin
  87.     Shift := 10;
  88.  
  89.     SkyBmp := TBitmap.Create;
  90.     SkyBmp.LoadFromResourceName(HInstance, 'sky');
  91.  
  92.     PlaneLeft := TBitmap.Create;
  93.     PlaneLeft.LoadFromResourceName(HInstance, 'plane_left');
  94.     PlaneLeft.Transparent := True;
  95.  
  96.     PlaneRight := TBitmap.Create;
  97.     PlaneRight.LoadFromResourceName(HInstance, 'plane_right');
  98.     PlaneRight.Transparent := True;
  99.  
  100.     PlaneBmp := PlaneRight;
  101. end;
  102.  
  103. procedure TMainForm.FormKeyDown(Sender: TObject; var Key: Word;
  104.   Shift: TShiftState);
  105. begin
  106.     case Key of
  107.         VK_RIGHT: Right;
  108.         VK_UP: Up;
  109.         VK_DOWN: Down;
  110.         VK_LEFT: Left;
  111.     end;
  112.  
  113. end;
  114.  
  115. procedure TMainForm.FormPaint(Sender: TObject);
  116. begin
  117.     PaintBox.Canvas.Draw(0, 0, SkyBmp);
  118.     PaintBox.Canvas.Draw(200, 200, PlaneBmp);
  119. end;
  120.  
  121. procedure TMainForm.Left;
  122. var
  123.     TempBmp: TBitmap;
  124. begin
  125.     PlaneBmp := PlaneLeft;
  126.     TempBmp := TBitmap.Create;
  127.     TempBmp.Width := 640;
  128.     TempBmp.Height := 480;
  129.     TempBmp.Canvas.CopyRect(Rect(Shift, 0, 640, 480), SkyBmp.Canvas, Rect(0, 0, 640 - Shift, 480));
  130.     TempBmp.Canvas.CopyRect(Rect(0, 0, Shift, 480), SkyBmp.Canvas, Rect(640 - Shift, 0, 640, 480));
  131.  
  132.     SkyBmp.Canvas.Draw(0, 0, TempBmp);
  133.  
  134.     TempBmp.Canvas.Draw(0, 0, SkyBmp);
  135.     TempBmp.Canvas.Draw(200, 200, PlaneBmp);
  136.  
  137.     PaintBox.Canvas.Draw(0, 0, TempBmp);
  138.  
  139.     TempBmp.Free;
  140. end;
  141.  
  142. procedure TMainForm.Up;
  143. var
  144.     TempBmp: TBitmap;
  145. begin
  146.     TempBmp := TBitmap.Create;
  147.     TempBmp.Width := 640;
  148.     TempBmp.Height := 480;
  149.     TempBmp.Canvas.CopyRect(Rect(0, Shift, 640, 480), SkyBmp.Canvas, Rect(0, 0, 640, 480 - Shift));
  150.     TempBmp.Canvas.CopyRect(Rect(0, 0, 640, Shift), SkyBmp.Canvas, Rect(0, 480 - Shift, 640, 480));
  151.  
  152.     SkyBmp.Canvas.Draw(0, 0, TempBmp);
  153.  
  154.     TempBmp.Canvas.Draw(0, 0, SkyBmp);
  155.     TempBmp.Canvas.Draw(200, 200, PlaneBmp);
  156.  
  157.     PaintBox.Canvas.Draw(0, 0, TempBmp);
  158.  
  159.     TempBmp.Free;
  160. end;
  161.  
  162. procedure TMainForm.Right;
  163. var
  164.     TempBmp: TBitmap;
  165. begin
  166.     PlaneBmp := PlaneRight;
  167.     TempBmp := TBitmap.Create;
  168.     TempBmp.Width := 640;
  169.     TempBmp.Height := 480;
  170.     TempBmp.Canvas.CopyRect(Rect(0, 0, 640 - Shift, 480), SkyBmp.Canvas, Rect(Shift, 0, 640, 480));
  171.     TempBmp.Canvas.CopyRect(Rect(640 - Shift, 0, 640, 480), SkyBmp.Canvas, Rect(0, 0, Shift, 480));
  172.  
  173.     SkyBmp.Canvas.Draw(0, 0, TempBmp);
  174.  
  175.     TempBmp.Canvas.Draw(0, 0, SkyBmp);
  176.     TempBmp.Canvas.Draw(200, 200, PlaneBmp);
  177.  
  178.     PaintBox.Canvas.Draw(0, 0, TempBmp);
  179.  
  180.     TempBmp.Free;
  181. end;
  182.  
  183. end.
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement