Skip to content

Commit

Permalink
json level changed
Browse files Browse the repository at this point in the history
  • Loading branch information
FRANCIS LOPEZ authored and FRANCIS LOPEZ committed Oct 24, 2015
1 parent c7daf26 commit b6a7543
Show file tree
Hide file tree
Showing 3 changed files with 44 additions and 48 deletions.
11 changes: 7 additions & 4 deletions assets/data/levels.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,16 +2,19 @@
{
"title": "Cave",
"tileset": "tilemap_cave",
"rockId": 1214
"rockId": 1214,
"data":[0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1214, 0, 1214, 0, 1214, 0, 1214, 0, 1214, 0, 1214, 0, 1214, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1214, 0, 1214, 0, 1214, 0, 1214, 0, 1214, 0, 1214, 0, 1214, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1214, 0, 1214, 0, 1214, 0, 1214, 0, 1214, 0, 1214, 0, 1214, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1214, 0, 1214, 0, 1214, 0, 1214, 0, 1214, 0, 1214, 0, 1214, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0]
},
{
"title": "Ice Cave",
"tileset": "tilemap_cave",
"rockId": 974
"rockId": 974,
"data":[0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 974, 974, 974, 974, 974, 974, 0, 974, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 974, 974, 974, 0, 974, 974, 974, 974, 0, 0, 0, 974, 974, 974, 0, 974, 0, 974, 0, 0, 0, 0, 974, 0, 0, 0, 0, 0, 974, 0, 974, 0, 974, 0, 0, 0, 0, 0, 0, 0, 974, 974, 0, 974, 0, 0, 0, 0, 0, 974, 0, 0, 974, 0, 0, 0, 0, 0, 974, 0, 974, 974, 974, 974, 974, 974, 0, 0, 0, 0, 0, 974, 974, 974, 0, 974, 0, 0, 974, 0, 0, 0, 974, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 974, 0, 0, 0, 974, 0]
},
{
"title": "Grass",
"tileset": "tilemap_grass",
"rockId": 23
"rockId": 23,
"data":[0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 23, 0, 23, 0, 23, 0, 23, 0, 23, 0, 23, 0, 0, 0, 0, 0, 0, 23, 0, 23, 0, 0, 0, 0, 0, 0, 0, 0, 0, 23, 23, 0, 23, 0, 0, 0, 23, 0, 0, 23, 23, 23, 0, 0, 0, 0, 0, 23, 0, 23, 0, 0, 0, 0, 0, 0, 23, 0, 0, 23, 23, 0, 23, 0, 23, 23, 23, 23, 23, 23, 0, 23, 0, 0, 0, 23, 0, 0, 0, 0, 23, 0, 23, 0, 23, 0, 23, 0, 0, 0, 23, 0, 23, 23, 23, 23, 0, 0, 0, 23, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0]
}
]
]
50 changes: 13 additions & 37 deletions scripts/objects/enemy.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
var DEFAULT_ENEMY_SPEED = 160 ;
var DEFAULT_ENEMY_SPEED = 100 ;

function Enemy(game, x, y) {
Player.call(this, game, x, y, 'enemy', 0);
Expand All @@ -22,7 +22,7 @@ function getRandomInt(min, max) {
return Math.floor(Math.random() * (max - min + 1)) + min;
};
Enemy.prototype.handleArificialMovement = function(rocks,rocksColliding,moveChooserVal) {

var moving = true;
this.game.physics.arcade.collide(this, this.rocks);
if(!moveChooserVal || moveChooserVal==null)
Expand All @@ -33,7 +33,6 @@ Enemy.prototype.handleArificialMovement = function(rocks,rocksColliding,moveChoo
this.body.velocity.y = 0;

//TODO:USE rocksColliding to create a fancy movement "IA"
console.log(moveChooser);
if (moveChooser == 1)
{
if(rocksColliding.left!=false)
Expand All @@ -44,28 +43,18 @@ Enemy.prototype.handleArificialMovement = function(rocks,rocksColliding,moveChoo
moving = true;
}
}
else
{
moveChooser= getRandomInt(2, 5) ;
this.handleArificialMovement(rocks,rocksColliding,moveChooser);
}
}
else if (moveChooser == 2)
{
if (rocksColliding.right!=false)
{
if(this.alive)
if(this.alive)
{
this.body.velocity.x = this.speed;
this.facing = "right";
moving = true;
}
}
else
{
moveChooser= getRandomInt(1, 5) ;
this.handleArificialMovement(rocks,rocksColliding,moveChooser);
}
}
else if (moveChooser == 3)
{
Expand All @@ -78,12 +67,7 @@ Enemy.prototype.handleArificialMovement = function(rocks,rocksColliding,moveChoo
moving = true;
}
}
else
{
moveChooser= getRandomInt(1, 5) ;
this.handleArificialMovement(rocks,rocksColliding,moveChooser);
}


}
else if (moveChooser == 4 )
{
Expand All @@ -96,24 +80,16 @@ Enemy.prototype.handleArificialMovement = function(rocks,rocksColliding,moveChoo
moving = true;
}
}
else
{
moveChooser= getRandomInt(1, 3) ;
this.handleArificialMovement(rocks,rocksColliding,moveChooser);
}
}
else if (moveChooser == 5)
{
if(this.alive)
{
moving = false;
this.freeze();
moveChooser= getRandomInt(1, 5) ;
this.handleArificialMovement(rocks,rocksColliding,moveChooser);
}

}

