Skip to content

Commit

Permalink
Add levels
Browse files Browse the repository at this point in the history
  • Loading branch information
hpneo committed Nov 28, 2015
1 parent 7cbca40 commit 709ece6
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 6 deletions.
25 changes: 21 additions & 4 deletions scripts/states/game.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,14 @@ function Game() {
this.bombRate = 500;
}

Game.CURRENT_LEVEL = 0;

Game.prototype = {
loadLevel: function(index) {
if (index > 3) {
Game.CURRENT_LEVEL = index = 1;
}

var levels = this.game.cache.getJSON('levels'),
levelsIndex = index - 1,
level = levels[levelsIndex];
Expand All @@ -23,7 +29,7 @@ Game.prototype = {
//Mundo
this.game.physics.startSystem(Phaser.Physics.ARCADE);

this.loadLevel(this.game.rnd.between(1, 3));
this.loadLevel(++Game.CURRENT_LEVEL);

this.ground = this.map.createLayer('Ground'),
this.rocks = this.map.createLayer('Rocks');
Expand All @@ -48,7 +54,6 @@ Game.prototype = {
this.explosionPool.setAll('body.allowGravity', true);
this.explosionRange = 1;


this.enemyPool = this.add.group();

//this.game.time.events.loop(5000, this.addEnemy, this);
Expand Down Expand Up @@ -77,6 +82,7 @@ Game.prototype = {
//Player
var pos = this.availableSpaces[this.availableSpaces.length - 1];
this.player = new Player(this.game, 14, 0, 'red', 0);
this.player.score = 0;
this.bombs = this.game.add.group();

this.scoreText = this.add.text(this.game.world.width - 30, 10, this.player.score.toString(), font);
Expand Down Expand Up @@ -111,7 +117,11 @@ Game.prototype = {
}

if (this.player.isMoving) {
this.enemyPool.callAll('easyStarMovement', null, this.player, this.level);
try {
this.enemyPool.callAll('easyStarMovement', null, this.player, this.level);
} catch (e) {

}
}
//this.enemyDropBomb();
},
Expand Down Expand Up @@ -156,6 +166,7 @@ Game.prototype = {
}

currentEnemy = new Enemy(this.game, finalPos.x, finalPos.y);
currentEnemy.alive = true;

this.enemyPool.add(currentEnemy);

Expand Down Expand Up @@ -185,9 +196,15 @@ Game.prototype = {
destroyEnemy: function(enemy, explosion) {
enemy.kill();
enemy.alive = false;
this.player.score += 1;
this.player.score = this.enemyPool.children.filter(function(e) { return e.alive === false; }).length;

this.scoreText.text = this.player.score.toString();

if (this.player.score === 3) {
this.backgroundMusic.stop();
this.player.score = 0;
this.game.state.start('Game');
}
},
getRocksColliding: function(x, y) {
var column = Math.floor(x / 32),
Expand Down
4 changes: 2 additions & 2 deletions scripts/states/gameover.js
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,8 @@ GameOver.prototype = {
strokeThickness: 4
};

this.title = this.add.text(this.game.world.width / 2, 50, 'Game Over :,C', fontTitle);
this.title.anchor.setTo(0.5);
// this.title = this.add.text(this.game.world.width / 2, 50, 'Game Over :,C', fontTitle);
// this.title.anchor.setTo(0.5);

this.buttonPlay = this.game.add.button(this.game.width/2,this.game.height-50,'play-menu',this.playGame,this);
this.buttonPlay.anchor.setTo(0.5,0.5);
Expand Down

0 comments on commit 709ece6

Please sign in to comment.