How can I make it different? So that the enemy can attack the player with the same mechanism?
Code: Select all
if(gf.spriteCollide(this.hitzone, enemies[i].div)) {
var enemyRoll = enemies[i].object.defend();
var playerRoll = Math.round(Math.random() * 6) + 5;
if(enemyRoll <= playerRoll) {
var dead = enemies[i].object.kill(playerRoll);
console.html("You hit the enemy "+playerRoll+"pt");
if (dead) {
console.html("You killed the enemy!");
enemies[i].div.fadeOut(2000, function() {
$(this).remove();
});
enemies.splice(i,1);
}
} else {
console.html("The enemy countered your attack");
}
interacted = true;
return;
}