if(moving) {
this.animations.play(this.facing);
}

};

};


Enemy.prototype.canDropBombs = function(bombsPool) {
return (bombsPool.total < this.maxBombs);
};
31 changes: 24 additions & 7 deletions scripts/states/game.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,8 @@ Game.prototype = {
this.map.addTilesetImage(level.title, level.tileset);
this.map.setCollision(level.rockId, true, 'Rocks');

console.log(level.data);

//Musica
this.backgroundMusic = this.add.audio('level_' + index, 0.6, true);
this.backgroundMusic.play();
Expand Down Expand Up @@ -84,11 +86,11 @@ Game.prototype = {
//Ajustes
this.ground.resizeWorld();
this.rocks.resizeWorld();

this.addEnemy(1);
this.addEnemy(2);
this.addEnemy(3);
this.game.time.events.loop(2000, this.handleEnemyMovement, this);
this.game.time.events.loop(1000, this.handleEnemyMovement, this);
},
update: function() {
this.physics.arcade.collide(this.player, this.rocks);
Expand All @@ -105,6 +107,17 @@ Game.prototype = {
if (this.player.bombButtonJustPressed && this.player.canDropBombs(this.bombsPool) && this.time.now > this.nextBomb) {
this.createBomb(this.player.x + this.player.width / 2, this.player.y + this.player.height / 2, this.keyBomb, 0);
}

this.enemyDropBomb();

},
enemyDropBomb: function(){
var enemyRandom = getRandomInt(0,this.enemyPool.children.length-1);
if (this.enemyPool.children[enemyRandom].canDropBombs(this.bombsPool)
&& this.time.now > this.nextBomb
&& this.enemyPool.children[enemyRandom].alive) {
this.createBomb(this.enemyPool.children[enemyRandom].x + this.enemyPool.children[enemyRandom].width / 2, this.enemyPool.children[enemyRandom].y + this.enemyPool.children[enemyRandom].height / 2, this.keyBomb, 0);
}
},
handleEnemyMovement: function(){
for (var i = 0, len = this.enemyPool.children.length; i < len; i++) {
Expand Down Expand Up @@ -165,7 +178,7 @@ Game.prototype = {
},
destroyEnemy: function(enemy, explosion) {
enemy.kill();

enemy.alive = false;
this.player.score += 1;

this.scoreText.text = this.player.score.toString();
Expand All @@ -184,11 +197,11 @@ Game.prototype = {
if (this.rocks.layer.data[row - 1] !== undefined && this.rocks.layer.data[row - 1]) {
rocksColliding.up = (this.rocks.layer.data[row - 1][column].index === this.level.rockId);
}
}
}
else
{
rocksColliding.up = true;
}
}
if(column>=0){
if (this.rocks.layer.data[row + 1] !== undefined && this.rocks.layer.data[row + 1]) {
rocksColliding.down = (this.rocks.layer.data[row + 1][column].index === this.level.rockId);
Expand All @@ -202,7 +215,7 @@ Game.prototype = {
if (this.rocks.layer.data[row][column - 1] !== undefined && this.rocks.layer.data[row][column - 1]) {
rocksColliding.left = (this.rocks.layer.data[row][column - 1].index === this.level.rockId);
}
}
}
else
{
rocksColliding.left = true;
Expand All @@ -224,7 +237,7 @@ Game.prototype = {
},
clearBombs: function() {
for(var bombId in this.bombsPool) {//TODO: add detonate timer ID
//clearTimeout(this.bombsPool[bombId].detonateTimerID);
//clearTimeout(this.bombsPool[bombId].detonateTimerID);
}
this.bombsPool = {};
},
Expand All @@ -240,5 +253,9 @@ Game.prototype = {
}
},
showGameStatusAndReset: function() {
},
getRandomInt:function(min, max) {
return Math.floor(Math.random() * (max - min + 1)) + min;
}

};

0 comments on commit b6a7543

Please sign in to comment.