var winID := Window.Open ("graphics:700;700,nobuttonbar,title:Moving Ball,offscreenonly")
var ball :
record
x, y : real
dir : real
forward_speed, backward_speed : int
radius : int
end record
ball.x := 100
ball.y := 100
ball.dir := 90
ball.forward_speed := 3
ball.backward_speed := 2
ball.radius := 6
var keys : array char of boolean
loop
Input.KeyDown (keys)
if keys (KEY_RIGHT_ARROW) then
if ball.dir <= 0 then
ball.dir += 360
end if
ball.dir -= 0.1
end if
if keys (KEY_LEFT_ARROW) then
if ball.dir >= 360 then
ball.dir -= 360
end if
ball.dir += 0.1
end if
if keys (KEY_UP_ARROW) then
ball.x += cos (ball.dir) * ball.forward_speed
ball.y += sin (ball.dir) * ball.backward_speed
end if
if keys (KEY_DOWN_ARROW) then
ball.x -= cos (ball.dir) * ball.forward_speed
ball.y -= sin (ball.dir) * ball.backward_speed
end if
cls
drawline (round (ball.x), round (ball.y), round (ball.x) + round ((cos (ball.dir) * (ball.radius * 1.5))), round (ball.y) + round ((sin (ball.dir) * (ball.radius * 1.5))), black)
drawfilloval (round (ball.x), round (ball.y), ball.radius, ball.radius, 12)
View.Update
delay (10)
exit when keys (KEY_ESC)
end loop
Window.Close (winID)
|