I tried my hand at putting trying to put 2 different games or modes or whatever you want to call them into one and that was a total failure. The first mode works fine by itself without the extra code and so does the other one, but the way I'm "merging" them doesn't really want to work no matter how hard I mull this over. The second mode isn't done so don't point that out I already know. I'm pretty sure it's the fact I'm using functions, but I'm just going watch as someone totally schools my code.
As a side note, the background is always blue for some reason unless I use CLS RGB(0,0,0). Otherwise I wouldn't be using that, since there's nothing to really "clear".
It's about 300 lines, so look out.
Randomize Timer()
Rem Regular Display Configuration
Set Display Mode 1024,768,32,1
Ink RGB(255,255,255),RGB(0,0,0)
Autocam Off : Backdrop Off
Rem Variables
X0=Screen Width() : Y0=Screen Height()
Global X1=X0 :Global Y1=Y0
Rem Main Menu
Line X1/2,0,X1/2,Y1
Text 750,300,"Play Wall Ball"
Text 250,300,"Play Pong"
Do
MX=MouseX()
Rem Play Pong
If MX>0 and MX<X1/2 and MouseClick()=1
CLS
Pong()
Endif
Rem Play Wall Ball
If MX>X1/2 and MX<X1 and MouseClick()=1
CLS
WallBall()
Endif
Loop
Rem Start the Pong Function
Function Pong
Hide Mouse
Randomize Timer()
Rem Load SFX
Load Sound "simple_beep.wav",1
Rem Sprite Variables
Local Red=1 :Local Blue=2 :Local Ball=3 :Local Court=4 :Local Court2=5
BallX=(X1/2) : BallY=(Y1/2)
RedY=(Y1/2)-63 : BlueY=(Y1/2)-63
Rem draw the court and get the image
Line 0,0,X1,0 : Line 0,Y1-1,X1,Y1-1
Get Image Court,0,0,X1,Y1,1
CLS
Line X1/2,0,X1/2,Y1 : Line 0,0,0,Y1-1 : Line X1-1,0,X1-1,Y1 : Circle X1/2,Y1/2,50
Get Image Court2,0,0,X1,Y1,1
Rem Setting Sprites and Loading Images
Load Image "Red.png",Red
Load Image "Blue.png",Blue
Load Image "Green.png",Ball
Sprite Court,0,0,Court
Sprite Red,25,RedY,Red
Sprite Blue,X1-50,BlueY,Blue
Sprite Ball,BallX,BallY,Ball
Offset Sprite Ball,12,12
Rem Setting Sprite Priority. The Ball and Paddels have precedence over the court(visual appeal)
For Priority=Red to Ball
Set Sprite Priority Priority,1
Next Priority
Rem Variables
ScoreRight=Sprite Width(Ball)/2
RH=Y1-Sprite Height(Red) : BH=Y1-Sprite Height(Blue)
GH=Y1-Sprite Height(Ball) : GW=X1-Sprite Width(Ball)
GameStart=1
Virgin=1
P1min=0 : P1max=0
P2min=0 : P2max=0
P1=0 : P2=0
Rem Pong Loop
Do
CLS RGB(0,0,0)
Paste Image Court2,0,0
Rem Temporary Variable code block, soon to be repositioned
RP=Sprite Y(Red) : BP=Sprite Y(Blue)
BSY=Sprite Y(Ball) : BSX=Sprite X(Ball)
Rem Main program
Gosub Paddel_Movement
Gosub Ball_Start
Gosub Ball_Movement
Gosub Ball_Collision
Gosub Collision
Gosub Score
Gosub Display_Score
Loop
End
Paddel_Movement:
Rem Left Player Movement
If Keystate(17)=1 and P1min=0 Then Move Sprite Red,5
If Keystate(31)=1 and P1max=0 Then Move Sprite Red,-5
Rem Right Player Movement
If UpKey()=1 and P2min=0 Then Move Sprite Blue,5
If DownKey()=1 and P2max=0 Then Move Sprite Blue,-5
Return
Ball_Movement:
Select BallAngle
Rem Top right movement
Case 0
Rotate Sprite Ball,TRA
Move Sprite Ball,6
Endcase
Rem Bottom right movement
Case 1
Rotate Sprite Ball,BRA
Move Sprite Ball,6
Endcase
Rem Top left movement
Case 2
Rotate Sprite Ball,BRA
Move Sprite Ball,-6
Endcase
Rem Bottom left movement
Case 3
Rotate Sprite Ball,TRA
Move Sprite Ball,-6
Endcase
Endselect
Return
Ball_Collision:
Rem Top edge ball collision
If BSY<0
TRA=Rnd(30)+15
If Ballangle=0
Ballangle=1
Endif
If Ballangle=2
Ballangle=3
Endif
Play Sound 1
Endif
Rem Bottom edge ball collision
If BSY>=GH
BRA=Rnd(25)+110
If Ballangle=1
Ballangle=0
Endif
If Ballangle=3
Ballangle=2
Endif
Play Sound 1
Endif
Return
Collision:
RedBall=Sprite Collision(Red,Ball)
Rem Red paddel Top edge Collision
If RP<=0
P1min=1
else
P1min=0
EndIf
Rem Red Paddel bottom edge collision
If RP=>RH
P1max=1
else
P1max=0
Endif
Rem Red paddel and ball collision
If RedBall=1
If Ballangle=2 Then Ballangle=0
If Ballangle=3 Then Ballangle=1
Play Sound 1
Endif
BlueBall=Sprite Collision(Blue,Ball)
Rem Blue paddel top edge collision
If BP<=0
P2min=1
else
P2min=0
Endif
Rem Blue paddel bottom edge collision
If BP=>BH
P2max=1
else
P2max=0
Endif
Rem Blue paddel and Ball Collision
If BlueBall=1
If Ballangle=0 Then Ballangle=2
If Ballangle=1 Then Ballangle=3
Play Sound 1
Endif
Return
Ball_Start:
Rem Randomly serveball at an angle
Rem Check for the Start of the Game
If GameStart=1
Dec GameStart,1
If Virgin=1
CLS RGB(0,0,0)
Paste Image Court2,0,0
Center Text X1/2,Y1/2+40,"Please, Press a button to continue"
wait key
Virgin=0
EndIf
Rem Random Variable
BallAngle=Rnd(3)
TRA=45
BRA=135
Endif
Return
Rem lumped the scoreing and reseting of the balls together
Score:
Rem Player to the left scores
If BSX=>GW
Inc P1,1
Delete Sprite Ball
Sprite Ball,BallX,BallY,Ball
GameStart=1
Endif
Rem Player to the right scores
If BSX=<0
Inc P2,1
Delete Sprite Ball
Sprite Ball,BallX,BallY,Ball
GameStart=1
Endif
Return
Display_Score:
Set Text Size 50
Rem Left player's score
Text (X1/2)-50,50,STR$(P1)
Rem Right player's score
Text (X1/2)+25,50,STR$(P2)
Return
ExitFunction
EndFunction
Rem Start the Wall Ball Game
Function WallBall
Randomize Timer()
Rem Variables
DIM Screen(1)
Screen(0)=Screen Width() : Screen(1)=Screen Height()
Right=1 : Left=1
Kick=RND(3)
Local Red=1 : Local Green=2
Rem Make Court
Line 0,0,Screen(0),0
Get Image 3,0,0,Screen(0),1
CLS RGB(0,0,0)
Line 0,0,0,Screen(1)
Line Screen(0)-1,0,Screen(0)-1,Screen(1)
Get Image 4,0,0,Screen(0),Screen(1)
Rem Load Media for use
Load Sound "simple_beep.wav",1
Load Image "Red.png",Red
Load Image "Green.png",Green
Rem Initialize Sprites
Sprite Red,(Screen(0)/2)+63,Screen(1)-50,Red
Sprite Green,Screen(0)/2,Screen(1)/2,Green
Sprite 3,0,0,3
Sprite 4,0,0,4
Rem Manipulate Sprites
Rotate Sprite Red,90
Stretch Sprite Red,100,150
Offset Sprite Green,12,12
Rem Main Wall Ball Loop
Do
CLS
Gosub Paddel_Movement
Gosub Paddel_Collision
Gosub Ball_Movement
Gosub Ball_Collision
Loop
End
Paddel_Movement:
If RightKey()=1 and Right=1 then Move Sprite Red,5
If LeftKey()=1 and Left=1 then Move Sprite Red,-5
Return
Paddel_Collision:
Rem If the Paddel hits the right stop movement
If Sprite X(Red)>Screen(0)
Right=0
Else
Right=1
Endif
Rem If the Paddel hits the left stop movement
If (Sprite X(Red)-Sprite Height(Red))<0
Left=0
Else
Left=1
Endif
Return
Ball_Movement:
Select Kick
Rem move to lower right
Case 0
Rotate Sprite Green,135
Move Sprite Green,1
EndCase
Rem move to lower left
Case 1
Rotate Sprite Green,225
Move Sprite Green,1
EndCase
Rem Move to upper right
Case 2
Rotate Sprite Green,45
Move Sprite Green,1
EndCase
Rem Move to upper left
Case 3
Rotate Sprite Green,315
Move Sprite Green,1
EndCase
EndSelect
Return
Rem Handels the collision of the ball
Ball_Collision:
Rem All the variables needed for the collision
RedBall=Sprite Collision(Green,Red)
TopBall=Sprite Collision(Green,3)
CourtBall=Sprite Collision(Green,4)
Rem Paddel and ball hitting
If RedBall=1
If Kick=0 Then Kick=2
If Kick=1 Then Kick=3
Endif
Rem Court and ball hitting
If CourtBall=1
Rem Lower right to lower left
If Kick=0 then Kick=1
Rem Lower left to lower right
If Kick=1 then Kick=0
Rem Upper right to upper left
If Kick=2 then Kick=3
Rem Upper left to upper right
If Kick=3 then Kick=2
Endif
Return
ExitFunction
EndFunction
I couldn't figure out how to load multiple files, sorry. I'm sure someone can just whip up 3 colored sprites in 5 seconds.