To n8r2k

Blitz3D Forums/Blitz3D Beginners Area/To n8r2k

The forum is locked. These are the original blitzbasic.com forums, kept so they can still be read. No new topics, replies or edits can be made here. To join in, head over to the Blitz3D+ forums.

here's an example of the way i structure this sort of thing - might be useful for you :) (runs standalone)

;=====================================================================================================
Const TITLE_EXPIRED = 0				; User did not press start in time, go back to splash screen.
Const END_SESSION% = 1				; The user has opted to quit the application.
Const DISPLAY_CREDITS% = 2			; User chose to view the credits screen.
Const DISPLAY_OPTIONS% = 3			; User chose to view the options screen.
Const LOAD_GAME% = 4				; User chose to load a saved game.
Const START_GAME% = 5				; User chose to begin a new game.

Const CONCLUSION_SUCCESS = 0		; User successfully completed the level.
Const CONCLUSION_FAIL_RETRY = 1		; User failed the level, but wants to retry.
Const CONCLUSION_FAIL_EXIT = 2		; User failed the level, and wants to quit.
Const USER_QUIT = 3					; User manually quit the level before conclusion.

;=====================================================================================================

Graphics 640,480
SetBuffer( FrontBuffer() )
RunMenuSystem()

;=====================================================================================================

Function RunMenuSystem()
	Repeat
		DisplaySplashScreen()
		DisplayTitleScreen()
		Repeat
			Select DisplayMainMenu()
				Case TITLE_EXPIRED		: Exit
				Case END_SESSION		: Return END_SESSION
				Case DISPLAY_CREDITS	: DisplayCredits()
				Case DISPLAY_OPTIONS	: DisplayOptions()
				Case LOAD_GAME			: RunGameSession( RequestSaveGame() ): Exit
				Case START_GAME			: RunGameSession( 1 ): Exit
			End Select
		Forever
	Forever
End Function

Function DisplaySplashScreen%()
	Local SplashTime = Ticker_New( 3000 )
	Repeat: Flip: Cls
		Text( 320, 240, "THIS IS THE SPLASH SCREEN", True, True )
		Text( 320, 260, "COMPANY LOGO HERE?", True, True )
	Until Ticker_HasTicked( SplashTime )
End Function

Function DisplayTitleScreen%()
	Repeat: Flip: Cls
		Text( 320, 240, "THIS IS THE MAIN TITLE SCREEN", True, True )
		Text( 320, 260, "PRESS ENTER TO BEGIN", True, True )
	Until KeyHit( 28 )
End Function

Function DisplayMainMenu%()
	Local ExpireTime = Ticker_New( 30000 )
	Repeat: Flip: Cls
		Text( 320, 200, "THIS IS THE MAIN MENU", True, True )
		Text( 320, 220, "1 = EXIT GAME", True, True )
		Text( 320, 240, "2 = DISPLAY CREDITS", True, True )
		Text( 320, 260, "3 = DISPLAY OPTIONS", True, True )
		Text( 320, 280, "4 = LOAD GAME", True, True )
		Text( 320, 300, "5 = START GAME", True, True )

		If KeyHit( 2 ) Then Return END_SESSION
		If KeyHit( 3 ) Then Return DISPLAY_CREDITS
		If KeyHit( 4 ) Then Return DISPLAY_OPTIONS
		If KeyHit( 5 ) Then Return LOAD_GAME
		If KeyHit( 6 ) Then Return START_GAME
	Until Ticker_HasTicked( ExpireTime )
	Return TITLE_EXPIRED
End Function

Function DisplayCredits%()
	Repeat: Flip: Cls
		Text( 320, 240, "THIS IS THE CREDITS SCREEN", True, True )
		Text( 320, 260, "PRESS ENTER TO EXIT", True, True )
	Until KeyHit( 28 )
End Function

Function DisplayOptions%()
	Repeat: Flip: Cls
		Text( 320, 240, "THIS IS THE OPTIONS SCREEN", True, True )
		Text( 320, 260, "PRESS ENTER TO EXIT", True, True )
	Until KeyHit( 28 )
End Function

Function RequestSaveGame%()
	Repeat: Flip: Cls
		Text( 320, 240, "THIS IS THE SAVE GAME LOADER SCREEN", True, True )
		Text( 320, 260, "LETS SAY WE HAVE LOADED LEVEL 8 (it could be anything)", True, True )
		Text( 320, 280, "PRESS ENTER TO EXIT THIS SCREEN", True, True )
	Until KeyHit( 28 )
	Return 8
End Function

Function RunGameSession( DesiredStage )
   Repeat
      Select PlayLevel( DesiredStage )
         Case CONCLUSION_SUCCESS	: DesiredStage = DesiredStage + 1
         Case CONCLUSION_FAIL_RETRY	: ;Don't need to do anything
         Case CONCLUSION_FAIL_EXIT	: Return
         Case USER_QUIT				: Return
      End Select
   Forever
End Function

Function PlayLevel( Level )
	LoadLevel( Level )
	Repeat: Flip: Cls
		Text( 320, 220, "THIS IS THE MAIN GAME SCREEN", True, True )
		Text( 320, 240, "CURRENT LEVEL IS " + Level, True, True )
		Text( 320, 260, "1 = CONCLUSION SUCCESS", True, True )
		Text( 320, 280, "2 = CONCLUSION FAILURE RETRY", True, True )
		Text( 320, 300, "3 = CONCLUSION FAILURE EXIT", True, True )
		Text( 320, 320, "4 = QUIT GAME", True, True )

		If KeyHit( 2 ) Then Return CONCLUSION_SUCCESS
		If KeyHit( 3 ) Then Return CONCLUSION_FAIL_RETRY
		If KeyHit( 4 ) Then Return CONCLUSION_FAIL_EXIT
		If KeyHit( 5 ) Then Return USER_QUIT
	Forever
End Function

Function LoadLevel%( DesiredLevel% )
	Local SplashTime = Ticker_New( 2000 )
	Repeat: Flip: Cls
		Text( 320, 240, "THIS IS THE LOADING SCREEN", True, True )
		Text( 320, 260, "NOW LOADING LEVEL " + DesiredLevel, True, True )
	Until Ticker_HasTicked( SplashTime )
End Function

;!====================================================================================================
; Ticker type.
;!====================================================================================================
Type Ticker
	Field LastTick%
	Field Frequency%
End Type

Function Ticker_New%( NewFrequency%=1000 )
	Local this.Ticker	= New Ticker

	this\LastTick%		= MilliSecs()
	this\Frequency%		= NewFrequency%

	Return Handle( this )
End Function

Function Ticker_Dispose%( HND% )
	Local this.Ticker = Object.Ticker( HND% )

	Delete this
End Function

Function Ticker_Frequency%( HND%, NewFrequency%=-1 )
	Local this.Ticker = Object.Ticker( HND% )

	If ( NewFrequeny% = -1 )
		Return this\Frequency%
	Else
		If NewFrequency% > 0
			this\Frequency% = NewFrequency%
		EndIf
	EndIf
End Function

Function Ticker_HasTicked%( HND% )
	Local this.Ticker = Object.Ticker( HND% )

	If ( MilliSecs() > ( this\LastTick% +this\Frequency% ) )
		this\LastTick% = MilliSecs()
		Return True
	EndIf

	Return False
End Function