Saturday, 28 April 2012

Game Start

After a short break, it's time to get back to the game portion of project.


Firstly, the test code in the case STATE_INTRO block needs to be removed.  This is replaced with the last two commented out lines from the previous block.
// Workaround to ensure frame rate ok before menu is called
if timer() > 3.0 then setGameState( STATE_MENU )
The comment slashes (//) have been removed from the second line and the value increased from, 2.0 to 3.0 to allow for loading time.

This advances the game state from STATE_INTRO to STATE_MENU after the game has been running three seconds.

Now the beginning the select statement should look like this.
   select GameState()
      case STATE_SETUP
         // Setup Code
         testNum = LoadObjectData( "standard" )
         setGameState( STATE_INTRO )
      endcase
      case STATE_INTRO
         // Intro Code
         // Workaround to ensure frame rate ok before menu is called
         if timer() > 3.0 then setGameState( STATE_MENU )
      endcase
      case STATE_DEMO
         // Demo Code
      endcase
      case STATE_MENU
         // Menu Code
We transition out of the menu, what is needed next is a transition into the game.

At the moment, the panel text Objects - used to open and close the panel - is visible as soon as the project starts, it should really only become visible once a game starts.

This is done by making it invisible, just after it's depth is set in the Initialise() function.
setTextVisible( panelText() , 0 )
This uses the setTextVisible() command with a 0 parameter.  Now the text will not be visible during the setup, initialise and menu states.

Now as we did with the menu, we can check if this is visible to determine when the game block is being called for the first time.

Inside the case STATE_RUNNING, block, the text is checked to see if it is visible.
if getTextVisible( PanelText() ) = 0
   // Game starting 
   setTextVisible( panelText() , 1 )
   setTextColor( panelText() , 127 , 255 , 127 , 0 )
   PositionPanelIcons()
   //  Activate Transition
   StartTransition( TRANS_FADEIN , MENU_FADE )
If the text is not visible, it is made visible and it's colour set, including an alpha value of zero to make it fully transparent.

The PositionPanelIcons() function is used to make sure the panel is in the right position, then - as with the menu - a transition is started.  This uses the parameters from the menu transition at the moment.

The next block of code is very similar to that used in the menu.
elseif (Transition() = TRANS_FADEIN) or (Transition() = TRANS_FADEOUT) 
   thisAlpha = 255.0 * TransitionCount()
   if Transition() = TRANS_FADEOUT then thisAlpha = 255 - thisAlpha
   setTextColorAlpha( panelText() , thisAlpha )
   if TransitionCount() = 1.0
      if Transition() = TRANS_FADEOUT
         // Game Exiting    
      
      else
         // Game Starting
      
      endif
      StopTransition()     
   endif
endif
Here only the alpha of the panel text is changed, though the method is identical.

An empty if/else/endif structure has been used in the middle as a place to put code for the end of the fade transition, when added.

The existing call to checkGamePointer() now follows this code.

With this, the word Objects at the top of the panel should fade in when the game starts.

No comments:

Post a Comment