Welcome Screen

In almost every game, you’ll find a Welcome screen that gives the player instructions on the controls needed to play the game. Our game will be no different. We’ll use the Welcome screen that we created in Chapter 8, “Getting Graphic.” If you happen to have skipped that chapter, now would be a good time to go over the process of creating your Welcome screen since you’ll need it for this section of code. Start off by creating a new program in Blitz3D and saving it with any name to the folder where you stored all of the files necessary for this game. The first thing that we are going to do is create a function that will initiate the Welcome screen. While creating our program, we’ll use lots of comments so that keeping track of where things are will be a breeze. Let’s start by adding the following code to create our function:

;Shooting Gallery
;________________
;Key constants
Const ENTER_KEY = 28
Const R_KEY = 19
Const V_KEY = 47
Const P_KEY = 25
Const LEFT_KEY = 203
Const RIGHT_KEY = 205
Const UP_KEY = 200
Const DOWN_KEY = 208
Const SPACE_BAR = 57
Const ESC_KEY = 1
;This line launches the welcome function
      welcome()
;Creating the welcome function
Function welcome()
      Graphics 1024,768
      screen=LoadImage ("welcome.bmp")
      DrawImage screen,0,0
      While Not KeyDown(ESC_KEY)
      If KeyDown(ENTER_KEY) Then Return
      Wend
      End Function

Note: Tabs

Notice how there are different tab indentations for different lines. Since our program is going to contain many lines of code, indenting groups of code will make it easier to identify.


Most of this function should already make sense to you. If it doesn’t, refer back to Chapter 3 to review functions. That being said, the process of loading an image was only briefly covered, so let’s look at the following two lines of that code in particular:

screen=LoadImage ("welcome.bmp")
DrawImage screen,0,0

These two lines of code start by creating an identifier called screen, and then the LoadImage command loads the image called welcome.bmp into the program. The code DrawImage screen will draw the image starting from the top-left corner of the screen (position 0,0). Go ahead and run the program now, and, with any luck, you should see the Welcome screen appear. When you press the Enter or Return key, the program should end. Notice that the display was set at 1024 768, which means the game should take up the entire screen on most monitors. If you run the program now, you should see the Welcome screen, as in Figure 14.9.

Figure 14.9. The Welcome screen is generated in the function run at the beginning of the program.


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

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