setscreen ("graphics:700;max,position:center;center,nobuttonbar,offscreenonly")
var x, y, button, paddlex, paddley, lastballx, lastbally := 100
var ballx, bally : real := 100
var power := 5
var dx, dy : real := 1
proc drawscreen
drawfillbox (0, 0, maxx, maxy, red) % Border
drawfillbox (20, 20, maxx - 20, maxy - 20, 1) %Background
drawfillbox (20, maxy div 2 - 150, maxx - 20, maxy div 2 - 155, red) % bottom line from center
drawfillbox (20, maxy div 2 + 150, maxx - 20, maxy div 2 + 155, red) % top line from center
drawfillbox (20, 20, maxx - 20, 30, grey) % bottom
drawfillbox (maxx div 2 - 70, 20, maxx div 2 + 70, 40, black) % net
drawfillbox (20, maxy - 20, maxx - 20, maxy - 30, grey) % top
drawfillbox (maxx div 2 - 70, maxy - 20, maxx div 2 + 70, maxy - 40, black) % net
drawfillbox (20, maxy div 2, maxx - 20, maxy div 2 + 5, grey) %center line
%Center Circle
drawfilloval (maxx div 2, maxy div 2, 80, 80, grey)
drawfilloval (maxx div 2, maxy div 2, 70, 70, 1)
drawfilloval (maxx div 2, maxy div 2, 10, 10, grey)
% Left top circle
drawfilloval (maxx div 2 - 200, maxy div 2 + 250, 70, 70, grey)
drawfilloval (maxx div 2 - 200, maxy div 2 + 250, 60, 60, 1)
% Right top circle
drawfilloval (maxx div 2 + 200, maxy div 2 + 250, 70, 70, grey)
drawfilloval (maxx div 2 + 200, maxy div 2 + 250, 60, 60, 1)
% Right bottom
drawfilloval (maxx div 2 + 200, maxy div 2 - 250, 70, 70, grey)
drawfilloval (maxx div 2 + 200, maxy div 2 - 250, 60, 60, 1)
% Left bottom
drawfilloval (maxx div 2 - 200, maxy div 2 - 250, 70, 70, grey)
drawfilloval (maxx div 2 - 200, maxy div 2 - 250, 60, 60, 1)
%ball
drawfilloval (round (ballx), round (bally), 15, 15, 7)
%paddle
drawfilloval (paddlex, paddley, 35, 35, 12)
View.Update
cls
end drawscreen
proc detection
if ballx > maxx or ballx < 0 then
dx *= -1
end if
if bally > maxy or bally < 0 then
dy *= -1
end if
if abs (sqrt ((ballx - paddlex) ** 2 + (bally - paddley) ** 2)) < 35 then
dx := (ballx - paddlex) / 10
dy := (bally - paddley) / 10
end if
end detection
loop
mousewhere (x, y, button)
if y > maxy div 2 then
paddley := maxy div 2
else
paddley := y
end if
if x > maxx then
paddlex := maxx
elsif x < 0 then
paddlex := 0
else
paddlex := x
end if
ballx += dx
bally += dy
detection
if abs (ballx - lastballx) > power or abs (bally - lastbally) > power then
lastballx := round (ballx)
lastbally := round (bally)
drawscreen
end if
end loop
|