Hey all. Completely new to Phaser. I have been doing a basic game coding course during lockdown to keep me busy. I’ve made a (very) simple top down RPG game. Currently, pressing the space key causes the player to attack based on the last direction they moved. Trying to set up a ranged attack and I’m such a noob that I keep going in circles.
So far, when the player pressed the control key, a blue orb appears in front of them, again based on the last direction they moved. It moves away from the player in the correct direction too. However, I need to reset in between each attack, as the orb just keeps on getting further and further from the player, rather than starting next to them each time. Additionally, it likes to go in diagonals after the first attack.
How would I go about resetting the attack each time please? Code is below and, if it helps, all the files are in the zip file at https://github.com/snewport8/snewportZenva
Many, many thanks in advance (driving me up the wall!)
Code so far is as follows:
// magic attack
if (this.scene.key.isDown && !this.playerMagicAttacking) {
this.pMagic.alpha = 1;
this.playerMagicAttacking = true;
this.scene.time.delayedCall(600, () => {
this.pMagic.alpha = 0;
this.playerMagicAttacking = false;
this.magicHit = false;
}, [], this);
}
if (this.playerMagicAttacking) {
if (this.pMagic.flipX) {
this.pMagic.angle -= 10;
} else {
this.pMagic.angle += 10;
}
} else {
if (this.currentDirection === Direction.DOWN) {
this.pMagic.setAngle(-270);
this.pMagic.body.setVelocityY(100);
} else if (this.currentDirection === Direction.UP) {
this.pMagic.setAngle(-90);
this.pMagic.body.setVelocityY(-100);
} else {
this.pMagic.setAngle(0);
this.pMagic.body.setVelocityX(100);
}
this.pMagic.flipX = false;
if (this.currentDirection === Direction.LEFT) {
this.pMagic.flipX = true;
this.pMagic.body.setVelocityX(-100)
}