mirror of
https://git.sr.ht/~rabbits/macintosh_cookbook
synced 2024-12-28 17:29:52 +00:00
49 lines
1.3 KiB
ObjectPascal
49 lines
1.3 KiB
ObjectPascal
program ExampleBall;
|
|
|
|
const
|
|
PICTURE_HEIGHT = 100;
|
|
PICTURE_WIDTH = 400;
|
|
BALL_SIZE = 8;
|
|
GRAVITY = -0.5;
|
|
BOUNCINESS = 0.9;
|
|
COURT_LEVEL = 100;
|
|
var
|
|
Horizontal_Position: Integer;
|
|
Vertical_Position, Velocity: Real;
|
|
drawingRect, ovalRect: Rect;
|
|
|
|
procedure DrawBall (Vertical_Position: Integer);
|
|
var
|
|
Top, Left, Bottom, Right: Integer;
|
|
begin
|
|
Top := COURT_LEVEL - Vertical_Position - BALL_SIZE;
|
|
Left := Horizontal_Position - BALL_SIZE;
|
|
Bottom := COURT_LEVEL - Vertical_Position + BALL_SIZE;
|
|
Right := Horizontal_Position + BALL_SIZE;
|
|
SetRect(ovalRect, Left, Top, Right, Bottom);
|
|
FrameOval(ovalRect);
|
|
end;
|
|
|
|
begin {bouncing ball}
|
|
|
|
ShowDrawing;
|
|
SetRect(drawingRect, 60, 60, 80 + PICTURE_WIDTH, 80 + PICTURE_HEIGHT);
|
|
SetDrawingRect(drawingRect);
|
|
|
|
Horizontal_Position := BALL_SIZE + 1;
|
|
Vertical_Position := PICTURE_HEIGHT - BALL_SIZE - 1;
|
|
Velocity := 0;
|
|
DrawBall(round(Vertical_Position));
|
|
repeat
|
|
Horizontal_Position := Horizontal_Position + 2;
|
|
Velocity := Velocity + GRAVITY;
|
|
Vertical_Position := Vertical_Position + Velocity;
|
|
if Vertical_Position <= 0 then
|
|
begin
|
|
Vertical_Position := Abs(Vertical_Position);
|
|
Velocity := -(BOUNCINESS * Velocity);
|
|
end;
|
|
DrawBall(round(Vertical_Position));
|
|
until Horizontal_Position >= PICTURE_WIDTH;
|
|
|
|
end. |