....If you compile the code I have uploaded (without any changes

The code is not organised the way it would be for an 'office app', in fact to me it looks 'old fashioned' using the Gosubs (I didn't even know PB had them!

Code: Select all
InitSprite ()
InitKeyboard ()
InitSound ()
InitMouse ()
Global timer.i = 0
Global musix.i = 100
Global effects.i = 100
Global musixtate.i = 1
Global effectsstate.i = 1
Global spriteloader.i = 0
Global Number.i = 1
Global ScreenOpen.i = 0
Global screenx.i = 640
Global screeny.i = 480
Global circlex.i = 200
Global Black.i = RGB (0,0,0)
Global White.i = RGB (255,255,255)
Global Font1Colour.i = White
Global Font1ColourBk.i = Black
Global Font2Colour.i =White
Global Font2ColourBk.i = Black
Global Font3Colour.i = White
Global Font2ColourBk.i = Black
Global Font4Colour.i = White
Global Font4ColourBk.i = Black
Global Font5Colour.i = White
Global Font5ColourBk.i = Black
Global circley.i = Random (480)
Global move.i = 1
Global move2.i = 1
Global player1x.i = 0
Global player1y.i = 200
Global player2x.i = 635
Global player2y.i = 200
Global ticker = Random (3)
Global zieg.s = "C:\Program Files\ProgMaster\Pong\"
If ticker = 1
move * -1
ElseIf ticker = 3
move2 * -1
ElseIf ticker = 0
move * 1
ElseIf ticker = 2
move2 * 1
EndIf
Procedure Ending ()
CloseScreen ()
End
EndProcedure
Procedure Controls ()
ending ()
EndProcedure
Procedure Videosettings ()
ending ()
EndProcedure
Procedure Options ()
Repeat
ClearScreen (0)
ExamineKeyboard ()
ExamineMouse ()
StartDrawing (ScreenOutput ())
DrawingFont (FontID(0))
twho = TextWidth ("Options")
twho2 = TextHeight ("Options")
awidth1 = (screenx / 2) - (twho / 2)
DrawText (awidth1,200,"Options",RGB(255,255,255),0)
DrawingFont (FontID(1))
If musixtate = 1
twmo = TextWidth ("Music on")
twmo2 = TextHeight ("Music on")
bwidth1 = (screenx / 2) - (twmo / 2)
DrawText (bwidth1,250,"Music on",Font1Colour,Font1ColourBk) ;200,250
Else
twmof = TextWidth ("Music off")
twmof2 = TextHeight ("Music off")
gwidth1 = (screenx / 2) - (twmof / 2)
DrawText (gwidth1,250,"Music off",Font1Colour,Font1ColourBk)
EndIf
If effectsstate = 1
tweo = TextWidth ("Effects on")
tweo2 = TextHeight ("Effects on")
cwidth1 = (screenx / 2) - (tweo / 2)
DrawText (cwidth1,280, "Effects on",Font2Colour,Font2ColourBk)
Else
tweof = TextWidth ("Effects off")
tweof2 = TextHeight ("Effects off")
hwidth1 = (screenx / 2) - (tweof / 2)
DrawText (hwidth1,280, "Effects off",Font2Colour,Font2ColourBk)
EndIf
twvs = TextWidth ("Video Settings")
twc = TextWidth ("Controls")
twb = TextWidth ("Back")
twvs2 = TextHeight ("Video Settings")
twc2 = TextHeight ("Controls")
twb2 = TextHeight ("Back")
dwidth1 = (screenx / 2) - (twvs / 2)
ewidth1 = (screenx / 2) - (twc / 2)
fwidth1 = (screenx / 2) - (twb / 2)
DrawText (dwidth1,310,"Video Settings",Font3Colour,Font3ColourBk)
DrawText (ewidth1,340, "Controls",Font4Colour,Font4ColourBk)
DrawText (fwidth1,370, "Back",Font5Colour,Font5ColourBk)
Box (MouseX (), MouseY (), 3,3,255)
StopDrawing ()
If MouseX () > bwidth1 And MouseX () < bwidth1 + twmo And MouseY () > 250 And MouseY () < 250 + twmo2 ;200,263,250,270
Font1Colour = Black
Font1ColourBk = White
Covered = 1
Else
Font1Colour = White
Font1ColourBk = Black
EndIf
If MouseX () > cwidth1 And MouseX () < cwidth1 + tweo And MouseY () > 280 And MouseY () < 280 + tweo2
Font2Colour = Black
Font2ColourBk = White
Covered = 2
Else
Font2Colour = White
Font2ColourBk = Black
EndIf
If MouseX () > dwidth1 And MouseX () < dwidth1 + twvs And MouseY () > 310 And MouseY () < 310 + twvs2
Font3Colour = Black
Font3ColourBk = White
Covered = 3
Else
Font3Colour = White
Font3ColourBk = Black
EndIf
If MouseX () > ewidth1 And MouseX () < ewidth1 + twc And MouseY () > 340 And MouseY () < 340 + twc2
Font4Colour = Black
Font4ColourBk = White
Covered = 4
Else
Font4Colour = White
Font4ColourBk = Black
EndIf
If MouseX () > fwidth1 And MouseX () < fwidth1 + twb And MouseY () > 370 And MouseY () < 370 + twb2
Font5Colour = Black
Font5ColourBk = White
Covered = 5
Else
Font5Colour = White
Font5ColourBk = Black
EndIf
If mouseblock > 0
mouseblock - 1
EndIf
If Covered = 1 And MouseButton (1) And mouseblock < 1
Musix = 0
musixtate + 1
mouseblock = 30
ElseIf Covered = 0 And MouseButton (1)
EndIf
If Covered = 2 And MouseButton (1) And mouseblock < 1
Effects = 0
effectsstate + 1
mouseblock = 30
ElseIf Covered = 0 And MouseButton (1)
EndIf
If Covered = 3 And MouseButton (1) And mouseblock < 1
mouseblock = 30
VideoSettings ()
ElseIf Covered = 0 And MouseButton (1)
EndIf
If Covered = 4 And MouseButton (1) And mouseblock < 1
mouseblock = 30
Controls ()
ElseIf Covered = 0 And MouseButton (1)
EndIf
If Covered = 5 And MouseButton (1) And mouseblock < 1
mouseblock = 30
Ending ()
ElseIf Covered = 0 And MouseButton (1)
EndIf
If musixtate > 1
musixtate = 0
EndIf
If effectsstate > 1
effectsstate = 0
EndIf
FlipBuffers ()
Until KeyboardPushed (1)
EndProcedure
Procedure NewGame ()
Repeat
ClearScreen (0)
ExamineKeyboard ()
StartDrawing (ScreenOutput ())
DrawText (20,20,Str (Score),255,0)
DrawText (400,20, Str (Score1),255,0)
StopDrawing ()
SoundVolume (0,Musix)
SoundVolume (1,Effects)
circlex + move
circley + move2
DisplayTransparentSprite (2,circlex,circley)
DisplayTransparentSprite (0,player1x,player1y)
DisplayTransparentSprite (1,player2x,player2y)
If circlex < 0
If timer < 1
PlaySound (1)
timer = 20
EndIf
circlex = screenx / 2
circley = screeny / 2
Score + 1
EndIf
If circlex > 640
If timer < 1
PlaySound (1)
timer = 20
EndIf
circlex = screenx / 2
circley = screeny / 2
Score2 + 1
EndIf
If circley + 10 > 478 Or circley < 0
move2 * -1
If timer < 1
PlaySound (0)
timer = 20
EndIf
EndIf
If SpritePixelCollision (1,player2x,player2y,2,circlex,circley) Or SpritePixelCollision (0,player1x,player1y,2,circlex,circley)
move * -1
If timer < 1
PlaySound (0)
timer = 20
EndIf
EndIf
If timer > 0
timer - 1
EndIf
If KeyboardPushed (#PB_Key_Up)
player2y - 2
EndIf
If KeyboardPushed (#PB_Key_Down)
player2y + 2
EndIf
If KeyboardPushed (#PB_Key_W)
player1y - 2
EndIf
If KeyboardPushed (#PB_Key_S)
player1y + 2
EndIf
If player2y < 0
player2y + 2
ElseIf player2y + 70 > 480
player2y - 2
EndIf
If player1y < 0
player1y + 2
ElseIf player1y + 70 > 480
player1y - 2
EndIf
FlipBuffers ()
Until KeyboardPushed (1)
EndProcedure
Procedure mainMenu ()
Repeat
ClearScreen (0)
ExamineKeyboard ()
ExamineMouse ()
StartDrawing (ScreenOutput ())
DrawingFont (FontID(0))
awidth = (screenx / 2) - (TextWidth ("Pong") / 2)
aheight = (screeny / 2) - (TextHeight ("Pong") / 2)
DrawText (awidth,aheight,"Pong",RGB(255,255,255),0)
DrawingFont (FontID(1))
twng = TextWidth ("New Game")
twp = TextWidth ("Play")
two = TextWidth ("Options")
twq = TextWidth ("Quit")
twng2 = TextHeight ("New Game")
twp2 = TextHeight ("Play")
two2 = TextHeight ("Options")
twq2 = TextHeight ("Quit")
bwidth = (screenx / 2) - (twng / 2)
cwidth = (screenx / 2) - (twp / 2)
dwidth = (screenx / 2) - (two / 2)
ewidth = (screenx / 2) - (twq / 2)
DrawText (bwidth,250,"New Game",Font1Colour,Font1ColourBk)
DrawText (cwidth,280, "Play",Font2Colour,Font2ColourBk)
DrawText (dwidth,310,"Options",Font3Colour,Font3ColourBk)
DrawText (ewidth,340, "Quit",Font4Colour,Font4ColourBk)
DrawText (20,30,Str (MouseX ()) + " " + Str (MouseY ()),255,0)
Box (MouseX (), MouseY (), 3,3,255)
StopDrawing ()
If MouseX () > bwidth And MouseX () < bwidth + twng And MouseY () > 250 And MouseY () < 250 + twng2 ;298,364,250,270
Font1Colour = Black
Font1ColourBk = White
Covered = 1
Else
Font1Colour = White
Font1ColourBk = Black
EndIf
If MouseX () > cwidth And MouseX () < cwidth + twp And MouseY () > 280 And MouseY () < 280 + twp2
Font2Colour = Black
Font2ColourBk = White
Covered = 2
Else
Font2Colour = White
Font2ColourBk = Black
EndIf
If MouseX () > dwidth And MouseX () < dwidth + two And MouseY () > 310 And MouseY () < 310 + two2
Font3Colour = Black
Font3ColourBk = White
Covered = 3
Else
Font3Colour = White
Font3ColourBk = Black
EndIf
If MouseX () > ewidth And MouseX () < ewidth + twq And MouseY () > 340 And MouseY () < 340 + twq2
Font4Colour = Black
Font4ColourBk = White
Covered = 4
Else
Font4Colour = White
Font4ColourBk = Black
EndIf
If Covered = 1 And MouseButton (1)
mouseblock = 30
NewGame ()
ElseIf Covered = 0 And MouseButton (1)
EndIf
If Covered = 2 And MouseButton (1)
mouseblock = 30
;Gosub Game
ElseIf Covered = 0 And MouseButton (1)
EndIf
If Covered = 3 And MouseButton (1)
mouseblock = 30
Options ()
ElseIf Covered = 0 And MouseButton (1)
EndIf
If Covered = 4 And MouseButton (1)
mouseblock = 30
Ending ()
ElseIf Covered = 0 And MouseButton (1)
EndIf
FlipBuffers ()
Until KeyboardPushed (1)
EndProcedure
OpenScreen (screenx,screeny,32,"kdfhlsk")
UsePNGImageDecoder ()
LoadSound (0,zieg + "Lazer.wav")
LoadSound (1,zieg + "Explosion.wav")
LoadSprite (0,zieg + "bat.png")
CopySprite (0,1)
LoadSprite (2,zieg + "ball.png")
LoadFont (0,"Arial",15)
LoadFont (1,"Arial",10)
MouseLocate (screenx / 2, screeny / 2)
mainMenu () ;loooooop
Not at all. In fact (don't make a habit of it), it's possible for a Procedure to call itself. I Often use a Procedure to call a succession of other procedures, so then I have one call in a loop rather than many - just keeps the code tidy.Question: Does it cause errors if I call a procedure inside a procedure?
I think gosubs are very very slightly faster than procedures in terms of instructions / CPU clock cycles (less overhead).... but the only time I ever saw a noticeable difference was back in the day when I was writing some graphics rendering programs... like when you are manually calculating hundreds of thousands of pixels per every single screen update... gosubs and macros gave me a slight speedup.IdeasVacuum wrote:Will be interesting to see if Procedures can replace Gosubs without a performance penalty.
If it opens the options screen and the mouse button is still pressed, it callsJ@ckWhiteIII wrote:Okay, there's another problem. Probably has something to do with variable "mouseblock", but I'm not sure. clicking on "Options" seems to lead to Procedure "Ending()".
...nah, I don't think those options are necessary