process ball1
setscreen ("graphics")
var key : array char of boolean
var x, y, r : int
x := maxx div 2 % Start at center
y := maxy div 2 % Start at center
r := 10 % Ball radius
loop
% Draw circle
drawfilloval (x, y, r, r, brightred)
Input.KeyDown (key)
% Move Left
if key (KEY_LEFT_ARROW) and x > 15 then % x>15 = left boundary
if whatdotcolor (x - 12, y) = black then
delay (85)
drawfilloval (x, y, r, r, black)
x := x - r
else
Text.Color (brightred)
put "You hit him!"
end if
% Move Right
elsif key (KEY_RIGHT_ARROW) and x < maxx - 15 then % x<maxx - 15 = right boundary
if whatdotcolor (x + 12, y) = black then
delay (85)
drawfilloval (x, y, r, r, black)
x := x + r
else
Text.Color (brightred)
put "You hit him!"
end if
% Move Up
elsif key (KEY_UP_ARROW) and y < maxy - 15 then % y<maxy-15 = top boundary
if whatdotcolor (x, y + 12) = black then
delay (85)
drawfilloval (x, y, r, r, black)
y := y + r
else
Text.Color (brightred)
put "You hit him!"
end if
% Move Down
elsif key (KEY_DOWN_ARROW) and y > 15 then % y>15 = bottom boundary
if whatdotcolor (x, y - 12) = black then
delay (85)
drawfilloval (x, y, r, r, black)
y := y - r
else
Text.Color (brightred)
put "You hit him!"
end if
end if
end loop
end ball1 %End process ball1
process ball2 %Begin process ball2
var key : array char of boolean
var x, y, r : int
x := maxx div 4
y := maxy div 4
r := 10 % Ball radius
loop
% Draw circle
drawfilloval (x, y, r, r, brightgreen)
Input.KeyDown (key)
% Move Left
if key ('a') and x > 14 then % x>15 = left boundary
if whatdotcolor (x - 12, y) = black then
delay (85)
drawfilloval (x, y, r, r, black)
x := x - r
else
Text.Color (brightgreen)
put "You hit him!"
end if
% Move Right
elsif key ('d') and x < maxx - 15 then % x<maxx - 15 = right boundary
if whatdotcolor (x + 12, y) = black then
delay (85)
drawfilloval (x, y, r, r, black)
x := x + r
else
Text.Color (brightgreen)
put "You hit him!"
end if
% Move Up
elsif key ('w') and y < maxy - 15 then % y<maxy-15 = top boundary
if whatdotcolor (x, y + 12) = black then
delay (85)
drawfilloval (x, y, r, r, black)
y := y + r
else
Text.Color (brightgreen)
put "You hit him!"
end if
% Move Down
elsif key ('s') and y > 15 then %y>15 = bottom boundary
if whatdotcolor (x, y - 12) = black then
delay (85)
drawfilloval (x, y, r, r, black)
y := y - r
else
Text.Color (brightgreen)
put "You hit him!"
end if
end if
end loop
end ball2
fork ball1
fork ball2
|