Advertisement
Guest User

Untitled

a guest
Nov 20th, 2017
211
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.84 KB | None | 0 0
  1. unit experiment3;
  2.  
  3. interface
  4.  
  5. uses
  6. Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
  7. Dialogs, pngimage, ExtCtrls;
  8.  
  9. type
  10. TForm1 = class(TForm)
  11. Image1: TImage;
  12. Timer1: TTimer;
  13. Shape1: TShape;
  14. Image2: TImage;
  15. Shape2: TShape;
  16. procedure OnTick(Sender: TObject);
  17. procedure FormKeyUp(Sender: TObject; var Key: Word; Shift: TShiftState);
  18. procedure FormKeyDown(Sender: TObject; var Key: Word; Shift: TShiftState);
  19. procedure OnClose(Sender: TObject; var Action: TCloseAction);
  20.  
  21. private
  22. { Private declarations }
  23. public
  24. { Public declarations }
  25. w: boolean;
  26. a: boolean;
  27. s: boolean;
  28. d: boolean;
  29. end;
  30.  
  31. var
  32. Form1: TForm1;
  33. location: TPoint;
  34. x: integer;
  35. y: integer;
  36.  
  37.  
  38. implementation
  39.  
  40. {$R *.dfm}
  41.  
  42. procedure TForm1.FormKeyDown(Sender: TObject; var Key: Word;
  43. Shift: TShiftState);
  44. begin
  45. if Key = 87 then
  46. w := true;
  47. if Key = 65 then
  48. a := true;
  49. if Key = 83 then
  50. s := true;
  51. if Key = 68 then
  52. d := true;
  53. end;
  54.  
  55.  
  56. procedure TForm1.FormKeyUp(Sender: TObject; var Key: Word; Shift: TShiftState);
  57. begin
  58. if Key = 87 then
  59. w := false;
  60. if Key = 65 then
  61. a := false;
  62. if Key = 83 then
  63. s := false;
  64. if Key = 68 then
  65. d := false;
  66.  
  67. end;
  68.  
  69.  
  70. procedure TForm1.OnClose(Sender: TObject; var Action: TCloseAction);
  71. begin
  72. Application.Terminate;
  73. end;
  74.  
  75. procedure TForm1.OnTick(Sender: TObject);
  76. var IntersectionRect: TRect;
  77. begin
  78.  
  79. 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
  80. begin
  81. if d = true then
  82. Image1.Left := Image1.Left + 5;
  83. end;
  84. 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
  85. begin
  86. if s = true then
  87. Image1.Top := Image1.Top + 5;
  88. end;
  89. 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
  90. begin
  91. if a = true then
  92. Image1.Left := Image1.Left - 5;
  93. end;
  94. 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
  95. begin
  96. if w = true then
  97. Image1.Top := Image1.Top - 5;
  98. end;
  99.  
  100.  
  101.  
  102. if not(((Image1.Width + Image1.BoundsRect.TopLeft.x) >= Shape2.Left-10 ) and ((Image1.Width + Image1.BoundsRect.TopLeft.x) <= Shape2.Left+10 ) and IntersectRect(IntersectionRect, Image1.BoundsRect, Shape2.BoundsRect)) then
  103. begin
  104. if d = true then
  105. Image1.Left := Image1.Left + 5;
  106. end;
  107. if not((Image1.BoundsRect.BottomRight.Y >= Shape2.Top - 10) and (Image1.BoundsRect.BottomRight.Y <= Shape2.Top + 10) and IntersectRect(IntersectionRect, Image1.BoundsRect, Shape2.BoundsRect)) then
  108. begin
  109. if s = true then
  110. Image1.Top := Image1.Top + 5;
  111. end;
  112. if not((Image1.BoundsRect.TopLeft.X - 10 <= (Shape2.Left + Shape2.Width)) and (Image1.BoundsRect.TopLeft.X + 10 >= (Shape2.Left + Shape1.Width)) and IntersectRect(IntersectionRect, Image1.BoundsRect, Shape2.BoundsRect)) then
  113. begin
  114. if a = true then
  115. Image1.Left := Image1.Left - 5;
  116. end;
  117. if not((Image1.BoundsRect.TopLeft.Y <= Shape2.BoundsRect.BottomRight.y + 10) and (Image1.BoundsRect.TopLeft.Y >= Shape2.BoundsRect.BottomRight.y - 10) and IntersectRect(IntersectionRect, Image1.BoundsRect, Shape2.BoundsRect)) then
  118. begin
  119. if w = true then
  120. Image1.Top := Image1.Top - 5;
  121. end;
  122.  
  123.  
  124.  
  125.  
  126. end;
  127.  
  128. end.
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement