JavaScript/jQuery fight system

Place for questions and answers for all newcomers and new coders. This is a free for all forum, no question is too stupid and to noob.
Post Reply
User avatar
Miroidan
Posts: 53
Joined: Sat Sep 27, 2014 7:23 pm

JavaScript/jQuery fight system

Post 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)
User avatar
Miroidan
Posts: 53
Joined: Sat Sep 27, 2014 7:23 pm

Re: JavaScript/jQuery fight system

Post 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.
User avatar
MikuzA
Posts: 395
Joined: Thu Aug 08, 2013 8:57 am

Re: JavaScript/jQuery fight system

Post 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
Why so serious?

Business Intelligence, Data Engineering, Data Mining
PHP, HTML, JavaScript, Bash/KornShell, Python, C#, PL/SQL
MySQL, DB2, Oracle, Snowflake
Pentaho, DataStage, Matillion, Unity3D, Blender
Post Reply

Return to “Beginner Help and Support”