JavaScript/jQuery fight system
Posted: Wed Nov 05, 2014 9:49 am
If the player's strike is bigger than the enemy's defense, the attack is successful and the enemy will suffer a loss of life equal to the player's strike. If the enemy's defense is stronger, the attack fails and the enemy remains safe.
How can I make it different? So that the enemy can attack the player with the same mechanism?
Sorry about any misspelling, I'm currently on my Phone looking at my laptop screen. (No internet atm)
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;
}