

setrgb 0,0,0,0
open window 640,512
rem gosub title
gosub intro
setrgb 0,50,50,255
open window 640,512
beep
pause .1
beep
gosub playerprompt
if players=1 gosub diffprompt
if players=2 gosub paramaters
if players=2 gosub paramaters2
gosub setup
gosub loop
exit

'####################################################
'## Nice title screen
'####################################################

label title
text 220,200, "Christopher Rankine"
pause 3 
clear window
text 270,200, "Presents"
pause 2 
clear window
text 230,200, "A Lab Production"
pause 2
clear window
text 270,200, "WallBall"
pause 2 
clear window
return

'####################################################
'## Text introduction
'####################################################
label intro
gosub intro_text
repeat
c=peek("port1")
if and(c,16384)>0 then
pause .5
close window
return
fi
if and(c,1)>0 end
until (and(c,1)>0)
return

label intro_text
text 100,40, "Welcome to WallBall. Press X to begin."
text 100,60, "It has two modes - a one player mode and a"
text 100,80, "two player mode. "
text 100,100, "In the one player mode you must score "
text 100,120, "points by hitting the ball against the wall"
text 100,140, "on the right hand side of the screen. If " 
text 100,160, "you miss the ball you loose a continue. If"
text 100,180, "you run out of continues and miss again "
text 100,200, "then it is game over. There are 3 difficulty"
text 100,220, "settings."
text 100,240, "In the two player mode you must beat your "
text 100,260, "opponent. To do this you must score points"
text 100,280, "by hitting the ball against the wall. After"   
text 100,300, "so many points you win sets and then the "
text 100,320, "match. The game always starts with player 1"
text 100,340, "shooting. Player 2 cannot hit it until "
text 100,360, "player 1 hits the ball or misses. It is "
text 100,380, "then player 2 who gets a shot where player"
text 100,400, "one can't hit the ball until player 2 hits"
text 100,420, "or misses. This cycle continues until a set"
text 100,440, "is won where the player who looses the set "
text 100,460, "hits next. The current player is displayed"
text 100,480, "at the top of the screen. You can custom "
text 100,500, "the amount of points and sets in each match."
return

'####################################################
'## Select the amount of players
'####################################################
label playerprompt
gosub playerdisplay
repeat
c=peek("port1")
if and(c,8192)>0 then
players=2
pause .5
clear window
pl2diff=1
return
fi
if and(c,16384)>0 then
players=1 
pause .5
clear window
return
fi
if and(c,1)>0 end
until (and(c,1)>0)
return

label playerdisplay
setrgb 1,255,255,255
text 10,100, "Press x for 1 player game"
text 10,120, "Press O for 2 player game"
text 10,140, "Press select to quit"
return

'####################################################
'## Select difficulty level in one player mode
'####################################################

label diffprompt
gosub display
repeat 
c=peek("port1")
if and(c,8192)>0 then
hard=1
pause 1
clear window
return
fi
if and(c,16384)>0 then
medium=1
pause 1
clear window
return
fi
if and(c,32768)>0 then
easy=1
pause 1
clear window
return
fi
if and(c,1)>0 end
until (and(c,1)>0)
return

label display
setrgb 1,255,255,255
text  20,50, "Press SQUARE for easy mode. Its the best mode for beginners"
text  20,70, "Press X for medium mode. Recommened mode."
text  20,90, "Press O for hard mode. I dare you to win this!"
return 

'####################################################
'## Select amount of points and sets in each match
'####################################################

label paramaters
gosub paramdisplay
repeat 
c=peek("port1")
if and(c,8192)>0 then
maxpoints=11
pause 1
clear window
return
fi
if and(c,16384)>0 then
maxpoints=7
pause 1
clear window
return
fi
if and(c,32768)>0 then
maxpoints=5
pause 1
clear window
return
fi
if and(c,1)>0 end
until (and(c,1)>0)
return

label paramdisplay
setrgb 1,255,255,255
text  20,50, "Press SQUARE 5 points per set."
text  20,70, "Press X for 7 points per set."
text  20,90, "Press O for 11 points per set."
return 

label paramaters2
gosub paramdisplay2
repeat 
c=peek("port1")
if and(c,8192)>0 then
maxsets=7
pause 1
clear window
return
fi
if and(c,16384)>0 then
maxsets=5
pause 1
clear window
return
fi
if and(c,32768)>0 then
maxsets=3
pause 1
clear window
return
fi
if and(c,1)>0 end
until (and(c,1)>0)
return

label paramdisplay2
setrgb 1,255,255,255
text  20,50, "Press SQUARE 3 sets per match."
text  20,70, "Press X for 5 sets per match."
text  20,90, "Press O for 7 sets per match."
return 
'####################################################
'## Sets up variables
'####################################################

label setup
strike=1
batx=25
baty=50
ballx=310
bally=246
pl2batx=50
pl2baty=400
xmove=7
ymove=ran(-5)
length=8
width=50
points=0
points2=0
set1=0
match1=0
set2=0
match2=0
cont=3
ptx=420
pty=20
return

'####################################################
'## Main loop
'####################################################

label loop
repeat 
c=peek("port1")
setdispbuf d
d=1-d
setdrawbuf d
clear window
gosub diff
gosub bat
gosub ball
gosub movement
gosub collision
if players=1 gosub game1
if players=2 gosub game2
if players=1 gosub stat1
if players=2 gosub stat2
until (and(c,1)>0)
return

