Advertisement
B3ar6

Lazarus - ball

Jan 18th, 2018
210
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.55 KB | None | 0 0
  1. unit Unit1;
  2.  
  3. {$mode objfpc}{$H+}
  4.  
  5. interface
  6.  
  7. uses
  8. Classes, SysUtils, FileUtil, Forms, Controls, Graphics, Dialogs, StdCtrls,
  9. ExtCtrls;
  10.  
  11. type
  12.  
  13. { TForm1 }
  14.  
  15. TForm1 = class(TForm)
  16. Button1: TButton;
  17. Button2: TButton;
  18. Button3: TButton;
  19. Button4: TButton;
  20. Shape1: TShape;
  21. Timer1: TTimer;
  22. procedure Button1Click(Sender: TObject);
  23. procedure Button2Click(Sender: TObject);
  24. procedure Button3Click(Sender: TObject);
  25. procedure Button4Click(Sender: TObject);
  26. procedure FormCreate(Sender: TObject);
  27. procedure Timer1Timer(Sender: TObject);
  28. private
  29.  
  30. public
  31.  
  32. end;
  33.  
  34. var
  35. Form1: TForm1;
  36. x,y: Integer;
  37.  
  38. implementation
  39.  
  40. {$R *.lfm}
  41.  
  42. { TForm1 }
  43.  
  44. procedure TForm1.Button3Click(Sender: TObject);
  45. begin
  46. Shape1.left := Shape1.Left - 10;
  47. end;
  48.  
  49. procedure TForm1.Button4Click(Sender: TObject);
  50. begin
  51. Shape1.top := Shape1.top + 10;
  52. end;
  53.  
  54. procedure TForm1.FormCreate(Sender: TObject);
  55. begin
  56. x := 5;
  57. y := 5;
  58. Timer1.Interval := 100;
  59. end;
  60.  
  61. procedure TForm1.Timer1Timer(Sender: TObject);
  62. begin
  63. if(Shape1.left+Shape1.Width>Form1.Width) then x:=-x;
  64. if(Shape1.Left<0) then x:=-x;
  65.  
  66. if(Shape1.Top+Shape1.Height>Form1.Height) then y:=-y;
  67. if(Shape1.Top<0) then y:=-y;
  68.  
  69. Shape1.left := Shape1.Left + x;
  70. Shape1.top := Shape1.top - y;
  71. end;
  72.  
  73. procedure TForm1.Button2Click(Sender: TObject);
  74. begin
  75. Shape1.left := Shape1.Left + 10;
  76. end;
  77.  
  78. procedure TForm1.Button1Click(Sender: TObject);
  79. begin
  80. Shape1.top := Shape1.top - 10;
  81. end;
  82.  
  83. end.
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement