Jump to content

multilevel architecture


pimous
 Share

Recommended Posts

It's all about states, you can create several levels as states, then you can do it by score or after killing a big enemy ( boss fight ). So for example, in you main game state ( single level game ), you can check if score is more that 500, 000 for example, so you can create a function that is checking score and after score reached a certain amount 500,000 in our example, you can call another state. For example here is in my main menu state, If a user clicks on screen or touches screen then we load our Stage1 state, which will be level 1:

 

update: function() {   if(this.game.input.activePointer.justPressed()) {   this.game.state.start('Stage1');   }  

}

 

 

Afterwards in our level 1 state we can create another function:

 

checkScore: function(score) {

    if(score > 500000) {

        this.game.state.start('Stage2');

     }

}

 

and so on, let me know if this helps.

 

Check out this great tutorial on game states:

 

http://www.emanueleferonato.com/2014/08/28/phaser-tutorial-understanding-phaser-states/

Link to comment
Share on other sites

You can keep all the level data in a JSON object, and pass the level to the GameState as a parameter. You can basically use the same State for multiple levels in this way:

var levelX = {  playerStartPosition: {x: 100, y: 20},  enemies: [    {x: 10, y: 10},    {x: 10, y: 20},    {x: 10, y: 30},    {x: 10, y: 4}],  speed: 3,  goalPosition: {x: 199, y:200}}

Then when you launch your state (let's call it GameState):

//The first “true” is because we want to refresh the game world, the second is set to “false” as we don’t want to erase the game’s cache//you pass it then the level data as a parameterthis.state.start('GameState', true, false, levelX)

In a State, you read the parameter that was passed by using the init() method:

init: function(levelData) {  this.levelData = levelData;}..create: function() {  //in here you place the level player, enemies and goal etc according to this.levelData..}
Link to comment
Share on other sites

 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...