setscreen ("graphics:500;max")
setscreen ("offscreenonly")
var playerscore, computerscore : int := 0
const gravity := -0.2
const radius := 50
var chars : array char of boolean
const ballradius := 15
const xdecay := 0.995
const ydecay := 0.99
loop
var playerx : int := 126
var playery : int := 100
var computerx : int := 354
var computery : int := 100
var ballx : int := 126
var bally : int := 400
var playerjump : boolean := false
var computerjump : boolean := false
var inplayer : boolean := false
var dy, dx : real := 0
var balldx, balldy : real := 0
loop
Input.KeyDown (chars)
drawfilloval (playerx, playery, radius, radius, white)
drawfilloval (computerx, computery, radius, radius, white)
drawfilloval (ballx, bally, ballradius, ballradius, white)
if chars (KEY_LEFT_ARROW) then
playerx -= 2
if chars (KEY_UP_ARROW) and playerjump = false then
dy := 10
playery += round (dy)
playerjump := true
end if
elsif chars (KEY_RIGHT_ARROW) then
playerx += 2
if chars (KEY_UP_ARROW) and playerjump = false then
dy := 10
playery += round (dy)
playerjump := true
end if
elsif chars (KEY_UP_ARROW) and playerjump = false then
dy := 10
playery += round (dy)
playerjump := true
elsif chars (KEY_SHIFT) then
if balldx < 0.5 and balldx > -0.5 then
balldx -= 2
end if
end if
playerx += round (dx)
playery += floor (dy)
dx *= xdecay
if dy > 1 or playery > 2 then
dy += gravity
else
playery := 0
end if
dy *= ydecay
if playery < 100 then
playery := 100
playerjump := false
end if
if playerx > 199 then
playerx := 199
end if
ballx += ceil (balldx)
bally += floor (balldy)
balldx *= xdecay
if balldy > 1 or bally > 2 then
balldy += gravity
else
bally := 0
end if
if balldy > 8 then
balldy := 8
elsif balldy < -8 then
balldy := -8
end if
if Math.Distance (ballx, bally, playerx, playery) < 75 and bally >= playery and inplayer = false then
inplayer := true
balldx += (ballx - playerx) / 20
balldy += (bally - playery) / 20
elsif Math.Distance (ballx, bally, playerx, playery) > 66 then
inplayer := false
end if
if ballx > maxx - 15 then
ballx := maxx - 15
balldx *= -xdecay
elsif bally > maxy - 15 then
bally := maxy - 15
balldy *= -ydecay
elsif ballx < 15 then
ballx := 15
balldx *= -xdecay
elsif bally < 115 and ballx > 250 then
bally := 115
balldy *= -ydecay
playerscore += 1
delay (1000)
exit
elsif bally < 115 and ballx <= 250 then
bally := 115
balldy *= -ydecay
computerscore += 1
delay (1000)
exit
end if
if Math.Distance (ballx, bally, computerx, computery) < 70 and bally >= computery and inplayer = false then
inplayer := true
balldx += (ballx - computerx) / 20
balldy += (bally - computery) / 20
elsif Math.Distance (ballx, bally, computerx, computery) > 66 then
inplayer := false
end if
if balldy > 0 and bally < playery and bally > playery - 15 and Math.Distance (ballx, bally, playerx, playery) < 66 then
balldy *= -ydecay
end if
if balldy > 0 and bally < computery and bally > computery - 15 and Math.Distance (ballx, bally, computerx, computery) < 66 then
balldy *= -ydecay
end if
if computerx < ballx + 15 then
computerx += 3
elsif computerx > ballx + 15 then
computerx -= 3
end if
if computery < 100 then
playery := 100
computerjump := false
end if
if computerx < 301 then
computerx := 301
elsif computerx > maxx - 50 then
computerx := maxx - 50
end if
Text.Locate (1, maxcol div 2 - 3)
colorback (white)
put playerscore, " - ", computerscore
drawfilloval (playerx, playery, radius, radius, blue) % player
drawfilloval (computerx, computery, radius, radius, brightblue) % computer
drawfilloval (playerx + 20, playery + 20, 10, 10, white) % eye of player
drawfilloval (computerx - 20, computery + 20, 10, 10, white) % eye of computer
drawfilloval (playerx + 20, playery + 20, 5, 5, black) % eye ball of player
drawfilloval (computerx - 20, computery + 20, 5, 5, black) % eye ball of computer
drawfillbox (playerx - 50, playery - 50, playerx + 50, playery, white) % bottom half of player
drawfillbox (computerx - 50, computery - 50, computerx + 50, computery, white) % bottom half of computer
Draw.ThickLine (maxx div 2, 100, maxx div 2, maxy - 15, 3, brightred) % net
drawfillbox (0, 0, maxx, 100, green) %floor
drawfilloval (ballx, bally, ballradius, ballradius, red) % ball
Text.Locate (maxrow - 3, 14)
colorback (green)
put "Press \"SHIFT\" if the ball is stuck"
View.Update
delay(12)
end loop
end loop |