
class enemyWorm extends Phaser.Physics.Arcade.Sprite {
    constructor(scene, xPos, yPos, texture) {
        super(scene, xPos, yPos, texture);
        // had to do this to create a physics body 
        scene.physics.add.existing(this);
        // set up the physics properties 
        this.setBounce(0.2);
        this.setCollideWorldBounds(true);
        // Add is to the scene to make it visible/active etc 
        scene.add.existing(this);

        // pseudo private properites
        this.scene = scene;
        this._VELOCITY = 60;
    } //  constructor() 

    WormMove(xDir, yDir) {

       
        if (xDir === 0 && yDir === 0)/** if there is no direction to the player nothing happens. */ {
            this.anims.play('Wmv', true);
            //plays animation if nothing happens.
           
        } else {
            if (xDir !== 0) {
                
                if (WormEnemy_spr.x === -1) /** if the worm enemy sprite x position equals -1 it plays an animation */{
                    this.anims.play('Wmv', true);
                    //plays animation

                } else if (WormEnemy_spr.x === 1) /** if the worm enemy sprite x position equals 1 it plays an animation */ {
                    this.anims.play('Wmv', true);
                      //plays animation
                }
            }
            
            if (yDir === -1) /** if the worm enemy sprite y position equals -1 it plays an animation */{
                this.anims.play('Wmv', true);
                   //plays animation
            } else if (yDir === 1) /** if the worm enemy sprite y position equals 1 it plays an animation */{
                this.anims.play('Wmv', true);
                  //plays animation
            }

        }

    }

    WormGetMove() {
         //work out directions the enemy needs to move to get closer to player
         let xDif = (player1_spr.x - this.x);
         /**  the xDif is calculated by the x positions of the player sprite and the worm sprite by taking it away.*/
        let yDif = (player1_spr.y - this.y);
        /**   the yDif is calculated by the y positions of the player sprite and the worm sprite by taking it away.*/
        let xDir = 0;//the x direction which we use to calculate and set the velocity 
        let yDir = 0;//the y direction which we use to calculate and set the velocity 
        this.setVelocityX(Math.sign(xDif) * this._VELOCITY);
        /**This calculation sets the velocity on the X axis 
         by calculating whether the worm goes left or right if the xdif is negative or positive */
        this.setVelocityY(Math.sign(yDif) * this._VELOCITY);
        /**This calculation sets the velocity on the Y axis
           by calculating whether the worm goes up or down if the ydif is negative or positive */
        //move the worm using the results of the calculations in get move.
        this.WormMove(xDir, yDir);
    }; // end of getMove()
    } // end of updateMe()

    