Skip to content

Commit

Permalink
los enemigos ya siguen a player
Browse files Browse the repository at this point in the history
  • Loading branch information
Gary Johal Figuerola Mora authored and Gary Johal Figuerola Mora committed Nov 19, 2015
1 parent 204d561 commit 7219970
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 90 deletions.
89 changes: 7 additions & 82 deletions scripts/objects/enemy.js
Original file line number Diff line number Diff line change
Expand Up @@ -33,97 +33,22 @@ Enemy.prototype.easyStarMovement = function(player,level){
var playerY = Math.floor(player.y / 32);
var thisX = Math.floor(this.x / 32);
var thisY = Math.floor(this.y / 32);
// console.log(playerX + " " + playerY);
// console.log(thisX + " " + thisY);
// console.log(this.columna + " " + this.fila);
easystar.setGrid(level.data);
easystar.setAcceptableTiles([0]);
easystar.findPath(thisX , thisY, playerX, playerY, function(path){
console.log(path);
var i = 0;
game.time.events.loop(Phaser.Timer.SECOND, function(){
this.path = path;
var i = 0;
this.game.time.events.loop(Phaser.Timer.SECOND, function(){
if(i < path.length){
this.x = (path[i].y) * 32;
this.y = (path[i].x) * 32;

console.log(this.columna + " " + this.fila);
this.x = (path[i].x) * 32;
this.y = (path[i].y) * 32;
i++;
}
});
});

},this);
}.bind(this));
easystar.calculate();
};

// Enemy.prototype.handleArificialMovement = function(rocks,rocksColliding,moveChooserVal) {
//
// var moving = true;
// this.game.physics.arcade.collide(this, this.rocks);
// if(!moveChooserVal || moveChooserVal==null)
// moveChooser = getRandomInt(1, 5) ;
// else
// moveChooser=moveChooserVal;
// this.body.velocity.x = 0;
// this.body.velocity.y = 0;
//
// //TODO:USE rocksColliding to create a fancy movement "IA"
// if (moveChooser == 1)
// {
// if(rocksColliding.left!=false && this.x-this.speed>0)
// { if(this.alive )
// {
// this.body.velocity.x = -this.speed;
// this.facing = "left";
// moving = true;
// }
// }
// }
// else if (moveChooser == 2)
// {
// if (rocksColliding.right!=false && this.x+this.width+this.speed<this.game.world.bounds.right)
// {
// if(this.alive)
// {
// this.body.velocity.x = this.speed;
// this.facing = "right";
// moving = true;
// }
// }
// }
// else if (moveChooser == 3)
// {
// if(rocksColliding.up != false && this.y+this.height+this.speed<this.game.world.bounds.top )
// {
// if (this.alive)
// {
// this.body.velocity.y = -this.speed;
// this.facing = "up";
// moving = true;
// }
// }
//
// }
// else if (moveChooser == 4 )
// {
// if(rocksColliding.down != false && this.y-this.speed>0)
// {
// if (this.alive)
// {
// this.body.velocity.y = this.speed;
// this.facing = "down";
// moving = true;
// }
// }
//
// }
//
// if(moving) {
// this.animations.play(this.facing);
// }
//
// };


Enemy.prototype.canDropBombs = function(bombsPool) {
return (bombsPool.total < this.maxBombs);
};
10 changes: 2 additions & 8 deletions scripts/states/game.js
Original file line number Diff line number Diff line change
Expand Up @@ -89,14 +89,9 @@ Game.prototype = {
this.addEnemy(2);
this.addEnemy(3);

// this.game.time.events.loop(1000, function() {
//
// }, this);
//this.handleEnemyMovement();
// this.game.time.events.loop(1000, this.handleEnemyMovement, this);
},
update: function() {

// this.enemyPool.children[0].easyStarMovement(this.player,this.level);
this.physics.arcade.collide(this.player, this.rocks);
this.physics.arcade.collide(this.enemyPool, this.rocks);
this.physics.arcade.collide(this.player, this.enemyPool);
Expand Down Expand Up @@ -152,7 +147,6 @@ Game.prototype = {
var currentEnemy = this.enemyPool.getFirstExists(false),
positionIndex = this.game.rnd.between(0, this.availableSpaces.length - 1),
position = this.availableSpaces[positionIndex];

var finalPos;
if(enemyID ==1)
{
Expand All @@ -171,7 +165,7 @@ Game.prototype = {

//if (!currentEnemy) {
currentEnemy = new Enemy(this.game, finalPos.x, finalPos.y);
currentEnemy.easyStarMovement(this.player,this.level);

this.enemyPool.add(currentEnemy);
//}
// else {
Expand Down

0 comments on commit 7219970

Please sign in to comment.