Welcome Screens

Almost every game should have a Welcome screen that provides the player with information on how to start the game, how to control the game, and how to end it. Earlier in the book, we designed a Welcome screen that we will now incorporate into our program. The code we are going to use to load our Welcome screen will be a function (I’ll cover functions in greater detail in the next chapter) that we’ll include at the very beginning of our program. Start by opening demo13-11.bb, which is a program with several spheres pivoting around each other. Save the file with a new name in another location on your computer, and make sure the files sunskin.jpg, and orbit.jpg are saved in the same location. Make sure that the image welcome.bmp is also located in the same location.

The key to the Welcome screen code is to put the function right at the beginning of our program, before all other code. After the function is executed, the main program will start at the point where the function ended. Enter the following code right at the beginning of the program:

; demo13-11.bb – welcome screen
;__________________
welcome()
Function welcome()
Graphics 640,480
screen=LoadImage ("welcome.bmp")
DrawImage screen,0,0
While Not KeyDown(1)
If KeyDown(31) Then Return
Wend
End Function

Graphics3D 640,480
SetBuffer BackBuffer()

Let’s take a look at the code line by line to see what we’ve just done:

welcome()—This launches the function called welcome().

Function welcome()—This is the start of the definition of the function we have called welcome.

Graphics 640,480—This line sets the screen resolution.

screen=LoadImage ("welcome.bmp")—This will load the image called “welcome.bmp” into the program but will not display it.

DrawImage screen,0,0—This will display the image we have loaded, starting at the 0,0 point on the screen.

While Not KeyDown(1)—This starts a loop within the function.

If KeyDown(31) Then Return—If the letter S is pressed, the function will end, and we will be returned to the main program.

Wend—This ends the loop.

End Function—This ends the function.

Run the program now, and you should see the Welcome screen appear. When you press the letter S, the Welcome screen should disappear and the game should begin.

..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset
3.144.37.38