Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- unit experiment3;
- interface
- uses
- Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
- Dialogs, pngimage, ExtCtrls;
- type
- TForm1 = class(TForm)
- Image1: TImage;
- Timer1: TTimer;
- Shape1: TShape;
- Image2: TImage;
- procedure OnTick1(Sender: TObject);
- procedure FormKeyUp(Sender: TObject; var Key: Word; Shift: TShiftState);
- procedure FormKeyDown(Sender: TObject; var Key: Word; Shift: TShiftState);
- procedure OnClose(Sender: TObject; var Action: TCloseAction);
- private
- { Private declarations }
- public
- { Public declarations }
- w: boolean;
- a: boolean;
- s: boolean;
- d: boolean;
- end;
- var
- Form1: TForm1;
- location: TPoint;
- x: integer;
- y: integer;
- implementation
- {$R *.dfm}
- procedure TForm1.FormKeyDown(Sender: TObject; var Key: Word;
- Shift: TShiftState);
- begin
- if Key = 87 then
- w := true;
- if Key = 65 then
- a := true;
- if Key = 83 then
- s := true;
- if Key = 68 then
- d := true;
- end;
- procedure TForm1.FormKeyUp(Sender: TObject; var Key: Word; Shift: TShiftState);
- begin
- if Key = 87 then
- w := false;
- if Key = 65 then
- a := false;
- if Key = 83 then
- s := false;
- if Key = 68 then
- d := false;
- end;
- procedure TForm1.OnClose(Sender: TObject; var Action: TCloseAction);
- begin
- Application.Terminate;
- end;
- procedure TForm1.OnTick1(Sender: TObject);
- var IntersectionRect: TRect;
- begin
- begin
- if not(((Image1.Width + Image1.BoundsRect.TopLeft.x) >= Shape1.Left-10 ) and ((Image1.Width + Image1.BoundsRect.TopLeft.x) <= Shape1.Left+10 ) and IntersectRect(IntersectionRect, Image1.BoundsRect, Shape1.BoundsRect)) then
- begin
- if d = true then
- Image1.Left := Image1.Left + 5;
- end;
- if not((Image1.BoundsRect.BottomRight.Y >= Shape1.Top - 10) and (Image1.BoundsRect.BottomRight.Y <= Shape1.Top + 10) and IntersectRect(IntersectionRect, Image1.BoundsRect, Shape1.BoundsRect)) then
- begin
- if s = true then
- Image1.Top := Image1.Top + 5;
- end;
- if not((Image1.BoundsRect.TopLeft.X - 10 <= (Shape1.Left + Shape1.Width)) and (Image1.BoundsRect.TopLeft.X + 10 >= (Shape1.Left + Shape1.Width)) and IntersectRect(IntersectionRect, Image1.BoundsRect, Shape1.BoundsRect)) then
- begin
- if a = true then
- Image1.Left := Image1.Left - 5;
- end;
- if not((Image1.BoundsRect.TopLeft.Y <= Shape1.BoundsRect.BottomRight.y + 10) and (Image1.BoundsRect.TopLeft.Y >= Shape1.BoundsRect.BottomRight.y - 10) and IntersectRect(IntersectionRect, Image1.BoundsRect, Shape1.BoundsRect)) then
- begin
- if w = true then
- Image1.Top := Image1.Top - 5;
- end;
- end;
- end;
- end.
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement