Deino Posted March 10, 2015 Share Posted March 10, 2015 Here is a game I wrote, I want to advance the level as soon as all the coins are collected. How can I do that? I can create another state but I don't know how to proceed from there var game = new Phaser.Game(1000,600, Phaser.AUTO, 'gameDiv');var mainState = { preload: function() { game.stage.backgroundColor = "#71c5cf"; game.load.image('ball','assets/fireball.png'); game.load.image('wv','assets/wallVertical.png'); game.load.image('wh','assets/wallHorizontal.png'); game.load.image('coin','assets/coin.png'); }, create: function() { game.physics.startSystem(Phaser.Physics.ARCADE); this.ball = this.game.add.sprite(100,250,'ball'); this.createworld(); game.physics.arcade.enable(this.ball); this.ball.body.gravity.y = 1000; var spacekey = this.game.input.keyboard.addKey(Phaser.Keyboard.SPACEBAR); spacekey.onDown.add(this.jump,this); var lkey = this.game.input.keyboard.addKey(Phaser.Keyboard.LEFT); lkey.onDown.add(this.lmove,this); var rkey = this.game.input.keyboard.addKey(Phaser.Keyboard.RIGHT); rkey.onDown.add(this.rmove,this); this.score = 0; this.labelScore = this.game.add.text(30, 90, "", { font: "30px Arial", fill: "#ffffff" }); this.labelScore.text = this.score; }, update: function() { game.physics.arcade.collide(this.ball,this.walls); game.physics.arcade.collide(this.ball,this.coins,this.scoreincrease,null,this); if (this.ball.inWorld == false) { this.restartGame(); } }, restartGame: function() { game.state.start('main'); }, jump: function() { this.ball.body.velocity.y = -350;}, lmove: function() { this.ball.body.velocity.x = -200; }, rmove: function() { this.ball.body.velocity.x = 200; }, createworld: function() { this.walls = this.game.add.group() this.walls.enableBody = true; game.add.sprite(150,150,'wv',0,this.walls); game.add.sprite(170,180,'wh',0,this.walls); game.add.sprite(170,480,'wh',0,this.walls); game.add.sprite(450,480,'wh',0,this.walls); game.add.sprite(650,150,'wv',0,this.walls); game.add.sprite(450,180,'wh',0,this.walls); this.walls.setAll('body.immovable',true); this.coins = this.game.add.group(); this.coins.enableBody = true; game.add.sprite(10,10,'coin',0,this.coins); game.add.sprite(10,60,'coin',0,this.coins); game.add.sprite(30,10,'coin',0,this.coins); game.add.sprite(30,60,'coin',0,this.coins); }, scoreincrease : function(ball,coins) { this.score += 20; this.labelScore.text = this.score; coins.kill(); } };game.state.add('main',mainState);game.state.start('main'); Link to comment Share on other sites More sharing options...
ZoomBox Posted March 11, 2015 Share Posted March 11, 2015 Levels are basically never states.It's just something you load differently at the beginning of you 'Game' state. Check this post I wrote recently and the others too: http://www.html5gamedevs.com/topic/12695-request-a-bit-more-advanced-beginner-tutorial/?p=73464 Link to comment Share on other sites More sharing options...
beuleal Posted March 11, 2015 Share Posted March 11, 2015 Its simple. You need to create differents states and enjoy! Link to comment Share on other sites More sharing options...
Recommended Posts