Run Bob Run - Levels

Use these instructions to add three levels to your game.



Add new Levels javascript files
Each new level will need it's own javascript file. Start by editing the index.html file and adding the following lines of code to load in our two new javascript files we will be creating.



            <script src="playlevel2.js"></script>
            <script src="playlevel3.js"></script>

        



Create a new javascript file for each level
Each level needs it's own javascript file.

Add a new file called "playlevel2.js" and copy the contents from "playlevel1.js" into "playlevel2.js".
Do the same for "playlevel3.js".




Update the state name for each Javascript File
Each javascript file needs to have a unique game state name.

Update the state names inside each "playlevel2.js" and "playlevel3.js" files. See example below:



        // play level 2 of our game
        var playlevel2State = {
      

        



Add new States to our Phaser Game Object
In the "game.js" file, replace the code to look like below. This code adds our two new states to the game object.



        // GAME - INITIALIZE 
        // -----------------------------------------------------------------

        // Startup the Phaser Game Engine
        var game = new Phaser.Game("98%", "95%", Phaser.CANVAS, 'gameBoard');

        // add game scenes ( game states ) to the phase game engine
        game.state.add('boot', bootState);
        game.state.add('load', loadState);
        game.state.add('menu', menuState);
        game.state.add('playlevel1', playlevel1State);
        game.state.add('playlevel2', playlevel2State);
        game.state.add('playlevel3', playlevel3State);
        game.state.add('gameover', gameoverState);
        game.state.add('winner', winnerState);

        // Start Game 
        game.state.start('boot');
      

        



Reroute level 1 to continue to level 2
In the "playlevel1.js" file, change the "gameOver" function to call the state "playlevel2".
Do the same for "playlevel2.js" but have it call "playlevel3".



    gameOver: function() { 

        game.state.start('playlevel2');

    }      

        



Run Game and Check for Errors
Press F12 to check console for any problems. Play It! Try to make it through all the levels.

Try designing your own levels, or adding some new levels.



code on plnkr