1 decade ago by ruimalta
Hi, I am trying to make the enemies in the level to chase the player, if he's near him, and I can only make one of each class to follow it, in the main.js I have:
just after the
in the init function I have:
and in the update funtion I have:
the whereami funtion is:
So, in resume my problem is that I can make only one of the "spikes" to follow me. What can I do?
just after the
MyGame = ig.Game.extend({
I have:sentinelNear: 0,
spikeNear: 0,
st: null,
in the init function I have:
var sentinelProx = 0;
var spikeProx = 0;
and in the update funtion I have:
var spike = this.getEntitiesByType( EntitySpike ) [0];
var spikeLength = this.getEntitiesByType( EntitySpike).length;
spikeProx = Math.abs( hero.pos.x - spike.pos.x );
for( var i = 0; i < spikeLength; i++ ) {
if (spikeProx < 50){
st = spike[i];
nearSpike = this.whereami(hero.pos.x, spike.pos.x);
st.flip = nearSpike;
if(nearSpike==1)
this.flip = true;//if hero is on the left side of the enemy
if(nearSpike==0)
this.flip = false;//if hero is on the right side of the enemy
}
}
the whereami funtion is:
whereami: function(xH, xE){
if( xH < xE ) //if player is on the left side of the enemy
return(1);
else (xH > xE) //if player is on the right side of the enemy
return(0);
},
So, in resume my problem is that I can make only one of the "spikes" to follow me. What can I do?