Example #1
0
void PongGame::update(){
	switch(currentState){
	case MENU_STATE:
		runMenuState();
		break;
	case COUNTDOWN_STATE:
		runCountdownState();
		break;
	case GAME_STATE:
		runGameState();
		break;
	case END_STATE:
		runEndState();
		break;
	default:
		runMenuState();
	}
}
Example #2
0
// Main entry point and game loop
int main()
{
    //Put printStr char height and width back to defaults (after splash changed them)
    charHeight = 0xf8;
    charWidth = 0x50;
    
    //Initialize settings that get passed around everywhere
    GameVars gameVars = {
        GSTitle,    //state
        0,          //frame
        0,          //frame multiplier
        MSStopped,   //Music state - no tune on start up credits
        GMusicTitle, //Current music track
        //Sounds array - index must match enum
            GSoundPaddleBounce, 5, 0, //sound name, duration, frame
            GSoundWallBounce, 4, 0,
        //ball
        {   false,          //invisible
            ballLeftMax,    //left
            ballTopMax,     //top
            1,              //moving right
            -1,             //moving down
            false           //speed up
        },
        //Player 1
        {
            0,      //p1 score
            0       //P1 xPos
        },
        //Player 2
        {
            0,      //p2 score
            0       //P2 xPos
        },
        true        //p1 to serve
    };

    //Setup joysticks - only need left & right on both
    //p1LR, P1UD, P2LR, P2UD
    joyEnableFlags(true, false, true, false);
    joyAnalogResolution(0x00); //v accurate
    
    //MAIN LOOP
    while (true)
    {
        //Music selection and preparation
        prepMusic(&gameVars);
        
        // wait for frame boundary (one frame = 30,000 cyles = 50 Hz)
        waitRecal();
        
        //Music execution
        runMusic(&gameVars);
        
        //Execute current state
        runGameState(&gameVars);

        //Game sound effects and music management
        runSound(&gameVars);
    }
}