Okay. So, i have a tile based game. It's set up to where i can move from map to map by different door tiles. However, my enemies are set up to restart the game when you touch them. I would like to move to another map when I touch the enemy. Here is the full code for the enemy actions.
Code:
function enemyBrain() {
//loop through all enemies currently on stage
for (var i = 0; i<game.currentEnemies; ++i) {
//name of new enemy
var name = "enemy"+i;
var ob = game[name];
//check if enemy will hit the wall
getMyCorners(ob.x+ob.speed*ob.xMove, ob.y+ob.speed*ob.yMove, ob);
if (ob.downleft and ob.upleft and ob.downright and ob.upright) {
//move enemy
moveChar(ob, ob.xMove, ob.yMove);
} else {
//reverse enemy direction
ob.xMove = -ob.xMove;
ob.yMove = -ob.yMove;
}
//check if we have collision with hero
var xdist = ob.x-char.x;
var ydist = ob.y-char.y;
if (Math.sqrt(xdist*xdist+ydist*ydist)<ob.width+char.width) {
//end the game
removeMovieClip(_root.tiles);
_root.gotoAndPlay(1);
}
}
}
So, basically, I have the if statement right because when it hits the enemy, it restarts the game. removeMovieClip takes the game off. the next line "_root.gotoAndPlay(1)" tells it to restart the game to frame 1 which is the click here to start frame.