function Length_Find (X1, Y1, X2, Y2 : real4) : real
result sqrt ((X1 - X2) ** 2 + (Y1 - Y2) ** 2)
end Length_Find
process Bump_Sound
sound (200, 200)
end Bump_Sound
procedure Blur_Screen (I, C : int)
for B : 1 .. I
drawline (Rand.Int (1, maxx), Rand.Int (1, maxy),
Rand.Int (1, maxx), Rand.Int (1, maxy), C)
end for
end Blur_Screen
setscreen ("graphics:700,400,nobuttonbar,nocursor")
const POWER_J := 0.02
const POWER_B := 0.02
const JUMP_S := 2
const SIZE_B := 10
const HIT_S := 15
const MID_X := maxx div 2
const MID_Y := maxy div 2
const SPEED := 1
const LENGTH_P := 40
var X1, Y1, X2, Y2 : real4
var VY1, VY2 : real4
var Score1, Score2 : nat1
var XB, YB : real4 % the ball cooridinates
var VXB, VYB : real4 % velocity of the ball
var Jump1, Jump2, Serve1, Serve2 : boolean
var Serve : boolean
var Name1, Name2 : string (20)
var Key : array char of boolean
var PauseKey : char
var Font1, Font2 : int
colorback (0)
Font1 := Font.New ("Arial:20")
Font2 := Font.New ("Arial:30")
loop
colorback (0)
cls
View.Set ("nooffscreenonly")
Font.Draw ("Goo-Ball!", 200, 200, Font2, 12)
Font.Draw ("made by Peter Watt", 200, 100, Font1, 12)
Font.Draw ("(press any key to continue)", 1, 1, Font1, 7)
PauseKey := getchar
cls
color (7)
put "The point of this game is to bump the ball into the other side"
put "of the court. The first person to score more than 10 points, "
put " and have a score higher than 2 more than your opponent wins."
color (9)
put "***CONTROLS***"
color (10)
put ""
put "Player 1"
put ""
put "Jump : up arrow key"
put "left and right : left and right arrow keys"
put ""
color (12)
put "Player 2"
put ""
put "Jump : w key"
put "left and right : a and d keys"
color (9)
put ""
put "(press any key to continue)"
PauseKey := getchar
colorback (9)
cls
Font.Draw ("Player1: enter your name", 1, maxy - 40, Font1, 10)
color (10)
locate (5, 1)
get Name1 : *
cls
Font.Draw ("Player2: enter your name", 1, maxy - 40, Font1, 12)
color (12)
locate (5, 1)
get Name2 : *
Serve := true
Serve1 := true
Score1 := 0
X1 := 40
Y1 := 10
Jump1 := false
Serve2 := false
X2 := maxx - 40
Y2 := 10
Score2 := 0
Jump2 := false
View.Set ("offscreenonly")
loop
Input.KeyDown (Key)
%cls
Blur_Screen (100, 9)
% ball reset possition
if Serve = true then
Serve := false
VXB := 0
VYB := 2
if Serve1 = true then
XB := X1
YB := 180
else
XB := X2
YB := 180
end if
end if
% player 1 movement
if Key (KEY_LEFT_ARROW) and X1 > 1 then
X1 := X1 - 1
end if
if Key (KEY_RIGHT_ARROW) and X1 + LENGTH_P < maxx div 2 then
X1 := X1 + 1
end if
if Key (KEY_UP_ARROW) and Jump1 = false then
Jump1 := true
VY1 := JUMP_S
end if
if Jump1 = true then
if Y1 < 10 then
Jump1 := false
end if
Y1 := Y1 + VY1
VY1 := VY1 - POWER_J
end if
% player 2 movement
if Key ('a') and X2 > MID_X + 40 then
X2 := X2 - 1
end if
if Key ('d') and X2 + LENGTH_P < maxx then
X2 := X2 + 1
end if
if Key ('w') and Jump2 = false then
Jump2 := true
VY2 := JUMP_S
end if
if Jump2 = true then
if Y2 < 10 then
Jump2 := false
end if
Y2 := Y2 + VY2
VY2 := VY2 - POWER_J
end if
% ball movement
%VXB := VYB - POWER_B
XB := XB + VXB
VYB := VYB - POWER_B
YB := YB + VYB
if Length_Find (X1, Y1, XB, YB) < LENGTH_P + 10 and YB > Y1 then
VXB := (XB - X1) / HIT_S
VYB := (YB - Y1) / HIT_S
fork Bump_Sound
end if
if Length_Find (X2, Y2, XB, YB) < LENGTH_P + 10 and YB > Y2 then
VXB := (XB - X2) / HIT_S
VYB := (YB - Y2) / HIT_S
fork Bump_Sound
end if
if XB < 1 or XB > maxx then
VXB := -VXB
end if
if YB < 10 then
Serve := true
if XB < MID_X then
Serve1 := false
Score2 := Score2 + 1
else
Score1 := Score1 + 1
Serve1 := true
end if
end if
% drawcourt
drawfillbox (1, 10, maxx, 1, 7)
drawfillbox (MID_X - 2, 10, MID_X + 2, 30, 7)
% draw blob 1
drawfillarc (round (X1), round (Y1), LENGTH_P, LENGTH_P, 0, 180, 10)
drawfilloval (round (X1) + 10, round (Y1) + 25, 10, 10, 0)
drawfilloval (round (X1) + 10, round (Y1) + 25, 3, 3, 7)
drawline (round (X1 + 40), round (Y1 + 10), round (X1),
round (Y1 + 10), 7)
% draw blob 2
drawfillarc (round (X2), round (Y2), LENGTH_P, LENGTH_P, 0, 180, 12)
drawfilloval (round (X2) - 10, round (Y2) + 25, 10, 10, 0)
drawfilloval (round (X2) - 10, round (Y2) + 25, 3, 3, 7)
drawline (round (X2 - 40), round (Y2 + 10), round (X2),
round (Y2 + 10), 7)
% drawball
drawfilloval (round (XB), round (YB), 10, 10, 14)
% stats
Font.Draw (Name1 + "'s score:" + natstr (Score1), 1, maxy - 20,
Font1, 10)
Font.Draw (Name2 + "'s score:" + natstr (Score2), MID_X, maxy - 20,
Font1, 12)
if Score1 > 10 or Score2 > 10 then
if Score1 > Score2 + 2 or Score2 > Score1 + 2 then
exit
end if
end if
View.Update
end loop
cls
loop
if Score1 > Score2 then
Font.Draw (Name1 + " has won!", 1, MID_Y, Font1, 10)
else
Font.Draw (Name2 + " has won!", 1, MID_Y, Font1, 12)
end if
Font.Draw ("Would you like to play again? (y/n)", 1, 1, Font1, 0)
View.Update
PauseKey := getchar
case PauseKey of
label "y", "n" :
exit
label :
end case
end loop
exit when PauseKey = "n"
end loop
cls
|