public void shootBottomRight(int bullets)
        {
            motor.MotorSpeed = 0;

            animation.myEffect = SpriteEffects.FlipHorizontally;
            activity = EnemyActivity2.enemyShootDiagDown;

            while (bullets != 0 && animation.currentFrame != animation.frameCount - 1 && bw.CancellationPending == false)
            {
                Thread.Sleep(10);

                if (MainMenuScreen.currentGameScreen == 1)
                {
                    while (!MainMenuScreen.gamePlayScreen.IsActive && bw.CancellationPending == false)
                    {
                        Thread.Sleep(5);
                    }
                }
                else
                {
                    while (!MainMenuScreen.gamePlayScreen2.IsActive && bw.CancellationPending == false)
                    {
                        Thread.Sleep(5);
                    }
                }

                if (animation.currentFrame == animation.frameCount - 1)
                {
                    bullets--;

                    animation.currentFrame = 15;          //this is the frame where the bear starts shooting, so loop the shooting until out of bullets

                    shootStartFrame = 15;            //covers the case if the animation type changes mid shooting
                }
            }

            shootStartFrame = 0;
            activity = EnemyActivity2.enemyIdle;
        }
 //Fired when we collide with another object. Use this to stop jumping
 //and resume normal movement
 public bool OnCollision(Fixture fix1, Fixture fix2, Contact contact)
 {
     //Check if we are both jumping this frame and last frame
     //so that we ignore the initial collision from jumping away from
     //the ground
     if (activity == EnemyActivity2.enemyJumping && oldActivity == EnemyActivity2.enemyJumping)
     {
         activity = EnemyActivity2.enemyIdle;
     }
     return true;
 }
        public EnemyCompositeCharacter2(World world, Vector2 position, float width, float height, float mass, Texture2D texture)
            : base(world, position, width, height, mass, texture)
        {
            if (width > height)
            {
                throw new Exception("Error width > height: can't make character because wheel would stick out of body");
            }

            this.animation = new Animation();
            this.audioEmitter = new AudioEmitter();
            this.drawOffset = new Vector2(0f, 0f);
            this.shootStartFrame = 0;

            this.bulletQueue = new Queue<Bullet>();
            this.tempBulletArray = bulletQueue.ToArray();
            this.bulletAdded = false;

            activity = EnemyActivity2.enemyIdle;

            wheel.OnCollision += new OnCollisionEventHandler(OnCollision);
        }
        public void moveRight(int millis, int speed)
        {
            motor.MotorSpeed = speed;
            activity = EnemyActivity2.enemyRunning;
            animation.myEffect = SpriteEffects.FlipHorizontally;
            Thread.Sleep(20);
            if (speed < 5)
            {
                animation.frameTime = 60;
            }
            else
            {
                animation.frameTime = 30;
            }

            int i = 0;

            while (bw.CancellationPending == false && i < millis)
            {
                Thread.Sleep(10);

                if (MainMenuScreen.currentGameScreen == 1)
                {
                    while (!MainMenuScreen.gamePlayScreen.IsActive && bw.CancellationPending == false)
                    {
                        Thread.Sleep(5);
                    }
                }
                else
                {
                    while (!MainMenuScreen.gamePlayScreen2.IsActive && bw.CancellationPending == false)
                    {
                        Thread.Sleep(5);
                    }
                }

                i += 10;
            }

            motor.MotorSpeed = 0;
            activity = EnemyActivity2.enemyIdle;
        }
        public void jump()
        {
            activity = EnemyActivity2.enemyJumping;
            motor.MotorSpeed = 0;
            jumpForce.Y = jumpImpulse;
            body.ApplyLinearImpulse(jumpForce, body.Position);

            while (activity != EnemyActivity2.enemyIdle && bw.CancellationPending == false)
            {
                Thread.Sleep(10);
            }

            activity = EnemyActivity2.enemyIdle;
        }
        public void idle(int millis)
        {
            activity = EnemyActivity2.enemyIdle;

            int i = 0;

            while (bw.CancellationPending == false && i < millis)
            {
                Thread.Sleep(10);

                if (MainMenuScreen.currentGameScreen == 1)
                {
                    while (!MainMenuScreen.gamePlayScreen.IsActive && bw.CancellationPending == false)
                    {
                        Thread.Sleep(5);
                    }
                }
                else
                {
                    while (!MainMenuScreen.gamePlayScreen2.IsActive && bw.CancellationPending == false)
                    {
                        Thread.Sleep(5);
                    }
                }

                i += 10;
            }
        }
        protected override void HandleInput(GameTime gameTime)
        {
            handleBullets();

            handleAnimation(gameTime);

            if (MainMenuScreen.currentGameScreen == 1)
            {
                //update 3d sound
                audioEmitter.Position = new Vector3(Position.X, Position.Y, 1f) / GameplayScreen.soundDistanceFactor;

                if (soundEffectInstance != null)
                {
                    if (soundEffectInstance.State == SoundState.Playing)
                    {
                        soundEffectInstance.Apply3D(GameplayScreen.audioListener, audioEmitter);
                    }
                }
            }
            else
            {
                //update 3d sound
                audioEmitter.Position = new Vector3(Position.X, Position.Y, 1f) / GameplayScreen.soundDistanceFactor;

                if (soundEffectInstance != null)
                {
                    if (soundEffectInstance.State == SoundState.Playing)
                    {
                        soundEffectInstance.Apply3D(GameplayScreen2.audioListener, audioEmitter);
                    }
                }
            }

            oldActivity = activity;
        }
        public void stopScript()
        {
            if (bw != null)
            {
                if (bw.IsBusy)
                {
                    bw.CancelAsync();

                    while (threadCompleted == false)
                    {
                        Thread.Sleep(1);
                    }

                    threadCompleted = false;

                    activity = EnemyActivity2.enemyIdle;
                }
            }
        }