Page 1 of 1

JavaScript/jQuery fight system

Posted: Wed Nov 05, 2014 9:49 am
by Miroidan
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?

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;
}
Sorry about any misspelling, I'm currently on my Phone looking at my laptop screen. (No internet atm)

Re: JavaScript/jQuery fight system

Posted: Wed Nov 05, 2014 4:23 pm
by Miroidan
You can test it live here http://mirorpg.atspace.cc/ not much right now. You attack/talk with the space button and walk around with arrow keys.

Is there any way to obfuscate the code? JScrambler is not an option.

Re: JavaScript/jQuery fight system

Posted: Fri Nov 07, 2014 11:01 am
by MikuzA
Ok,

I took a look at your game and quite impressive!
Back to your question,

If you want to make the enemy attack back during your attack, you could simply just add it to the same function.
I don't have that much time to go through your whole engine but I would suggest the following:

-Decide on do you want the enemies to approach you with hostile intention when they are 'X'-distance from the char.
--If so, you can build some action to this that when enemy is closer than 'attack-range' they will do an attack with 'y'-delay.

If your enemies remain static in place and you wish to have the combat as 'transactional' that you always start the fights, then you can add it to the same attack-function in reverse.

Not sure if I answered your question here but hope this helps :D