'####################################################
'## Text displayed during one player mode
'####################################################

label stat1
text 20,40, "Player 1 points: " + str$(points)
text 420,40, "Continues : "  + str$(cont)
return

'####################################################
'## Text displayed during two player mode
'####################################################

label stat2
text 50,45,"Current player's shot : Player " + str$(strike)
rectangle ptx,pty to ptx+180,pty+80
text 480,35, "Points " + " Set"
text 420,55,"PL1" + "    " + str$(points)  + "       "  + str$(set1)
text 420,75,"PL2" + "    " + str$(points2) + "       "  + str$(set2)
return

'####################################################
'## Sets up difficulty levels
'####################################################

label diff
if easy=1 then
my=5
spin=3
maxspeed=5
crazyangle=1
fi
if medium=1 then
my=8
spin=3
maxspeed=8
crazyangle=1
fi
if hard=1 then
my=8
spin=5
maxspeed=12
crazyangle=2
fi
if pl2diff=1 then
my=8
my2=8
spin=3
maxspeed=10
crazyangle=1
fi
return

'####################################################
'## Set up one player match
'####################################################

label game1
if players=1 then
if points=11 then
close window
gosub win
fi
fi
return

'####################################################
'## Set up two player match
'####################################################

label game2
if players=2 then
if points=maxpoints then
set1=set1+1
points=0
points2=0
fi
fi
if set1=maxsets then
match1=1
fi
if players=2 then
if points2=maxpoints then
set2=set2+1
points=0
points2=0
fi
fi
if set2=maxsets then
match2=1
fi
if match1=1 then 
close window
gosub win1
fi
if match2=1 then 
close window
gosub win2
fi
return

'####################################################
'## Win screens
'####################################################

label win
open window 640,512
text 220,240, "You won the match."
text 220,260, "Press select to end."
repeat
c=peek("port1")
if and(c,1)>0 end
until (and(c,1)>0)
return

label win1
open window 640,512
text 220,240, "Player 1 won the match."
text 220,260, "Press select to end."
repeat
c=peek("port1")
if and(c,1)>0 end
until (and(c,1)>0)
return

label win2
open window 640,512
text 220,240, "Player 2 won the match."
text 220,260, "Press select to end."
repeat
c=peek("port1")
if and(c,1)>0 end
until (and(c,1)>0)
return

'####################################################
'## Draws the bat(s)
'####################################################

label bat
if players=1 then
setrgb 1,255,255,255
fill rectangle batx,baty to batx+length,baty+width
fi
if players=2 then
setrgb 1,255,255,255
fill rectangle batx,baty to batx+length,baty+width
setrgb 1,0,0,0
fill rectangle pl2batx,pl2baty to pl2batx+length,pl2baty+width
fi
return

'####################################################
'## Draws and moves the ball
'####################################################

label ball
setrgb 1,255,255,255
fill circle ballx,bally,6
bally=bally+ymove
ballx=ballx-xmove

if players=1 then
if ballx<-5 then
cont=cont-1
ballx=600
ymove=ymove-3
fi
fi

if cont<0 end

if ballx>640 then
if players=1 then
xmove=-xmove
points=points+1
fi
fi

if players=2 then
if ballx<-5 then
strike=strike+1
ballx=600
ymove=ymove-3
pause 1
fi
fi

if ballx>640 then
if players=2 then
if strike=1 then
xmove=-xmove
points2=points2+1
fi
fi
fi

if ballx>640 then
if players=2 then
if strike=2 then
xmove=-xmove
points=points+1
fi
fi
fi
if bally<10 ymove=-ymove+spin
if bally>512 ymove=-ymove-spin
return

'####################################################
'## Collision between bat(s) and ball
'####################################################

label collision
if players=1 then
if ballx<(batx+length) and ballx>(batx) then
if bally>(baty+1) then
if bally<(baty+(width+1)) then
beep
xmove=-(xmove)
ymove=(ymove+(ran(spin)))
fi
fi
fi
fi
if players=2 then
if strike=1 then
if xmove>0 then
if ballx<(batx+length) and ballx>(batx) then
if bally>(baty) then
if bally<(baty+width) then
beep
xmove=-xmove
ymove=(ymove+(ran(spin)))
strike=strike+1
fi
fi
fi
fi
fi
fi

if players=2 then
if strike=2 then
if xmove>0 then
if ballx<(pl2batx+length) and ballx>(pl2batx) then
if bally>(pl2baty) then
if bally<(pl2baty+width) then
beep
xmove=-(xmove)
ymove=(ymove+(ran(spin)))
strike=strike+1
fi
fi
fi
fi
fi
fi
if strike>2 strike=1
if ymove>maxspeed then
ymove=ymove-crazyangle
fi
if ymove<-maxspeed then
ymove=ymove+crazyangle
fi
return

'####################################################
'## Moves bat(s)
'####################################################

label movement
c=peek("port1")
if and(c,64)>0 then
baty=baty+my
fi
if and(c,16)>0 then
baty=baty-my
fi
if baty<10 baty=10
if baty>462 baty=462

c=peek("port2")
if and(c,64)>0 then
pl2baty=pl2baty+my2
fi
if and(c,16)>0 then
pl2baty=pl2baty-my2
fi
if pl2baty<10 pl2baty=10
if pl2baty>462 pl2baty=462
return


