Mizukage Posted October 27, 2015 Share Posted October 27, 2015 My battle function after objects collision function fightEngine(gracz, enemy) { //Trying to freze player during fight playerSprite.body.immovable = true; if (this.enemies.hp > 0) { this.enemies.hp -= playerDmg; console.log('Enemy recieved ' + playerDmg + ' dmg'); if (this.enemies.hp <= 0) { var enemyGold = Math.floor(Math.random() * this.enemies.goldMax) + this.enemies.goldMin; //get grind stuff player.gold += enemyGold; player.exp += this.enemies.exp; //delete the enemy object enemy.kill(); this.shatter.play(); console.log('"' + this.enemies.name + '"' + ' is dead.'); console.log('Enemy drop ' + enemyGold + ' gold.'); console.log('You gain ' + this.enemies.exp + ' experience.'); //Restore life for next enemies clone this.enemies.hp = 50; } else { var enemyDmg = Math.floor(Math.random() * this.enemies.attackMax) + this.enemies.attackMin; player.hp -= enemyDmg; console.log('You lost ' + enemyDmg + ' life'); if (player.hp <= 0) { console.log('You are dead'); } } }I spend few hours and still have no idea how to change this battle to turn.For ex. function battle() {player attack//time for sound and animationenemy attack//time for sound and animation} Add to this only checking object who recieved dmg is alive, if is than fine, if not then can start another new function like a enemyDie(enemy) or something like that. Link to comment Share on other sites More sharing options...
WombatTurkey Posted October 28, 2015 Share Posted October 28, 2015 Hey Mizuk, what do you mean when you say 'battle to turn'? Link to comment Share on other sites More sharing options...
Mizukage Posted October 28, 2015 Author Share Posted October 28, 2015 For ex. function battle() {player attack//time for sound and animationenemy attack//time for sound and animation} Now whole battle have 0000001 sec Link to comment Share on other sites More sharing options...
drhayes Posted October 28, 2015 Share Posted October 28, 2015 You posted this before and I answered: http://www.html5gamedevs.com/topic/18139-problem-with-enemies-grup-and-battle-sytem/ Did my solution not work? Are you still running this as the collision handler for a sprite and a group? Link to comment Share on other sites More sharing options...
Mizukage Posted October 28, 2015 Author Share Posted October 28, 2015 I have no idea how to inject your tip from this subject to my code.Nothing change in code Link to comment Share on other sites More sharing options...
drhayes Posted October 28, 2015 Share Posted October 28, 2015 You want to use timers. If you want battle to only happen every 1 second, you need code that looks like this:game.time.events.add(1000, fightBattle, null, gracz, enemy);That will call this function once every second, passing in "gracz" and "enemy" as its two arguments. If you want first the enemy to attack, then wait for animation, then player to attack, then wait for animation, you'll end up having multiple timers. Or, better yet, you'll start the enemy attacking and, when it's done, start a timer to start the player attack. Regardless, the solution won't look like a single function that you call. It's going to end up as multiple functions that get called one after another all controlled by events (onAnimationComplete) and timers. Mizukage and WombatTurkey 2 Link to comment Share on other sites More sharing options...
Recommended Posts