private void pushBullet(Vector2 position, float direction)
 {
     for (int i = 0; i < bulletCount; i++)
     {
         if (!bullets[i].active)
         {
             bullets[i] = new GunBullet(position, direction + (float)(Math.PI / 9 * Game1.rand.NextDouble() - (Math.PI / 18)));
             AudioLib.playSoundEffect(machineGunSoundEffect);
             return;
         }
     }
 }
            public void update(LevelState parentWorld, GameTime currentTime)
            {
                if (!active)
                {
                    return;
                }

                timePassed += currentTime.ElapsedGameTime.Milliseconds;

                bool hitWall = false;

                if (timePassed > maxWaveMotionBulletTime || (hitWall = parentWorld.Map.hitTestWall(position)))
                {
                    if (hitWall)
                    {
                        AudioLib.playSoundEffect("waveHit");
                        parentWorld.Particles.pushImpactEffect(position, Color.Lerp(new Color(224, 255, 255, 127), new Color(0.0f, 0.0f, 1.0f, 0.5f), (float)(Math.Sin(timePassed / 1000f + colorSpinOffset))));
                    }

                    active = false;
                    return;
                }

                //calculate directional velocity by taking d/dt of a predefined parametric path (Dan just did some calc on a rotation matrix and tweaked the values until it looked good)
                Vector2 velocity = new Vector2((float)(Math.Cos(direction) - (15 * 2 * (Math.PI / 100) * Math.Sin(direction) * Math.Cos(2 * Math.PI / 13 * timePassed / 20))), (float)(Math.Sin(direction) + (15 * 2 * (Math.PI / 100) * Math.Cos(direction) * Math.Cos(2 * Math.PI / 13 * timePassed / 20))));

                position += motionBulletSpeed * velocity * currentTime.ElapsedGameTime.Milliseconds;

                for (int i = 0; i < parentWorld.EntityList.Count; i++)
                {
                    if (parentWorld.EntityList[i] is Player)
                    {
                        continue;
                    }

                    if (hitTestEntity(parentWorld.EntityList[i]))
                    {
                        parentWorld.EntityList[i].knockBack(Vector2.Normalize(velocity), 1.5f, 12);
                        AudioLib.playSoundEffect("waveHit");
                        parentWorld.Particles.pushImpactEffect(position, Color.Lerp(new Color(224, 255, 255, 127), new Color(0.0f, 0.0f, 1.0f, 0.5f), (float)(Math.Sin(timePassed / 1000f + colorSpinOffset))));
                        if (parentWorld.EntityList[i].Death == false)
                        {
                            this.active = false;
                        }
                    }
                }

                prevPosition2 = prevPosition1;
                prevPosition1 = position;
            }
        public override void knockBack(Vector2 direction, float magnitude, int damage, Entity attacker)
        {
            if (knockBackTimer > knockBackDuration)
            {
                parentWorld.Particles.pushBloodParticle(CenterPoint);
                parentWorld.Particles.pushBloodParticle(CenterPoint);
                parentWorld.Particles.pushBloodParticle(CenterPoint);
                parentWorld.Particles.pushBloodParticle(CenterPoint);
                parentWorld.Particles.pushBloodParticle(CenterPoint);
                parentWorld.Particles.pushBloodParticle(CenterPoint);
                parentWorld.Particles.pushBloodParticle(CenterPoint);
                parentWorld.Particles.pushBloodParticle(CenterPoint);
                parentWorld.Particles.pushBloodParticle(CenterPoint);

                enemy_life -= damage;

                if (deadCushySoundTimer > 500f)
                {
                    AudioLib.playSoundEffect("fleshyKnockBack");

                    deadCushySoundTimer = 0;
                }

                if (enemy_life < 1)
                {
                    broodState = BroodLordState.Dying;
                    AudioLib.playSoundEffect("alienChaserDie");
                    for (int i = 0; i < 20; i++)
                    {
                        parentWorld.Particles.pushExplosiveGib(CenterPoint);
                    }

                    for (int i = 0; i < 10; i++)
                    {
                        parentWorld.Particles.pushGib(CenterPoint);
                    }
                    parentWorld.pushCoin(this);
                }

                knockBackTimer = 0;
            }
        }
        public override void update(GameTime currentTime)
        {
            switch (dropItem)
            {
            case DropItemType.CoinDrop:
                if (state == DropState.Active)
                {
                    animationTime += currentTime.ElapsedGameTime.Milliseconds;

                    for (int i = 0; i < parentWorld.EntityList.Count; i++)
                    {
                        if (parentWorld.EntityList[i] is Player)
                        {
                            if (hitTest(parentWorld.EntityList[i]))
                            {
                                GameCampaign.Player_Coin_Amount = GameCampaign.Player_Coin_Amount + (int)value;
                                LevelState.ElapsedCoinAmount   += (int)value;

                                AudioLib.playSoundEffect("testCoin");

                                state = DropState.Inactive;
                            }
                        }
                    }

                    if (isKnockedBack)
                    {
                        knockedBackTime += currentTime.ElapsedGameTime.Milliseconds;

                        if (knockedBackTime > knockBackDuration)
                        {
                            isKnockedBack = false;
                        }
                    }
                    else
                    {
                        velocity = Vector2.Zero;
                    }

                    Vector2 nextStep = position + (velocity * currentTime.ElapsedGameTime.Milliseconds);

                    Vector2 finalPos = parentWorld.Map.reloactePosition(position, nextStep, dimensions);
                    position = finalPos;
                }
                else
                {
                    position = new Vector2(-100, -100);
                }
                break;

            case DropItemType.AmmoDrop:
                if (state == DropState.Active)
                {
                    for (int i = 0; i < parentWorld.EntityList.Count; i++)
                    {
                        if (parentWorld.EntityList[i] is Player)
                        {
                            InputDevice2.PPG_Player playerIndex = ((Player)parentWorld.EntityList[i]).Index;

                            if (hitTest(parentWorld.EntityList[i]))
                            {
                                AudioLib.playSoundEffect("ammoPickup");
                                if (ammo_value == AmmoValue.fullAmmo)
                                {
                                    if (playerIndex == InputDevice2.PPG_Player.Player_1)
                                    {
                                        GameCampaign.Player_Ammunition = 100;
                                    }
                                    else
                                    {
                                        GameCampaign.Player2_Ammunition = 100;
                                    }
                                }
                                else
                                {
                                    if (playerIndex == InputDevice2.PPG_Player.Player_1)
                                    {
                                        float ammo = GameCampaign.Player_Ammunition + (int)ammo_value;
                                        if (ammo > 100)
                                        {
                                            GameCampaign.Player_Ammunition = 100;
                                        }
                                        else
                                        {
                                            GameCampaign.Player_Ammunition += (int)ammo_value;
                                        }
                                    }
                                    else
                                    {
                                        float ammo = GameCampaign.Player_Ammunition + (int)ammo_value;
                                        if (ammo > 100)
                                        {
                                            GameCampaign.Player2_Ammunition = 100;
                                        }
                                        else
                                        {
                                            GameCampaign.Player2_Ammunition += (int)ammo_value;
                                        }
                                    }
                                }
                                state = DropState.Inactive;
                            }
                        }
                    }

                    if (isKnockedBack)
                    {
                        knockedBackTime += currentTime.ElapsedGameTime.Milliseconds;

                        if (knockedBackTime > knockBackDuration)
                        {
                            isKnockedBack = false;
                        }
                    }
                    else
                    {
                        velocity = Vector2.Zero;
                    }

                    Vector2 nextStep = position + (velocity * currentTime.ElapsedGameTime.Milliseconds);

                    Vector2 finalPos = parentWorld.Map.reloactePosition(position, nextStep, dimensions);
                    position = finalPos;
                }
                else
                {
                    position = new Vector2(-100, -100);
                }
                break;

            case DropItemType.MedDrop:
                if (state == DropState.Active)
                {
                    for (int i = 0; i < parentWorld.EntityList.Count; i++)
                    {
                        if (parentWorld.EntityList[i] is Player)
                        {
                            if (hitTest(parentWorld.EntityList[i]))
                            {
                                InputDevice2.PPG_Player playerIndex = ((Player)parentWorld.EntityList[i]).Index;
                                AudioLib.playSoundEffect("healthSound");
                                if (med_value == MedValue.fullPack)
                                {
                                    if (((Player)parentWorld.EntityList[i]).Index == InputDevice2.PPG_Player.Player_1)
                                    {
                                        GameCampaign.Player_Health = 100;
                                    }
                                    else
                                    {
                                        GameCampaign.Player2_Health = 100;
                                    }
                                }
                                else
                                {
                                    if (((Player)parentWorld.EntityList[i]).Index == InputDevice2.PPG_Player.Player_1)
                                    {
                                        float health = GameCampaign.Player_Health + (int)med_value;
                                        if (health > 100)
                                        {
                                            GameCampaign.Player_Health = 100;
                                        }
                                        else
                                        {
                                            GameCampaign.Player_Health += (int)med_value;
                                        }
                                    }
                                    else
                                    {
                                        float health = GameCampaign.Player2_Health + (int)med_value;
                                        if (health > 100)
                                        {
                                            GameCampaign.Player2_Health = 100;
                                        }
                                        else
                                        {
                                            GameCampaign.Player2_Health += (int)med_value;
                                        }
                                    }
                                }
                                state = DropState.Inactive;
                            }
                        }
                    }

                    if (isKnockedBack)
                    {
                        knockedBackTime += currentTime.ElapsedGameTime.Milliseconds;

                        if (knockedBackTime > knockBackDuration)
                        {
                            isKnockedBack = false;
                        }
                    }
                    else
                    {
                        velocity = Vector2.Zero;
                    }

                    Vector2 nextStep = position + (velocity * currentTime.ElapsedGameTime.Milliseconds);

                    Vector2 finalPos = parentWorld.Map.reloactePosition(position, nextStep, dimensions);
                    position = finalPos;
                }
                else
                {
                    position = new Vector2(-100, -100);
                }
                break;

            default:
                throw new System.InvalidOperationException("invalid DropItem state");
            }
        }
Esempio n. 5
0
        public override void update(GameTime currentTime)
        {
            animation_time += currentTime.ElapsedGameTime.Milliseconds;

            if (chaserState == SlowChaserState.Idle)
            {
                state = EnemyState.Moving;

                timer += currentTime.ElapsedGameTime.Milliseconds;

                directionAnims[(int)direction_facing].Animation = directionAnims[(int)direction_facing].Skeleton.Data.FindAnimation("idle");

                velocity = Vector2.Zero;

                if (timer > idleTime)
                {
                    targetEntity = null;

                    for (int i = 0; i < parentWorld.EntityList.Count; i++)
                    {
                        if (parentWorld.EntityList[i].Enemy_Type == EnemyType.Player || parentWorld.EntityList[i].Enemy_Type == EnemyType.Guard || parentWorld.EntityList[i].Enemy_Type == EnemyType.Prisoner)
                        {
                            if (Vector2.Distance(parentWorld.EntityList[i].Position, position) < attackRadius && (targetEntity == null || Vector2.Distance(parentWorld.EntityList[i].Position, position) < Vector2.Distance(targetEntity.Position, position)) && !parentWorld.EntityList[i].Death)
                            {
                                targetEntity = parentWorld.EntityList[i];
                            }
                        }
                    }

                    if (targetEntity != null && aggressionTime > maxAggressionTime)
                    {
                        targetPosition = targetEntity.CenterPoint;
                        timer          = 0;
                        chaseIteration = 0;
                        chaserState    = SlowChaserState.WindUp;
                        AudioLib.playSoundEffect("alienChaserAlert");
                    }
                    else if (targetEntity != null && aggressionTime <= maxAggressionTime)
                    {
                        aggressionTime += currentTime.ElapsedGameTime.Milliseconds;
                    }
                    else if (targetEntity == null)
                    {
                        aggressionTime -= currentTime.ElapsedGameTime.Milliseconds;

                        if (aggressionTime < 0)
                        {
                            aggressionTime = 0;
                        }
                    }
                }
            }
            else if (chaserState == SlowChaserState.WindUp)
            {
                state = EnemyState.Chase;

                velocity = Vector2.Zero;

                directionAnims[(int)direction_facing].Animation = directionAnims[(int)direction_facing].Skeleton.Data.FindAnimation("windUp");

                timer += currentTime.ElapsedGameTime.Milliseconds;

                if (timer > windUpTime)
                {
                    timer       = 0;
                    chaserState = SlowChaserState.Sprint;

                    double angle = Math.Atan2(targetPosition.Y - CenterPoint.Y, targetPosition.X - CenterPoint.X);
                    velocity = new Vector2((float)(Math.Cos(angle)), (float)(Math.Sin(angle))) * chaseSpeed;
                }
            }
            else if (chaserState == SlowChaserState.Sprint)
            {
                state = EnemyState.Chase;

                timer += currentTime.ElapsedGameTime.Milliseconds;

                directionAnims[(int)direction_facing].Animation = directionAnims[(int)direction_facing].Skeleton.Data.FindAnimation("charge");

                if (timer > chaseTime)
                {
                    chaseIteration++;

                    if (chaseIteration >= numberOfChaseIterations)
                    {
                        timer        = 0;
                        targetEntity = null;
                        chaserState  = SlowChaserState.Cooldown;

                        velocity = Vector2.Zero;
                    }
                    else
                    {
                        timer          = 0;
                        targetPosition = targetEntity.CenterPoint;
                        chaserState    = SlowChaserState.WindUp;
                    }
                }
            }
            else if (chaserState == SlowChaserState.Cooldown)
            {
                state = EnemyState.Idle;

                timer += currentTime.ElapsedGameTime.Milliseconds;

                directionAnims[(int)direction_facing].Animation = directionAnims[(int)direction_facing].Skeleton.Data.FindAnimation("coolDown");

                if (timer > coolDownTime)
                {
                    timer          = 0;
                    chaserState    = SlowChaserState.Idle;
                    aggressionTime = maxAggressionTime * 0.8f;
                }
                else if (timer > coolDownTime / 4)
                {
                    velocity = Vector2.Zero;
                }
            }
            else if (chaserState == SlowChaserState.KnockedBack)
            {
                state = EnemyState.Moving;

                if (enemy_life < 1)
                {
                    chaserState = SlowChaserState.Dying;
                    parentWorld.pushCoin(this);
                    animation_time = 0;
                    directionAnims[(int)direction_facing].Animation = directionAnims[(int)direction_facing].Skeleton.Data.FindAnimation(Game1.rand.Next() % 2 == 0 ? "die" : Game1.rand.Next() % 2 == 0 ? "die2" : "die3");
                    AudioLib.playSoundEffect("alienChaserDie");
                    return;
                }

                knockBackTime += currentTime.ElapsedGameTime.Milliseconds;

                if (knockBackTime > knockBackDuration)
                {
                    targetEntity   = null;
                    chaserState    = SlowChaserState.Idle;
                    aggressionTime = 0.95f * maxAggressionTime;
                }
            }
            else if (chaserState == SlowChaserState.Dying)
            {
                this.dimensions = new Vector2(2);
                this.velocity   = Vector2.Zero;
                this.death      = true;
            }
            else
            {
                throw new Exception("Invalid SlowChaser state");
            }

            for (int i = 0; i < parentWorld.EntityList.Count; i++)
            {
                if (parentWorld.EntityList[i].Enemy_Type != EnemyType.Alien && chaserState != SlowChaserState.Dying)
                {
                    if (Vector2.Distance(parentWorld.EntityList[i].Position, position) < 300)
                    {
                        if (hitTest(parentWorld.EntityList[i]))
                        {
                            parentWorld.EntityList[i].knockBack(parentWorld.EntityList[i].CenterPoint - CenterPoint, 6, 7);

                            if (chaserState == SlowChaserState.Sprint && Vector2.Distance(position, targetEntity.Position) < GlobalGameConstants.TileSize.X)
                            {
                                timer        = 0;
                                targetEntity = null;
                                chaserState  = SlowChaserState.Cooldown;
                                velocity    *= -0.1f;
                            }
                        }
                    }
                }
            }

            if (Math.Abs(velocity.X) > Math.Abs(velocity.Y))
            {
                if (velocity.X > 0)
                {
                    direction_facing = GlobalGameConstants.Direction.Right;
                }
                else if (velocity.X < 0)
                {
                    direction_facing = GlobalGameConstants.Direction.Left;
                }
            }
            else if (Math.Abs(velocity.X) < Math.Abs(velocity.Y))
            {
                if (velocity.Y > 0)
                {
                    direction_facing = GlobalGameConstants.Direction.Down;
                }
                else if (velocity.Y < 0)
                {
                    direction_facing = GlobalGameConstants.Direction.Up;
                }
            }

            Vector2 newPos = position + (this.velocity * currentTime.ElapsedGameTime.Milliseconds);

            position = parentWorld.Map.reloactePosition(position, newPos, dimensions);

            directionAnims[(int)direction_facing].Animation.Apply(directionAnims[(int)direction_facing].Skeleton, animation_time / 1000f, chaserState == SlowChaserState.Dying ? false : true);
        }
        public override void update(GameTime currentTime)
        {
            animation_time += currentTime.ElapsedGameTime.Milliseconds / 1000f;
            sound_timer    += currentTime.ElapsedGameTime.Milliseconds;

            if (sound_timer > 250f)
            {
                play_sound = true;
            }

            if (sound_alert && state == ChargerState.search && entity_found == null)
            {
                state       = ChargerState.alert;
                alert_timer = 0.0f;
            }

            if (state == ChargerState.dying)
            {
                velocity = Vector2.Zero;

                death = true;

                // may the programming gods have mercy on me hacking over this complicated state machine
                goto DeadSkipStates;
            }

            if (disable_movement == true)
            {
                disable_movement_time += currentTime.ElapsedGameTime.Milliseconds;

                if (disable_movement_time > 300)
                {
                    disable_movement_time = 0.0f;
                    disable_movement      = false;
                    velocity = Vector2.Zero;
                    state    = ChargerState.alert;
                }

                directionAnims[(int)direction_facing].Animation = directionAnims[(int)direction_facing].Skeleton.Data.FindAnimation("hurt");
            }
            else
            {
                switch (state)
                {
                case ChargerState.search:
                    directionAnims[(int)direction_facing].Animation = directionAnims[(int)direction_facing].Skeleton.Data.FindAnimation("idle");

                    change_direction_time += currentTime.ElapsedGameTime.Milliseconds;
                    //first if state is if enemy was knocked back by a enemy of a different type
                    if (enemy_found == false)
                    {
                        for (int i = 0; i < parentWorld.EntityList.Count; i++)
                        {
                            if (parentWorld.EntityList[i] == this || (GameCampaign.PlayerAllegiance < 0.3 && parentWorld.EntityList[i] is Player))
                            {
                                continue;
                            }
                            else if (parentWorld.EntityList[i].Enemy_Type != enemy_type && parentWorld.EntityList[i].Enemy_Type != EnemyType.NoType && parentWorld.EntityList[i].Death == false)
                            {
                                component.update(this, parentWorld.EntityList[i], currentTime, parentWorld);
                                if (enemy_found == true)
                                {
                                    entity_found = parentWorld.EntityList[i];
                                    break;
                                }
                            }
                        }
                    }

                    if (enemy_found)
                    {
                        state    = ChargerState.windUp;
                        velocity = Vector2.Zero;
                    }
                    else
                    {
                        if (change_direction_time > 5000)
                        {
                            switch (direction_facing)
                            {
                            case GlobalGameConstants.Direction.Right:
                                direction_facing = GlobalGameConstants.Direction.Down;
                                break;

                            case GlobalGameConstants.Direction.Left:
                                direction_facing = GlobalGameConstants.Direction.Up;
                                break;

                            case GlobalGameConstants.Direction.Up:
                                direction_facing = GlobalGameConstants.Direction.Right;
                                break;

                            default:
                                direction_facing = GlobalGameConstants.Direction.Left;
                                break;
                            }
                            change_direction_time = 0.0f;
                        }
                        entity_found = null;
                        sound_alert  = false;
                    }
                    break;

                case ChargerState.alert:
                    directionAnims[(int)direction_facing].Animation = directionAnims[(int)direction_facing].Skeleton.Data.FindAnimation("idle");

                    if (sound_alert && entity_found == null)
                    {
                        //if false then sound didn't hit a wall
                        if (!parentWorld.Map.soundInSight(this, sound_position))
                        {
                            directionAnims[(int)direction_facing].Animation = directionAnims[(int)direction_facing].Skeleton.Data.FindAnimation("run");
                            alert_timer += currentTime.ElapsedGameTime.Milliseconds;
                            for (int i = 0; i < parentWorld.EntityList.Count; i++)
                            {
                                if (parentWorld.EntityList[i].Enemy_Type != enemy_type && parentWorld.EntityList[i].Enemy_Type != EnemyType.NoType && parentWorld.EntityList[i].Death == false)
                                {
                                    float distance = Vector2.Distance(CenterPoint, parentWorld.EntityList[i].CenterPoint);
                                    if (distance <= range_distance)
                                    {
                                        enemy_found    = true;
                                        entity_found   = parentWorld.EntityList[i];
                                        state          = ChargerState.windUp;
                                        animation_time = 0.0f;
                                        sound_alert    = false;
                                        alert_timer    = 0.0f;
                                        windup_timer   = 0.0f;
                                        animation_time = 0.0f;
                                        velocity       = Vector2.Zero;
                                        charge_timer   = 0.0f;
                                        break;
                                    }
                                }
                            }

                            if (alert_timer > 3000 || ((int)CenterPoint.X == (int)sound_position.X && (int)CenterPoint.Y == (int)sound_position.Y))
                            {
                                entity_found   = null;
                                enemy_found    = false;
                                sound_alert    = false;
                                state          = ChargerState.search;
                                velocity       = Vector2.Zero;
                                animation_time = 0.0f;
                                charge_timer   = 0.0f;
                                windup_timer   = 0.0f;
                                animation_time = 0.0f;
                            }
                        }
                        else
                        {
                            entity_found   = null;
                            enemy_found    = false;
                            sound_alert    = false;
                            state          = ChargerState.search;
                            velocity       = Vector2.Zero;
                            animation_time = 0.0f;
                            charge_timer   = 0.0f;
                            windup_timer   = 0.0f;
                            animation_time = 0.0f;
                        }
                    }
                    else if (entity_found != null)
                    {
                        sound_alert = false;
                        float distance = Vector2.Distance(CenterPoint, entity_found.CenterPoint);
                        if (parentWorld.Map.enemyWithinRange(entity_found, this, range_distance) && distance < range_distance && entity_found.Death == false)
                        {
                            state          = ChargerState.windUp;
                            animation_time = 0.0f;
                        }
                        else
                        {
                            entity_found   = null;
                            enemy_found    = false;
                            state          = ChargerState.search;
                            velocity       = Vector2.Zero;
                            animation_time = 0.0f;
                            charge_timer   = 0.0f;
                            windup_timer   = 0.0f;
                            animation_time = 0.0f;
                        }
                    }
                    break;

                case ChargerState.windUp:
                    directionAnims[(int)direction_facing].Animation = directionAnims[(int)direction_facing].Skeleton.Data.FindAnimation("windUp");
                    windup_timer += currentTime.ElapsedGameTime.Milliseconds;
                    angle         = (float)Math.Atan2(entity_found.CenterPoint.Y - CenterPoint.Y, entity_found.CenterPoint.X - CenterPoint.X);

                    if (windup_timer > 300)
                    {
                        animation_time = 0.0f;
                        state          = ChargerState.charge;
                        velocity       = new Vector2(8.0f * (float)(Math.Cos(angle)), 8.0f * (float)(Math.Sin(angle)));

                        charge_timer = 0.0f;
                    }
                    break;

                case ChargerState.charge:
                    directionAnims[(int)direction_facing].Animation = directionAnims[(int)direction_facing].Skeleton.Data.FindAnimation("charge");
                    charge_timer += currentTime.ElapsedGameTime.Milliseconds;
                    for (int i = 0; i < parentWorld.EntityList.Count; i++)
                    {
                        if (parentWorld.EntityList[i] == this)
                        {
                            continue;
                        }
                        if (hitTest(parentWorld.EntityList[i]))
                        {
                            if (play_sound)
                            {
                                AudioLib.playSoundEffect("chargerImpact");
                                sound_timer = 0.0f;
                                play_sound  = false;
                            }

                            Vector2 direction = parentWorld.EntityList[i].CenterPoint - CenterPoint;
                            parentWorld.EntityList[i].knockBack(direction, knockback_magnitude, enemy_damage);
                        }
                    }

                    if (charge_timer > 800)
                    {
                        if (entity_found.Death == true)
                        {
                            entity_found = null;
                        }
                        sound_alert    = false;
                        state          = ChargerState.alert;
                        velocity       = Vector2.Zero;
                        animation_time = 0.0f;
                        charge_timer   = 0.0f;
                        windup_timer   = 0.0f;
                        animation_time = 0.0f;
                        enemy_found    = false;
                    }
                    break;

                default:
                    break;
                }
            }

DeadSkipStates:
            Vector2 pos = new Vector2(position.X, position.Y);
            Vector2 nextStep = new Vector2(position.X + velocity.X, position.Y + velocity.Y);
            Vector2 finalPos = parentWorld.Map.reloactePosition(pos, nextStep, dimensions);

            position.X = finalPos.X;
            position.Y = finalPos.Y;

            directionAnims[(int)direction_facing].Animation.Apply(directionAnims[(int)direction_facing].Skeleton, animation_time, state == ChargerState.dying ? false : true);

            if (enemy_life <= 0 && state != ChargerState.dying && death == false)
            {
                directionAnims[(int)direction_facing].Animation = directionAnims[(int)direction_facing].Skeleton.Data.FindAnimation(Game1.rand.Next() % 3 == 0 ? "die" : Game1.rand.Next() % 2 == 0 ? "die2" : "die3");
                death          = true;
                state          = ChargerState.dying;
                animation_time = 0;
                parentWorld.pushCoin(this);
            }
        }
        public override void knockBack(Vector2 direction, float magnitude, int damage, Entity attacker)
        {
            if (guardState == PatrolGuardState.KnockBack)
            {
                return;
            }

            health -= damage;

            if (health <= 0 && guardState != PatrolGuardState.Dying)
            {
                if (attacker is Player)
                {
                    GameCampaign.AlterAllegiance(-0.01f);
                }

                guardState     = PatrolGuardState.Dying;
                animation_time = 0;

                velocity = Vector2.Zero;

                dimensions /= 8;

                parentWorld.pushCoin(this);

                death = true;

                return;
            }
            else if (guardState == PatrolGuardState.Dying)
            {
                parentWorld.Particles.pushBloodParticle(CenterPoint);
                parentWorld.Particles.pushBloodParticle(CenterPoint);
                parentWorld.Particles.pushBloodParticle(CenterPoint);

                if (deadCushySoundTimer > 500f)
                {
                    AudioLib.playSoundEffect("fleshyKnockBack");

                    deadCushySoundTimer = 0;
                }

                return;
            }

            direction.Normalize();
            velocity = direction * (magnitude / 2);

            knockBackTime = 0.0f;

            guardState     = PatrolGuardState.KnockBack;
            animation_time = 0;

            parentWorld.Particles.pushBloodParticle(CenterPoint);
            parentWorld.Particles.pushBloodParticle(CenterPoint);
            parentWorld.Particles.pushBloodParticle(CenterPoint);

            AudioLib.playSoundEffect("fleshyKnockBack");

            //where you look in the entity's direction and start chasing them
            if (attacker != null && (attacker.Enemy_Type != EnemyType.NoType && attacker.Enemy_Type != enemy_type))
            {
                target = attacker;
            }
        }
        public override void update(GameTime currentTime)
        {
            animation_time += currentTime.ElapsedGameTime.Milliseconds;

            if (sound_alert && molotovState == MolotovState.MoveWait && entity_found == null)
            {
                molotovState   = MolotovState.Alert;
                animation_time = 0.0f;
            }

            if (molotovState == MolotovState.InvalidState)
            {
                throw new Exception("Invalid State handling");
            }
            else if (molotovState == MolotovState.MoveWait)
            {
                moveWaitTimer += currentTime.ElapsedGameTime.Milliseconds;

                // check if player is in front of enemy within range. if so throw a molotov
                if (flame.active == false)
                {
                    MolotovFlame f = new MolotovFlame();
                    if (direction_facing == GlobalGameConstants.Direction.Up || direction_facing == GlobalGameConstants.Direction.Down)
                    {
                        f.dimensions = new Vector2(GlobalGameConstants.TileSize.X * 3, GlobalGameConstants.TileSize.Y * 4);
                    }
                    else
                    {
                        f.dimensions = new Vector2(GlobalGameConstants.TileSize.X * 4, GlobalGameConstants.TileSize.Y * 3);
                    }

                    switch (direction_facing)
                    {
                    case GlobalGameConstants.Direction.Up:
                        f.position = position + new Vector2(-GlobalGameConstants.TileSize.X, -GlobalGameConstants.TileSize.Y * 4);
                        break;

                    case GlobalGameConstants.Direction.Down:
                        f.position = position + new Vector2(-GlobalGameConstants.TileSize.X, dimensions.Y);
                        break;

                    case GlobalGameConstants.Direction.Left:
                        f.position = position + new Vector2(-(GlobalGameConstants.TileSize.X * 4), -GlobalGameConstants.TileSize.Y);
                        break;

                    case GlobalGameConstants.Direction.Right:
                        f.position = position + new Vector2(dimensions.X, -GlobalGameConstants.TileSize.Y);
                        break;
                    }

                    for (int i = 0; i < parentWorld.EntityList.Count; i++)
                    {
                        if (parentWorld.EntityList[i] == this)
                        {
                            continue;
                        }

                        if (parentWorld.EntityList[i] is Player || parentWorld.EntityList[i] is Enemy)
                        {
                            if (parentWorld.EntityList[i] is Enemy)
                            {
                                if (((Enemy)parentWorld.EntityList[i]).Enemy_Type == Enemy.EnemyType.Prisoner)
                                {
                                    continue;
                                }
                            }

                            if (GameCampaign.PlayerAllegiance < 0.3 && parentWorld.EntityList[i] is Player)
                            {
                                continue;
                            }
                            else if (f.hitTestWithEntity(parentWorld.EntityList[i]))
                            {
                                animation_time = 0.0f;

                                entity_found = parentWorld.EntityList[i];

                                molotovState = MolotovState.WindUp;
                                windUpTimer  = 0.0f;
                                break;
                            }
                        }
                    }
                }

                if (moveWaitStepping)
                {
                    switch (direction_facing)
                    {
                    case GlobalGameConstants.Direction.Up:
                        velocity = new Vector2(0.0f, -molotovMovementSpeed);
                        break;

                    case GlobalGameConstants.Direction.Down:
                        velocity = new Vector2(0.0f, molotovMovementSpeed);
                        break;

                    case GlobalGameConstants.Direction.Left:
                        velocity = new Vector2(-molotovMovementSpeed, 0.0f);
                        break;

                    case GlobalGameConstants.Direction.Right:
                        velocity = new Vector2(molotovMovementSpeed, 0.0f);
                        break;
                    }

                    directionAnims[(int)direction_facing].Animation = directionAnims[(int)direction_facing].Skeleton.Data.FindAnimation("run");
                }
                else
                {
                    velocity = Vector2.Zero;

                    directionAnims[(int)direction_facing].Animation = directionAnims[(int)direction_facing].Skeleton.Data.FindAnimation("idle");
                }

                if (moveWaitTimer > moveStepTime)
                {
                    moveWaitStepping = !moveWaitStepping;
                    moveWaitTimer    = 0.0f;

                    if (moveWaitStepping)
                    {
                        direction_facing = (GlobalGameConstants.Direction)(Game1.rand.Next() % 4);
                    }
                }
            }
            else if (molotovState == MolotovState.Alert)
            {
                if (sound_alert && entity_found == null)
                {
                    directionAnims[(int)direction_facing].Animation = directionAnims[(int)direction_facing].Skeleton.Data.FindAnimation("run");

                    if (!parentWorld.Map.soundInSight(this, sound_position))
                    {
                        if (flame.active == false)
                        {
                            alert_timer += currentTime.ElapsedGameTime.Milliseconds;
                            for (int i = 0; i < parentWorld.EntityList.Count; i++)
                            {
                                if (parentWorld.EntityList[i].Enemy_Type != enemy_type && parentWorld.EntityList[i].Enemy_Type != EnemyType.NoType && parentWorld.EntityList[i].Death == false)
                                {
                                    float distance = Vector2.Distance(CenterPoint, parentWorld.EntityList[i].CenterPoint);
                                    if (distance <= range_distance)
                                    {
                                        enemy_found    = true;
                                        entity_found   = parentWorld.EntityList[i];
                                        molotovState   = MolotovState.WindUp;
                                        animation_time = 0.0f;
                                        sound_alert    = false;
                                        alert_timer    = 0.0f;
                                        windUpTimer    = 0.0f;
                                        animation_time = 0.0f;
                                        velocity       = Vector2.Zero;
                                        break;
                                    }
                                }
                            }

                            if (alert_timer > 3000 || ((int)CenterPoint.X == (int)sound_position.X && (int)CenterPoint.Y == (int)sound_position.Y))
                            {
                                entity_found   = null;
                                enemy_found    = false;
                                sound_alert    = false;
                                molotovState   = MolotovState.MoveWait;
                                velocity       = Vector2.Zero;
                                animation_time = 0.0f;
                                windUpTimer    = 0.0f;
                            }
                        }
                    }
                    else
                    {
                        entity_found   = null;
                        enemy_found    = false;
                        sound_alert    = false;
                        molotovState   = MolotovState.MoveWait;
                        velocity       = Vector2.Zero;
                        animation_time = 0.0f;
                        windUpTimer    = 0.0f;
                    }
                }
                else if (entity_found != null)
                {
                    sound_alert = false;
                    directionAnims[(int)direction_facing].Animation = directionAnims[(int)direction_facing].Skeleton.Data.FindAnimation("idle");

                    float distance = Vector2.Distance(CenterPoint, entity_found.CenterPoint);
                    if (flame.active == false)
                    {
                        if (parentWorld.Map.enemyWithinRange(entity_found, this, range_distance) && distance < range_distance)
                        {
                            molotovState   = MolotovState.WindUp;
                            windUpTimer    = 0.0f;
                            animation_time = 0.0f;
                        }
                        else
                        {
                            entity_found   = null;
                            enemy_found    = false;
                            molotovState   = MolotovState.MoveWait;
                            velocity       = Vector2.Zero;
                            animation_time = 0.0f;
                            windUpTimer    = 0.0f;
                            animation_time = 0.0f;
                        }
                    }
                    else
                    {
                        float angle = (float)(Math.Atan2(entity_found.CenterPoint.Y - CenterPoint.Y, entity_found.CenterPoint.X - CenterPoint.X));

                        if ((angle > (-1 * Math.PI / 4) && angle < (Math.PI / 4)))
                        {
                            direction_facing = GlobalGameConstants.Direction.Right;
                        }
                        else if (((angle > (3 * Math.PI / 4) || angle < (-3 * Math.PI / 4))))
                        {
                            direction_facing = GlobalGameConstants.Direction.Left;
                        }
                        else if ((angle > (-3 * Math.PI / 4) && angle < (-1 * Math.PI / 4)))
                        {
                            direction_facing = GlobalGameConstants.Direction.Up;
                        }
                        else if ((angle > Math.PI / 4 && angle < 3 * Math.PI / 4))
                        {
                            direction_facing = GlobalGameConstants.Direction.Down;
                        }
                    }
                }
            }
            else if (molotovState == MolotovState.WindUp)
            {
                directionAnims[(int)direction_facing].Animation = directionAnims[(int)direction_facing].Skeleton.Data.FindAnimation("windUp");

                windUpTimer += currentTime.ElapsedGameTime.Milliseconds;
                angle        = (float)(Math.Atan2(entity_found.CenterPoint.Y - CenterPoint.Y, entity_found.CenterPoint.X - CenterPoint.X));

                if (windUpTimer > windUpDuration)
                {
                    animation_time = 0.0f;

                    molotovState  = MolotovState.Throwing;
                    throwingTimer = 0.0f;
                    throwPosition = position;
                }

                velocity = Vector2.Zero;
            }
            else if (molotovState == MolotovState.Throwing)
            {
                directionAnims[(int)direction_facing].Animation = directionAnims[(int)direction_facing].Skeleton.Data.FindAnimation("attack");

                throwingTimer += currentTime.ElapsedGameTime.Milliseconds;

                Vector2 throwDirection = Vector2.Zero;


                /*switch (direction_facing)
                 * {
                 *  case GlobalGameConstants.Direction.Up:
                 *      throwDirection = new Vector2(0, -1);
                 *      break;
                 *  case GlobalGameConstants.Direction.Down:
                 *      throwDirection = new Vector2(0, 1);
                 *      break;
                 *  case GlobalGameConstants.Direction.Left:
                 *      throwDirection = new Vector2(-1, 0);
                 *      break;
                 *  case GlobalGameConstants.Direction.Right:
                 *      throwDirection = new Vector2(1, 0);
                 *      break;
                 * }*/

                throwDirection = new Vector2((float)(Math.Cos(angle)), (float)(Math.Sin(angle)));

                throwPosition  = position + (throwVelocity * throwingTimer * throwDirection);
                flame.position = throwPosition;

                if (parentWorld.Map.hitTestWall(flame.position) || parentWorld.Map.hitTestWall(flame.position + flame.dimensions))
                {
                    throwingTimer = 999f;
                }
                else
                {
                    for (int i = 0; i < parentWorld.EntityList.Count; i++)
                    {
                        if (parentWorld.EntityList[i] is Player)
                        {
                            if (flame.hitTestWithEntity(parentWorld.EntityList[i]))
                            {
                                throwingTimer = 999f;
                                break;
                            }
                        }
                    }
                }

                if (throwingTimer > throwDuration)
                {
                    animation_time = 0.0f;

                    AudioLib.playSoundEffect("molotovExplode");

                    flame = new MolotovFlame(throwPosition);

                    molotovState  = MolotovState.Alert;
                    moveWaitTimer = 0.0f;
                    alert_timer   = 0.0f;
                }
            }
            else if (molotovState == MolotovState.KnockedBack)
            {
                knockBackTime += currentTime.ElapsedGameTime.Milliseconds;

                directionAnims[(int)direction_facing].Animation = directionAnims[(int)direction_facing].Skeleton.Data.FindAnimation("hurt");

                if (knockBackTime > knockBackDuration)
                {
                    molotovState   = MolotovState.MoveWait;
                    entity_found   = null;
                    animation_time = 0.0f;
                }
            }
            else if (molotovState == MolotovState.Dying)
            {
                velocity = Vector2.Zero;
                death    = true;
                //
            }
            else
            {
                throw new NotImplementedException("Need to complete other states first");
            }

            if (flame.active)
            {
                flame.update(parentWorld, currentTime);
            }

            Vector2 newPos   = position + (velocity);
            Vector2 finalPos = parentWorld.Map.reloactePosition(position, newPos, dimensions);

            position = finalPos;

            directionAnims[(int)direction_facing].Animation.Apply(directionAnims[(int)direction_facing].Skeleton, animation_time / 1000f, molotovState == MolotovState.MoveWait ? true : false);
        }
        public override void update(GameTime currentTime)
        {
            if (enemy_life <= 0 && death == false)
            {
                death                      = true;
                state                      = ChaseState.death;
                animation_time             = 0.0f;
                current_skeleton.Animation = current_skeleton.Skeleton.Data.FindAnimation(death_anim[(int)(Game1.rand.Next()) % 3]);

                parentWorld.pushCoin(this);
            }

            switch (state)
            {
            case ChaseState.search:
                change_direction_time     += currentTime.ElapsedGameTime.Milliseconds;
                current_skeleton.Animation = current_skeleton.Skeleton.Data.FindAnimation("run");
                for (int i = 0; i < parentWorld.EntityList.Count; i++)
                {
                    if (parentWorld.EntityList[i] == this || (parentWorld.EntityList[i] is Player && GameCampaign.PlayerAllegiance < 0.3))
                    {
                        continue;
                    }

                    if (parentWorld.EntityList[i].Enemy_Type != enemy_type && parentWorld.EntityList[i].Enemy_Type != EnemyType.NoType && !parentWorld.EntityList[i].Death)
                    {
                        component.update(this, parentWorld.EntityList[i], currentTime, parentWorld);
                        if (enemy_found)
                        {
                            component      = chaseComponent;
                            state          = ChaseState.chase;
                            animation_time = 0.0f;
                            chase_target   = parentWorld.EntityList[i];
                            break;
                        }
                    }
                }
                break;

            case ChaseState.chase:
                //checks to see if player was hit
                //wind up

                //component won't update when the swing is in effect
                float distance = Vector2.Distance(chase_target.CenterPoint, CenterPoint);
                current_skeleton.Animation = current_skeleton.Skeleton.Data.FindAnimation("chase");
                if (distance > 300.0f || chase_target.Death)
                {
                    state          = ChaseState.search;
                    component      = searchComponent;
                    enemy_found    = false;
                    wind_anim      = 0.0f;
                    animation_time = 0.0f;
                }
                else
                {
                    component.update(this, chase_target, currentTime, parentWorld);
                    if (distance < 64.0f)
                    {
                        current_skeleton.Animation = current_skeleton.Skeleton.Data.FindAnimation("windUp");
                        state          = ChaseState.windUp;
                        wind_anim      = 0.0f;
                        animation_time = 0.0f;
                    }
                }
                break;

            case ChaseState.windUp:
                wind_anim += currentTime.ElapsedGameTime.Milliseconds;
                //animation_time = 0.0f;

                velocity = Vector2.Zero;
                switch (direction_facing)
                {
                case GlobalGameConstants.Direction.Right:
                    sword_position.X = position.X + dimensions.X;
                    sword_position.Y = position.Y;
                    break;

                case GlobalGameConstants.Direction.Left:
                    sword_position.X = position.X - sword_hitbox.X;
                    sword_position.Y = position.Y;
                    break;

                case GlobalGameConstants.Direction.Up:
                    sword_position.Y = position.Y - sword_hitbox.Y;
                    sword_position.X = CenterPoint.X - sword_hitbox.X / 2;
                    break;

                default:
                    sword_position.Y = CenterPoint.Y + dimensions.Y / 2;
                    sword_position.X = CenterPoint.X - sword_hitbox.X / 2;
                    break;
                }
                if (wind_anim > 300)
                {
                    state          = ChaseState.attack;
                    wind_anim      = 0.0f;
                    animation_time = 0.0f;
                }
                break;

            case ChaseState.attack:
                wind_anim += currentTime.ElapsedGameTime.Milliseconds;
                current_skeleton.Animation = current_skeleton.Skeleton.Data.FindAnimation("attack");
                if (swordSlashHitTest(chase_target))
                {
                    Vector2 direction = chase_target.CenterPoint - CenterPoint;

                    if (play_sound)
                    {
                        AudioLib.playSoundEffect("swordHit");
                        play_sound = false;
                    }
                    chase_target.knockBack(direction, knockback_magnitude, enemy_damage);
                }
                else
                {
                    if (play_sound)
                    {
                        AudioLib.playSoundEffect("testSword");
                        play_sound = false;
                    }
                }
                if (wind_anim > 500)
                {
                    play_sound                 = true;
                    dimensions                 = new Vector2(48f, 48f);
                    wind_anim                  = 0.0f;
                    animation_time             = 0.0f;
                    state                      = ChaseState.chase;
                    current_skeleton.Animation = current_skeleton.Skeleton.Data.FindAnimation("chase");
                }
                break;

            case ChaseState.knockback:
                if (death == false)
                {
                    disable_movement_time     += currentTime.ElapsedGameTime.Milliseconds;
                    current_skeleton.Animation = current_skeleton.Skeleton.Data.FindAnimation("hurt");
                    if (disable_movement_time > 300)
                    {
                        state                 = ChaseState.search;
                        velocity              = Vector2.Zero;
                        component             = searchComponent;
                        disable_movement      = false;
                        disable_movement_time = 0;
                        animation_time        = 0.0f;
                    }
                }
                break;

            case ChaseState.death:
                velocity = Vector2.Zero;
                break;

            default:
                break;
            }

            Vector2 pos = new Vector2(position.X, position.Y);

            Vector2 nextStep = new Vector2(position.X + velocity.X, position.Y + velocity.Y);
            Vector2 finalPos = parentWorld.Map.reloactePosition(pos, nextStep, dimensions);

            position.X = finalPos.X;
            position.Y = finalPos.Y;

            animation_time += currentTime.ElapsedGameTime.Milliseconds / 1000f;

            //decides if the animation loops or not
            current_skeleton.Animation.Apply(current_skeleton.Skeleton, animation_time, (wind_anim == 0 && !death) ? true : false);
        }
        public override void update(GameTime currentTime)
        {
            if (sound_alert && state == mutantBallState.Search && entity_found == null && !death)
            {
                state       = mutantBallState.Alert;
                alert_timer = 0.0f;
            }

            if (enemy_life <= 0 && !death)
            {
                velocity = Vector2.Zero;
                death    = true;
                AudioLib.playSoundEffect("alienChaserDie");
                current_skeleton.Animation = current_skeleton.Skeleton.Data.FindAnimation(deathAnim[Game1.rand.Next() % 3]);
                state          = mutantBallState.Death;
                animation_time = 0.0f;
                parentWorld.pushCoin(this);
            }
            switch (state)
            {
            case mutantBallState.Search:
                current_skeleton.Animation = current_skeleton.Skeleton.Data.FindAnimation("idle");
                change_direction_time     += currentTime.ElapsedGameTime.Milliseconds;
                if (!enemy_found)
                {
                    for (int i = 0; i < parentWorld.EntityList.Count; i++)
                    {
                        if (parentWorld.EntityList[i] == this)
                        {
                            continue;
                        }
                        else if (parentWorld.EntityList[i].Enemy_Type != enemy_type && parentWorld.EntityList[i].Enemy_Type != EnemyType.NoType)
                        {
                            component.update(this, parentWorld.EntityList[i], currentTime, parentWorld);
                            if (enemy_found)
                            {
                                entity_found = parentWorld.EntityList[i];
                                break;
                            }
                        }
                    }
                }
                if (enemy_found)
                {
                    state          = mutantBallState.Agressive;
                    velocity       = Vector2.Zero;
                    animation_time = 0.0f;
                }
                else
                {
                    if (change_direction_time > 5000)
                    {
                        switch (direction_facing)
                        {
                        case GlobalGameConstants.Direction.Right:
                            direction_facing = GlobalGameConstants.Direction.Down;
                            break;

                        case GlobalGameConstants.Direction.Left:
                            direction_facing = GlobalGameConstants.Direction.Up;
                            break;

                        case GlobalGameConstants.Direction.Up:
                            direction_facing = GlobalGameConstants.Direction.Right;
                            break;

                        default:
                            direction_facing = GlobalGameConstants.Direction.Left;
                            break;
                        }
                        change_direction_time = 0.0f;
                    }
                }

                switch (direction_facing)
                {
                case GlobalGameConstants.Direction.Right:
                    current_skeleton = walk_right;
                    break;

                case GlobalGameConstants.Direction.Left:
                    current_skeleton = walk_right;
                    break;

                case GlobalGameConstants.Direction.Up:
                    current_skeleton = walk_up;
                    break;

                default:
                    current_skeleton = walk_down;
                    break;
                }
                break;

            /*case mutantBallState.Alert:
             *  if (sound_alert && entity_found == null)
             *  {
             *      //if false then sound didn't hit a wall
             *      if (!parentWorld.Map.soundInSight(this, sound_position))
             *      {
             *          current_skeleton.Animation = current_skeleton.Skeleton.Data.FindAnimation("run");
             *          alert_timer += currentTime.ElapsedGameTime.Milliseconds;
             *          for (int i = 0; i < parentWorld.EntityList.Count; i++)
             *          {
             *              if (parentWorld.EntityList[i].Enemy_Type != enemy_type && parentWorld.EntityList[i].Enemy_Type != EnemyType.NoType && parentWorld.EntityList[i].Death == false)
             *              {
             *                  float distance = Vector2.Distance(CenterPoint, parentWorld.EntityList[i].CenterPoint);
             *                  if (distance <= range_distance)
             *                  {
             *                      enemy_found = true;
             *                      entity_found = parentWorld.EntityList[i];
             *                      state = mutantBallState.Search;
             *                      animation_time = 0.0f;
             *                      sound_alert = false;
             *                      animation_time = 0.0f;
             *                      velocity = Vector2.Zero;
             *                      agressive_timer = 0.0f;
             *                      break;
             *                  }
             *              }
             *          }
             *
             *          if (alert_timer > 3000 || ((int)CenterPoint.X == (int)sound_position.X && (int)CenterPoint.Y == (int)sound_position.Y))
             *          {
             *              entity_found = null;
             *              enemy_found = false;
             *              sound_alert = false;
             *              state = mutantBallState.Search;
             *              velocity = Vector2.Zero;
             *              animation_time = 0.0f;
             *              agressive_timer = 0.0f;
             *              animation_time = 0.0f;
             *          }
             *      }
             *      else
             *      {
             *          entity_found = null;
             *          enemy_found = false;
             *          sound_alert = false;
             *          state = mutantBallState.Search;
             *          velocity = Vector2.Zero;
             *          animation_time = 0.0f;
             *          agressive_timer = 0.0f;
             *          animation_time = 0.0f;
             *      }
             *  }
             *  else if (entity_found != null)
             *  {
             *      sound_alert = false;
             *      float distance = Vector2.Distance(CenterPoint, entity_found.CenterPoint);
             *      if (parentWorld.Map.enemyWithinRange(entity_found, this, range_distance) && distance < range_distance)
             *      {
             *          state = mutantBallState.Search;
             *          animation_time = 0.0f;
             *      }
             *      else
             *      {
             *          entity_found = null;
             *          enemy_found = false;
             *          state = mutantBallState.Search;
             *          velocity = Vector2.Zero;
             *          animation_time = 0.0f;
             *          agressive_timer = 0.0f;
             *          animation_time = 0.0f;
             *      }
             *  }
             *  break;*/
            case mutantBallState.Agressive:
                agressive_timer           += currentTime.ElapsedGameTime.Milliseconds;
                current_skeleton.Animation = current_skeleton.Skeleton.Data.FindAnimation("attack");
                sound_timer += currentTime.ElapsedGameTime.Milliseconds;

                if (sound_timer > 30)
                {
                    play_sound = true;
                }

                float angle_from_entity = (float)Math.Atan2(entity_found.CenterPoint.Y - CenterPoint.Y, entity_found.CenterPoint.X - CenterPoint.X);

                switch (direction_facing)
                {
                case GlobalGameConstants.Direction.Right:
                    if (angle_from_entity > Math.PI / 4)
                    {
                        direction_facing = GlobalGameConstants.Direction.Down;
                        current_skeleton = walk_down;
                    }
                    else if (angle_from_entity < -1 * Math.PI / 4)
                    {
                        direction_facing = GlobalGameConstants.Direction.Up;
                        current_skeleton = walk_up;
                    }
                    break;

                case GlobalGameConstants.Direction.Left:
                    if (angle_from_entity > -3 * Math.PI / 4 && angle_from_entity < 0)
                    {
                        direction_facing = GlobalGameConstants.Direction.Up;
                        current_skeleton = walk_up;
                    }
                    else if (angle_from_entity < 3 * Math.PI / 4 && angle_from_entity > 0)
                    {
                        direction_facing = GlobalGameConstants.Direction.Down;
                        current_skeleton = walk_down;
                    }
                    break;

                case GlobalGameConstants.Direction.Up:
                    if (angle_from_entity > -1 * Math.PI / 4)
                    {
                        direction_facing = GlobalGameConstants.Direction.Right;
                        current_skeleton = walk_right;
                    }
                    else if (angle_from_entity < -3 * Math.PI / 4)
                    {
                        direction_facing = GlobalGameConstants.Direction.Left;
                        current_skeleton = walk_right;
                    }
                    break;

                default:
                    if (angle_from_entity > 3 * Math.PI / 4)
                    {
                        direction_facing = GlobalGameConstants.Direction.Left;
                        current_skeleton = walk_right;
                    }
                    else if (angle_from_entity < Math.PI / 4)
                    {
                        direction_facing = GlobalGameConstants.Direction.Right;
                        current_skeleton = walk_right;
                    }
                    break;
                }

                velocity = new Vector2((float)Math.Cos(angle_from_entity), (float)Math.Sin(angle_from_entity));

                angle += 0.1f;
                if (angle >= (float)(2 * Math.PI))
                {
                    angle = 0;
                }

                float temp_radius = 0.0f;

                while (temp_radius <= radius)
                {
                    ball_coordinate.X = CenterPoint.X + temp_radius * (float)(Math.Cos(angle));
                    ball_coordinate.Y = CenterPoint.Y + temp_radius * (float)(Math.Sin(angle));

                    for (int i = 0; i < parentWorld.EntityList.Count; i++)
                    {
                        if (parentWorld.EntityList[i] == this)
                        {
                            continue;
                        }
                        else if (parentWorld.EntityList[i].Death == false && hitTestBall(parentWorld.EntityList[i], ball_coordinate.X, ball_coordinate.Y))
                        {
                            if (play_sound)
                            {
                                AudioLib.playSoundEffect("chargerImpact");
                                play_sound  = false;
                                sound_timer = 0.0f;
                            }
                            float   distance  = Vector2.Distance(ball_coordinate, CenterPoint);
                            Vector2 direction = new Vector2(distance * (float)(Math.Cos(angle)), distance * (float)(Math.Sin(angle)));

                            float temp_knockback_magnitude = knockback_magnitude / (radius / temp_radius);
                            parentWorld.EntityList[i].knockBack(direction, temp_knockback_magnitude, enemy_damage, this);
                        }
                    }
                    temp_radius++;
                }

                if (agressive_timer > 4000)
                {
                    state           = mutantBallState.Search;
                    velocity        = Vector2.Zero;
                    agressive_timer = 0.0f;
                    enemy_found     = false;
                    entity_found    = null;
                    animation_time  = 0.0f;
                }
                break;

            case mutantBallState.KnockBack:
                disable_movement_time     += currentTime.ElapsedGameTime.Milliseconds;
                current_skeleton.Animation = current_skeleton.Skeleton.Data.FindAnimation("hurt");
                if (disable_movement_time > 300)
                {
                    state = mutantBallState.Search;
                    disable_movement_time = 0.0f;
                    velocity       = Vector2.Zero;
                    animation_time = 0.0f;
                }
                break;

            case mutantBallState.Death:
                velocity = Vector2.Zero;
                break;

            default:
                break;
            }
            Vector2 pos      = new Vector2(position.X, position.Y);
            Vector2 nextStep = new Vector2(position.X + velocity.X, position.Y + velocity.Y);
            Vector2 finalPos = parentWorld.Map.reloactePosition(pos, nextStep, dimensions);

            position.X = finalPos.X;
            position.Y = finalPos.Y;

            animation_time += currentTime.ElapsedGameTime.Milliseconds / 1000f;
            current_skeleton.Animation.Apply(current_skeleton.Skeleton, animation_time, (state == mutantBallState.Death)? false:true);
        }
        public override void knockBack(Vector2 direction, float magnitude, int damage, Entity attacker)
        {
            if (!death)
            {
                if (disable_movement == false)
                {
                    AudioLib.playSoundEffect("fleshyKnockBack");
                    state = mutantBallState.KnockBack;
                    if (Math.Abs(direction.X) > (Math.Abs(direction.Y)))
                    {
                        if (direction.X < 0)
                        {
                            velocity = new Vector2(-5.51f * magnitude, direction.Y / 100 * magnitude);
                        }
                        else
                        {
                            velocity = new Vector2(5.51f * magnitude, direction.Y / 100 * magnitude);
                        }
                    }
                    else
                    {
                        if (direction.Y < 0)
                        {
                            velocity = new Vector2(direction.X / 100f * magnitude, -5.51f * magnitude);
                        }
                        else
                        {
                            velocity = new Vector2((direction.X / 100f) * magnitude, 5.51f * magnitude);
                        }
                    }

                    enemy_life = enemy_life - damage;
                }

                if (attacker == null)
                {
                    return;
                }
                else if (attacker.Enemy_Type != enemy_type && attacker.Enemy_Type != EnemyType.NoType)
                {
                    switch (attacker.Direction_Facing)
                    {
                    case GlobalGameConstants.Direction.Right:
                        direction_facing = GlobalGameConstants.Direction.Left;
                        break;

                    case GlobalGameConstants.Direction.Left:
                        direction_facing = GlobalGameConstants.Direction.Right;
                        break;

                    case GlobalGameConstants.Direction.Up:
                        direction_facing = GlobalGameConstants.Direction.Down;
                        break;

                    default:
                        direction_facing = GlobalGameConstants.Direction.Up;
                        break;
                    }
                }
                animation_time = 0.0f;
            }
            parentWorld.Particles.pushBloodParticle(CenterPoint);
            parentWorld.Particles.pushBloodParticle(CenterPoint);
            parentWorld.Particles.pushBloodParticle(CenterPoint);
        }
        protected override void doUpdate(GameTime currentTime)
        {
            button_pressed_timer += currentTime.ElapsedGameTime.Milliseconds;
            zoom += currentTime.ElapsedGameTime.Milliseconds;

            switch (zoom_state)
            {
            case popUpZoomState.zoomIn:
                if (zoom > zoom_duration)
                {
                    pop_up_menu = true;
                    zoom_state  = popUpZoomState.zoomStay;
                    zoom        = 0.0f;
                }
                break;

            case popUpZoomState.zoomStay:
                zoom = 0.0f;
                break;

            case popUpZoomState.zoomOut:
                if (zoom > zoom_duration)
                {
                    zoom_state    = popUpZoomState.zoomStay;
                    pop_up_menu   = false;
                    pop_up_screen = false;
                    zoom          = 0.0f;
                }
                break;
            }

            if (!pop_up_menu)
            {
                if (InputDevice2.IsPlayerButtonDown(InputDevice2.PPG_Player.Player_1, InputDevice2.PlayerButton.DownDirection))
                {
                    if (!down_pressed)
                    {
                        button_pressed_timer = 0.0f;
                    }
                    down_pressed = true;
                }

                if ((down_pressed && !InputDevice2.IsPlayerButtonDown(InputDevice2.PPG_Player.Player_1, InputDevice2.PlayerButton.DownDirection)) || (down_pressed && InputDevice2.IsPlayerButtonDown(InputDevice2.PPG_Player.Player_1, InputDevice2.PlayerButton.DownDirection) && button_pressed_timer > max_button_pressed_timer))
                {
                    button_pressed_timer = 0.0f;
                    down_pressed         = false;
                    AudioLib.playSoundEffect(menuBlipSound);
                    menu_item_select++;

                    if (menu_item_select >= options_list.Count())
                    {
                        menu_item_select = menu_item_select % options_list.Count();
                    }
                    else if (menu_item_select < 0)
                    {
                        menu_item_select += options_list.Count();
                    }
                }

                if (InputDevice2.IsPlayerButtonDown(InputDevice2.PPG_Player.Player_1, InputDevice2.PlayerButton.UpDirection))
                {
                    if (!up_pressed)
                    {
                        button_pressed_timer = 0.0f;
                    }

                    up_pressed = true;
                }

                if ((up_pressed && !InputDevice2.IsPlayerButtonDown(InputDevice2.PPG_Player.Player_1, InputDevice2.PlayerButton.UpDirection)) || (up_pressed && InputDevice2.IsPlayerButtonDown(InputDevice2.PPG_Player.Player_1, InputDevice2.PlayerButton.UpDirection) && button_pressed_timer > max_button_pressed_timer))
                {
                    button_pressed_timer = 0.0f;
                    up_pressed           = false;
                    AudioLib.playSoundEffect(menuBlipSound);
                    menu_item_select--;

                    if (menu_item_select > 0)
                    {
                        menu_item_select = menu_item_select % options_list.Count();
                    }
                    else if (menu_item_select < 0)
                    {
                        menu_item_select += options_list.Count();
                    }
                }

                if (InputDevice2.IsPlayerButtonDown(InputDevice2.PPG_Player.Player_1, InputDevice2.PlayerButton.Confirm))
                {
                    confirm_pressed = true;
                }
                else if (confirm_pressed)
                {
                    confirm_pressed = false;

                    switch (options_list[menu_item_select].text)
                    {
                    case "HIGH SCORE":
                        isComplete = true;
                        break;

                    case "ERASE HIGH SCORE":
                        pop_up_screen       = true;
                        popup_item_selected = 0;
                        zoom_state          = popUpZoomState.zoomIn;
                        HighScoresState.ResetHighScores();
                        SaveGameModule.saveGame();
                        break;

                    case "CREDITS":
                        isComplete = true;
                        break;

                    case "BACK":
                        isComplete = true;
                        break;

                    default:
                        break;
                    }
                }

                for (int i = 0; i < options_list.Count(); i++)
                {
                    if (i == menu_item_select)
                    {
                        options_list[menu_item_select].select = true;
                    }
                    else
                    {
                        options_list[i].select = false;
                    }

                    options_list[i].update(currentTime);
                }
            }
            /*************************************************************************************************************/
            else
            {
                if (InputDevice2.IsPlayerButtonDown(InputDevice2.PPG_Player.Player_1, InputDevice2.PlayerButton.LeftDirection))
                {
                    if (!down_pressed)
                    {
                        button_pressed_timer = 0.0f;
                    }
                    down_pressed = true;
                }

                if ((down_pressed && !InputDevice2.IsPlayerButtonDown(InputDevice2.PPG_Player.Player_1, InputDevice2.PlayerButton.LeftDirection)) || (down_pressed && InputDevice2.IsPlayerButtonDown(InputDevice2.PPG_Player.Player_1, InputDevice2.PlayerButton.LeftDirection) && button_pressed_timer > max_button_pressed_timer))
                {
                    button_pressed_timer = 0.0f;
                    down_pressed         = false;

                    popup_item_selected++;

                    if (popup_item_selected >= popup_options.Count())
                    {
                        popup_item_selected = popup_item_selected % popup_options.Count();
                    }
                    else if (menu_item_select < 0)
                    {
                        popup_item_selected += popup_options.Count();
                    }
                }

                if (InputDevice2.IsPlayerButtonDown(InputDevice2.PPG_Player.Player_1, InputDevice2.PlayerButton.RightDirection))
                {
                    if (!up_pressed)
                    {
                        button_pressed_timer = 0.0f;
                    }

                    up_pressed = true;
                }

                if ((up_pressed && !InputDevice2.IsPlayerButtonDown(InputDevice2.PPG_Player.Player_1, InputDevice2.PlayerButton.RightDirection)) || (up_pressed && InputDevice2.IsPlayerButtonDown(InputDevice2.PPG_Player.Player_1, InputDevice2.PlayerButton.RightDirection) && button_pressed_timer > max_button_pressed_timer))
                {
                    button_pressed_timer = 0.0f;
                    up_pressed           = false;

                    popup_item_selected--;

                    if (popup_item_selected > 0)
                    {
                        popup_item_selected = popup_item_selected % popup_options.Count();
                    }
                    else if (popup_item_selected < 0)
                    {
                        popup_item_selected += popup_options.Count();
                    }
                }

                if (InputDevice2.IsPlayerButtonDown(InputDevice2.PPG_Player.Player_1, InputDevice2.PlayerButton.Confirm))
                {
                    confirm_pressed = true;
                }
                else if (confirm_pressed)
                {
                    confirm_pressed = false;

                    switch (popup_options[popup_item_selected].text)
                    {
                    case "NO":
                        zoom_state = popUpZoomState.zoomOut;
                        break;

                    case "YES":
                        zoom_state = popUpZoomState.zoomOut;
                        break;

                    default:
                        break;
                    }
                }

                for (int i = 0; i < popup_options.Count(); i++)
                {
                    if (i == popup_item_selected)
                    {
                        popup_options[popup_item_selected].select = true;
                    }
                    else
                    {
                        popup_options[i].select = false;
                    }

                    popup_options[i].update(currentTime);
                }
            }
        }
        public void update(Player parent, GameTime currentTime, LevelState parentWorld)
        {
            updateRocketAndExplosion(parent, currentTime, parentWorld);


            if (state == RocketLauncherState.IdleWait)
            {
                if ((parent.Index == InputDevice2.PPG_Player.Player_1 ? GameCampaign.Player_Ammunition : GameCampaign.Player2_Ammunition) >= 20)
                {
                    if (!rocket.active && !explosion.active)
                    {
                        parent.Velocity = Vector2.Zero;

                        timer = 0;
                        state = RocketLauncherState.WindUp;

                        if ((parent.Index == InputDevice2.PPG_Player.Player_1 ? GameCampaign.Player_Right_Item : GameCampaign.Player2_Item_1) == ItemType() && InputDevice2.IsPlayerButtonDown(parent.Index, InputDevice2.PlayerButton.UseItem1))
                        {
                            slot1 = true;
                            parent.LoadAnimation.Animation = parent.LoadAnimation.Skeleton.Data.FindAnimation(parent.Direction_Facing == GlobalGameConstants.Direction.Left ? "lRocket" : "rRocket");
                        }
                        else if ((parent.Index == InputDevice2.PPG_Player.Player_1 ? GameCampaign.Player_Left_Item : GameCampaign.Player2_Item_2) == ItemType() && InputDevice2.IsPlayerButtonDown(parent.Index, InputDevice2.PlayerButton.UseItem2))
                        {
                            slot1 = false;
                            parent.LoadAnimation.Animation = parent.LoadAnimation.Skeleton.Data.FindAnimation(parent.Direction_Facing == GlobalGameConstants.Direction.Left ? "rRocket" : "lRocket");
                        }

                        if (parent.Index == InputDevice2.PPG_Player.Player_1)
                        {
                            GameCampaign.Player_Ammunition -= ammo_consumption;
                        }
                        else
                        {
                            GameCampaign.Player2_Ammunition -= ammo_consumption;
                        }

                        parent.Animation_Time = 0;
                        parent.LoopAnimation  = false;
                    }
                    else
                    {
                        parent.Disable_Movement = false;
                        parent.State            = Player.playerState.Moving;
                    }
                }
                else
                {
                    parent.Disable_Movement = false;
                    parent.State            = Player.playerState.Moving;
                }
            }
            else if (state == RocketLauncherState.WindUp)
            {
                timer += currentTime.ElapsedGameTime.Milliseconds;

                if (timer > windUpDuration)
                {
                    timer = 0;
                    state = RocketLauncherState.Shooting;

                    AudioLib.playSoundEffect(rocketSound);

                    parentWorld.Particles.pushRocketCasing(new Vector2(parent.LoadAnimation.Skeleton.FindBone(parent.Direction_Facing == GlobalGameConstants.Direction.Left ? "rGun" : "lGun").WorldX, parent.LoadAnimation.Skeleton.FindBone(parent.Direction_Facing == GlobalGameConstants.Direction.Left ? "rGun" : "lGun").WorldY));

                    if (slot1)
                    {
                        rocket = new Rocket(new Vector2(parent.LoadAnimation.Skeleton.FindBone(parent.Direction_Facing == GlobalGameConstants.Direction.Left ? "lGunMuzzle" : "rGunMuzzle").WorldX, parent.LoadAnimation.Skeleton.FindBone(parent.Direction_Facing == GlobalGameConstants.Direction.Left ? "lGunMuzzle" : "rGunMuzzle").WorldY), parent.Direction_Facing);
                    }
                    else
                    {
                        rocket = new Rocket(new Vector2(parent.LoadAnimation.Skeleton.FindBone(parent.Direction_Facing == GlobalGameConstants.Direction.Left ? "lGunMuzzle" : "rGunMuzzle").WorldX, parent.LoadAnimation.Skeleton.FindBone(parent.Direction_Facing == GlobalGameConstants.Direction.Left ? "rGunMuzzle" : "lGunMuzzle").WorldY), parent.Direction_Facing);
                    }
                }


                for (int i = 0; i < parentWorld.EntityList.Count; i++)
                {
                    float distance = Vector2.Distance(parentWorld.EntityList[i].Position, new Vector2(parent.LoadAnimation.Skeleton.FindBone(parent.Direction_Facing == GlobalGameConstants.Direction.Left ? "lGunMuzzle" : "rGunMuzzle").WorldX, parent.LoadAnimation.Skeleton.FindBone(parent.Direction_Facing == GlobalGameConstants.Direction.Left ? "lGunMuzzle" : "rGunMuzzle").WorldY));
                    if (distance <= 1000 && parentWorld.EntityList[i] is Enemy)
                    {
                        ((Enemy)parentWorld.EntityList[i]).Sound_Alert    = true;
                        ((Enemy)parentWorld.EntityList[i]).Sound_Position = new Vector2(parent.LoadAnimation.Skeleton.FindBone(parent.Direction_Facing == GlobalGameConstants.Direction.Left ? "lGunMuzzle" : "rGunMuzzle").WorldX, parent.LoadAnimation.Skeleton.FindBone(parent.Direction_Facing == GlobalGameConstants.Direction.Left ? "lGunMuzzle" : "rGunMuzzle").WorldY);
                    }
                }
            }
            else if (state == RocketLauncherState.Shooting)
            {
                timer += currentTime.ElapsedGameTime.Milliseconds;

                if (timer > shootDuration)
                {
                    timer = 0;
                    state = RocketLauncherState.CoolDown;
                }
            }
            else if (state == RocketLauncherState.CoolDown)
            {
                parent.Disable_Movement = false;
                parent.State            = Player.playerState.Moving;

                timer += currentTime.ElapsedGameTime.Milliseconds;

                if (timer > coolDownDuration)
                {
                    timer = 0;
                    state = RocketLauncherState.IdleWait;
                }
            }
            else if (state == RocketLauncherState.InvalidState)
            {
                throw new Exception("Invalid Rocket Launcher State");
            }
        }
 public void popExplosion(Vector2 position)
 {
     AudioLib.playSoundEffect(explosionSound);
     explosion = new Explosion(position);
 }
Esempio n. 15
0
            public void update(LevelState parentWorld, GameTime currentTime, Entity parent)
            {
                active_timer += currentTime.ElapsedGameTime.Milliseconds;
                if (active)
                {
                    switch (state)
                    {
                    case GrenadeState.Travel:
                        if (active_timer > max_active_time)
                        {
                            state        = GrenadeState.Explosion;
                            active_timer = 0.0f;
                            dimensions   = new Vector2(96, 96);
                            position     = CenterPoint - (dimensions / 2);
                        }
                        else
                        {
                            nextStep_temp = new Vector2(position.X - (dimensions.X / 2) + velocity.X, (position.Y + velocity.X));

                            on_wall = parentWorld.Map.hitTestWall(nextStep_temp);
                            int check_corners = 0;
                            while (check_corners != 4)
                            {
                                if (on_wall == false)
                                {
                                    if (check_corners == 0)
                                    {
                                        nextStep_temp = new Vector2(position.X + (dimensions.X / 2) + velocity.X, position.Y + velocity.Y);
                                    }
                                    else if (check_corners == 1)
                                    {
                                        nextStep_temp = new Vector2(position.X + velocity.X, position.Y - (dimensions.Y / 2) + velocity.Y);
                                    }
                                    else if (check_corners == 2)
                                    {
                                        nextStep_temp = new Vector2(position.X + velocity.X, position.Y + dimensions.Y + velocity.Y);
                                    }
                                    else
                                    {
                                        position += velocity;
                                    }
                                    on_wall = parentWorld.Map.hitTestWall(nextStep_temp);
                                }
                                else
                                {
                                    state = GrenadeState.Explosion;
                                    AudioLib.playSoundEffect("testExplosion");
                                    active_timer = 0.0f;
                                    dimensions   = new Vector2(96, 96);
                                    position     = position - (dimensions / 2);
                                    break;
                                }
                                check_corners++;
                            }
                        }

                        if (on_wall == false)
                        {
                            foreach (Entity en in parentWorld.EntityList)
                            {
                                if (en == parent)
                                {
                                    continue;
                                }
                                else if (grenadeHitTest(en))
                                {
                                    state        = GrenadeState.Explosion;
                                    active_timer = 0.0f;
                                    dimensions   = new Vector2(96, 96);
                                    position     = position - (dimensions / 2);
                                    AudioLib.playSoundEffect("testExplosion");
                                    break;
                                }
                            }
                        }
                        position += velocity;
                        break;

                    case GrenadeState.Explosion:
                        explosion_timer += currentTime.ElapsedGameTime.Milliseconds;

                        foreach (Entity en in parentWorld.EntityList)
                        {
                            if (grenadeHitTest(en))
                            {
                                Vector2 direction = en.CenterPoint - CenterPoint;
                                en.knockBack(direction, 3.0f, 10);
                            }
                        }

                        if (explosion_timer > max_explosion_timer)
                        {
                            active_timer = 0.0f;
                            state        = GrenadeState.Reset;
                        }
                        break;

                    case GrenadeState.Reset:
                        dimensions = new Vector2(16, 16);
                        position   = new Vector2(0, 0);
                        active     = false;
                        break;
                    }
                }
            }
Esempio n. 16
0
        public override void update(GameTime currentTime)
        {
            float distance = float.MaxValue;

            if (disable_movement == true)
            {
                disable_movement_time += currentTime.ElapsedGameTime.Milliseconds;
                if (disable_movement_time > 300)
                {
                    disable_movement      = false;
                    disable_movement_time = 0.0f;
                    velocity = Vector2.Zero;
                }
            }
            else
            {
                switch (mech_state)
                {
                case MechState.Moving:
                    current_skeleton.Animation = current_skeleton.Skeleton.Data.FindAnimation("idle");
                    tank_hull_animation_time  += currentTime.ElapsedGameTime.Milliseconds;
                    change_direction_time     += currentTime.ElapsedGameTime.Milliseconds;

                    if (enemy_found == false)
                    {
                        for (int i = 0; i < parentWorld.EntityList.Count; i++)
                        {
                            if (parentWorld.EntityList[i] == this || (parentWorld.EntityList[i] is Player && GameCampaign.PlayerAllegiance > 0.7))
                            {
                                continue;
                            }
                            else if (parentWorld.EntityList[i].Enemy_Type != enemy_type && parentWorld.EntityList[i].Enemy_Type != EnemyType.NoType && parentWorld.EntityList[i].Death == false)
                            {
                                component.update(this, parentWorld.EntityList[i], currentTime, parentWorld);
                                if (enemy_found)
                                {
                                    entity_found = parentWorld.EntityList[i];
                                    break;
                                }
                            }
                        }
                    }

                    switch (direction_facing)
                    {
                    case GlobalGameConstants.Direction.Right:
                        velocity   = new Vector2(0.5f, 0f);
                        dimensions = new Vector2(120, 96);
                        angle      = 0.0f;
                        break;

                    case GlobalGameConstants.Direction.Left:
                        velocity   = new Vector2(-0.5f, 0f);
                        dimensions = new Vector2(120, 96);
                        angle      = (float)(Math.PI);
                        break;

                    case GlobalGameConstants.Direction.Up:
                        velocity   = new Vector2(0f, -0.5f);
                        dimensions = new Vector2(96, 120);
                        angle      = (float)(-1 * Math.PI / 2);
                        break;

                    default:
                        velocity   = new Vector2(0.0f, 0.5f);
                        dimensions = new Vector2(96, 120);
                        angle      = (float)(Math.PI / 2);
                        break;
                    }

                    if (enemy_found)
                    {
                        distance = Vector2.Distance(CenterPoint, entity_found.CenterPoint);

                        tank_hull_animation_time = 0.0f;

                        if (Math.Abs(distance) < range_distance)
                        {
                            if (Math.Abs(distance) > 192 && Math.Abs(distance) < range_distance)
                            {
                                mech_state = MechState.Firing;
                            }
                            else
                            {
                                mech_state = MechState.MeleeWindUp;
                            }
                        }
                    }

                    int  corner_check = 0;
                    bool is_on_wall   = false;

                    while (corner_check != 4)
                    {
                        if (corner_check == 0)
                        {
                            is_on_wall = parentWorld.Map.hitTestWall(position);
                        }
                        else if (corner_check == 1)
                        {
                            is_on_wall = parentWorld.Map.hitTestWall(position + new Vector2(dimensions.X, 0));
                        }
                        else if (corner_check == 2)
                        {
                            is_on_wall = parentWorld.Map.hitTestWall(position + new Vector2(0, dimensions.Y));
                        }
                        else if (corner_check == 3)
                        {
                            is_on_wall = parentWorld.Map.hitTestWall(position + dimensions);
                        }

                        if (is_on_wall)
                        {
                            if (direction_facing == GlobalGameConstants.Direction.Right || direction_facing == GlobalGameConstants.Direction.Left)
                            {
                                dimensions = new Vector2(96, 120);
                                if (Game1.rand.NextDouble() > 0.5)
                                {
                                    direction_facing = GlobalGameConstants.Direction.Up;
                                }
                                else
                                {
                                    direction_facing = GlobalGameConstants.Direction.Down;
                                }
                            }
                            else
                            {
                                dimensions = new Vector2(120, 96);
                                if (Game1.rand.NextDouble() > 0.5)
                                {
                                    direction_facing = GlobalGameConstants.Direction.Right;
                                }
                                else
                                {
                                    direction_facing = GlobalGameConstants.Direction.Left;
                                }
                            }
                            break;
                        }
                        corner_check++;
                    }

                    break;

                case MechState.Firing:
                    windup_timer += currentTime.ElapsedGameTime.Milliseconds;
                    angle         = (float)Math.Atan2(entity_found.CenterPoint.Y - current_skeleton.Skeleton.FindBone("muzzle").WorldY, entity_found.CenterPoint.X - current_skeleton.Skeleton.FindBone("muzzle").WorldX);

                    distance = Vector2.Distance(position, entity_found.Position);

                    velocity = Vector2.Zero;

                    bool enemy_in_sight = parentWorld.Map.playerInSight(angle, distance, this, entity_found);

                    if (Math.Abs(distance) > 600 || entity_found.Remove_From_List == true || enemy_in_sight)
                    {
                        mech_state   = MechState.Moving;
                        windup_timer = 0.0f;
                        enemy_found  = false;
                        return;
                    }
                    else if (Math.Abs(distance) < 192)
                    {
                        windup_timer = 0.0f;
                        mech_state   = MechState.MeleeWindUp;
                    }

                    if (windup_timer > 2000)
                    {
                        if (grenade.active == false)
                        {
                            AudioLib.playSoundEffect("tankFire");
                            rocket_angle = (float)Math.Atan2(entity_found.CenterPoint.Y - current_skeleton.Skeleton.FindBone("muzzle").WorldY, entity_found.CenterPoint.X - current_skeleton.Skeleton.FindBone("muzzle").WorldX);
                            current_skeleton.Animation = current_skeleton.Skeleton.Data.FindAnimation("attack");
                            grenade        = new Grenades(new Vector2(current_skeleton.Skeleton.FindBone("muzzle").WorldX, current_skeleton.Skeleton.FindBone("muzzle").WorldY), angle);
                            grenade.active = true;
                        }
                    }

                    if (windup_timer > 2100)
                    {
                        windup_timer = 0.0f;
                        current_skeleton.Animation = current_skeleton.Skeleton.Data.FindAnimation("idle");
                    }

                    switch (direction_facing)
                    {
                    case GlobalGameConstants.Direction.Right:
                        if (angle < -1 * Math.PI / 3.27)
                        {
                            direction_facing = GlobalGameConstants.Direction.Up;
                            dimensions       = new Vector2(96, 120);
                        }
                        else if (angle > Math.PI / 3.27)
                        {
                            direction_facing = GlobalGameConstants.Direction.Down;
                            dimensions       = new Vector2(96, 120);
                        }
                        break;

                    case GlobalGameConstants.Direction.Left:
                        if (angle < Math.PI / 1.44 && angle > Math.PI / 1.5)
                        {
                            direction_facing = GlobalGameConstants.Direction.Down;
                            dimensions       = new Vector2(96, 120);
                        }
                        else if (angle > -1 * Math.PI / 1.44 && angle < -1 * Math.PI / 1.5)
                        {
                            direction_facing = GlobalGameConstants.Direction.Up;
                            dimensions       = new Vector2(96, 120);
                        }
                        break;

                    case GlobalGameConstants.Direction.Up:
                        if (angle < -1 * Math.PI / 1.24)
                        {
                            direction_facing = GlobalGameConstants.Direction.Left;
                            dimensions       = new Vector2(120, 96);
                        }
                        else if (angle > -1 * Math.PI / 5.14)
                        {
                            direction_facing = GlobalGameConstants.Direction.Right;
                            dimensions       = new Vector2(120, 96);
                        }
                        break;

                    default:
                        if (angle < Math.PI / 5.14)
                        {
                            direction_facing = GlobalGameConstants.Direction.Right;
                            dimensions       = new Vector2(120, 96);
                            //current_skeleton = walk_right;
                        }
                        else if (angle > Math.PI / 1.24)
                        {
                            direction_facing = GlobalGameConstants.Direction.Left;
                            dimensions       = new Vector2(120, 96);
                            //current_skeleton = walk_right;
                        }
                        break;
                    }

                    break;

                case MechState.MeleeWindUp:
                    windup_timer += currentTime.ElapsedGameTime.Milliseconds;
                    angle         = (float)Math.Atan2(entity_found.CenterPoint.Y - CenterPoint.Y, entity_found.CenterPoint.X - CenterPoint.X);

                    if (windup_timer > 1000)
                    {
                        mech_state   = MechState.Melee;
                        windup_timer = 0.0f;
                        melee_active = true;
                    }

                    switch (direction_facing)
                    {
                    case GlobalGameConstants.Direction.Right:
                        if (angle < -1 * Math.PI / 3.27)
                        {
                            direction_facing = GlobalGameConstants.Direction.Up;
                            dimensions       = new Vector2(96, 120);
                            //current_skeleton = walk_up;
                        }
                        else if (angle > Math.PI / 3.27)
                        {
                            direction_facing = GlobalGameConstants.Direction.Down;
                            dimensions       = new Vector2(96, 120);
                            //current_skeleton = walk_down;
                        }
                        break;

                    case GlobalGameConstants.Direction.Left:
                        if (angle < Math.PI / 1.44 && angle > Math.PI / 1.5)
                        {
                            direction_facing = GlobalGameConstants.Direction.Down;
                            dimensions       = new Vector2(96, 120);
                            //current_skeleton = walk_down;
                        }
                        else if (angle > -1 * Math.PI / 1.44 && angle < -1 * Math.PI / 1.5)
                        {
                            direction_facing = GlobalGameConstants.Direction.Up;
                            dimensions       = new Vector2(96, 120);
                            //current_skeleton = walk_up;
                        }
                        break;

                    case GlobalGameConstants.Direction.Up:
                        if (angle < -1 * Math.PI / 1.24)
                        {
                            direction_facing = GlobalGameConstants.Direction.Left;
                            dimensions       = new Vector2(120, 96);
                            //current_skeleton = walk_right;
                        }
                        else if (angle > -1 * Math.PI / 5.14)
                        {
                            direction_facing = GlobalGameConstants.Direction.Right;
                            dimensions       = new Vector2(120, 96);
                            //current_skeleton = walk_right;
                        }
                        break;

                    default:
                        if (angle < Math.PI / 5.14)
                        {
                            direction_facing = GlobalGameConstants.Direction.Right;
                            dimensions       = new Vector2(120, 96);
                            //current_skeleton = walk_right;
                        }
                        else if (angle > Math.PI / 1.24)
                        {
                            direction_facing = GlobalGameConstants.Direction.Left;
                            dimensions       = new Vector2(120, 96);
                            //current_skeleton = walk_right;
                        }
                        break;
                    }
                    break;

                case MechState.Melee:
                    //current_skeleton.Animation = current_skeleton.Skeleton.Data.FindAnimation("idle");
                    windup_timer += currentTime.ElapsedGameTime.Milliseconds;

                    AudioLib.playTankFlameSoundEffect(true);

                    Vector2 flame_displacement = Vector2.Zero;

                    if (direction_facing == GlobalGameConstants.Direction.Left || direction_facing == GlobalGameConstants.Direction.Right)
                    {
                        flame_displacement = new Vector2(tankAnim.FrameDimensions.X / 2, 0);
                    }
                    else
                    {
                        flame_displacement = new Vector2(0, tankAnim.FrameDimensions.X / 2);
                    }

                    parentWorld.Particles.pushFlame(CenterPoint + ((direction_facing == GlobalGameConstants.Direction.Left || direction_facing == GlobalGameConstants.Direction.Up)?-1 * flame_displacement : flame_displacement), (float)((int)direction_facing * Math.PI / 2));
                    parentWorld.Particles.pushFlame(CenterPoint + ((direction_facing == GlobalGameConstants.Direction.Left || direction_facing == GlobalGameConstants.Direction.Up) ? -1 * flame_displacement : flame_displacement), (float)((int)direction_facing * Math.PI / 2));

                    switch (direction_facing)
                    {
                    case GlobalGameConstants.Direction.Right:
                        melee_position = position + new Vector2(dimensions.X, melee_hitbox.Y / 4);
                        break;

                    case GlobalGameConstants.Direction.Left:
                        melee_position = position + new Vector2(-1 * melee_hitbox.X, dimensions.Y / 4);
                        break;

                    case GlobalGameConstants.Direction.Up:
                        melee_position = position + new Vector2(dimensions.X / 4, -1 * melee_hitbox.Y);
                        break;

                    default:
                        melee_position = position + new Vector2(dimensions.X / 4, dimensions.Y);
                        break;
                    }

                    foreach (Entity en in parentWorld.EntityList)
                    {
                        if (en == this)
                        {
                            continue;
                        }
                        else if (meleeHitTest(en))
                        {
                            Vector2 direction = en.CenterPoint - CenterPoint;
                            en.knockBack(direction, 3.5f, 10, this);
                        }
                    }

                    velocity = Vector2.Zero;
                    if (windup_timer > 1500)
                    {
                        windup_timer = 0.0f;
                        melee_active = false;
                        if (Math.Abs(distance) > 300 || entity_found.Remove_From_List)
                        {
                            enemy_found = false;
                            mech_state  = MechState.Moving;
                        }
                        else if (Math.Abs(distance) > 192 && Math.Abs(distance) < 300)
                        {
                            mech_state = MechState.Firing;
                        }
                        else
                        {
                            mech_state = MechState.MeleeWindUp;
                        }
                        AudioLib.stopTankFlameSoundEffect();
                    }
                    break;

                case MechState.Reset:
                    windup_timer = 0.0f;
                    enemy_found  = false;
                    mech_state   = MechState.Moving;
                    break;

                case MechState.Death:
                    death          = true;
                    explode_timer += currentTime.ElapsedGameTime.Milliseconds;
                    velocity       = Vector2.Zero;
                    break;

                default:
                    break;
                }
            }

            if (grenade.active)
            {
                grenade.update(parentWorld, currentTime, this);
            }

            if (enemy_life <= 0 && death == false)
            {
                AudioLib.stopFlameSoundEffect();
                explode_timer += currentTime.ElapsedGameTime.Milliseconds;
                animation_time = 0.0f;
                death          = true;
                mech_state     = MechState.Death;
                velocity       = Vector2.Zero;
                parentWorld.pushCoin(this);
            }

            Vector2 pos      = new Vector2(position.X, position.Y);
            Vector2 nextStep = new Vector2(position.X + velocity.X, position.Y + velocity.Y);
            Vector2 finalPos = parentWorld.Map.reloactePosition(pos, nextStep, dimensions);

            position.X = finalPos.X;
            position.Y = finalPos.Y;

            animation_time += currentTime.ElapsedGameTime.Milliseconds / 1000f;
            current_skeleton.Animation.Apply(current_skeleton.Skeleton, animation_time, true);
        }
        public void update(Player parent, GameTime currentTime, LevelState parentWorld)
        {
            updateBullets(parentWorld, currentTime);
            if (state == WaveMotionState.Wait)
            {
                if (GameCampaign.Player_Ammunition >= 5)
                {
                    shotTime = 0.0f;
                    parent.Disable_Movement = true;
                    parent.Velocity         = Vector2.Zero;

                    float shotDirection = 0.0f;

                    switch (parent.Direction_Facing)
                    {
                    case GlobalGameConstants.Direction.Up:
                        shotDirection = (float)Math.PI / -2;
                        break;

                    case GlobalGameConstants.Direction.Down:
                        shotDirection = (float)Math.PI / 2;
                        break;

                    case GlobalGameConstants.Direction.Left:
                        shotDirection = (float)Math.PI;
                        break;

                    case GlobalGameConstants.Direction.Right:
                        shotDirection = 0.0f;
                        break;
                    }

                    Vector2 bulletPos = Vector2.Zero;

                    if (GameCampaign.Player_Right_Item == ItemType() && InputDevice2.IsPlayerButtonDown(parent.Index, InputDevice2.PlayerButton.UseItem1))
                    {
                        if (parent.Index == InputDevice2.PPG_Player.Player_1)
                        {
                            GameCampaign.Player_Ammunition -= ammo_consumption;
                        }
                        else
                        {
                            GameCampaign.Player2_Ammunition -= ammo_consumption;
                        }
                        parent.LoadAnimation.Animation = parent.LoadAnimation.Skeleton.Data.FindAnimation(parent.Direction_Facing == GlobalGameConstants.Direction.Left ? "lRayGun" : "rRayGun");
                        bulletPos = new Vector2(parent.LoadAnimation.Skeleton.FindBone(parent.Direction_Facing == GlobalGameConstants.Direction.Left ? "lGunMuzzle" : "rGunMuzzle").WorldX, parent.LoadAnimation.Skeleton.FindBone(parent.Direction_Facing == GlobalGameConstants.Direction.Left ? "lGunMuzzle" : "rGunMuzzle").WorldY);
                    }
                    else if (GameCampaign.Player_Left_Item == ItemType() && InputDevice2.IsPlayerButtonDown(parent.Index, InputDevice2.PlayerButton.UseItem2))
                    {
                        GameCampaign.Player_Ammunition -= ammo_consumption;
                        parent.LoadAnimation.Animation  = parent.LoadAnimation.Skeleton.Data.FindAnimation(parent.Direction_Facing == GlobalGameConstants.Direction.Left ? "rRayGun" : "lRayGun");
                        bulletPos = new Vector2(parent.LoadAnimation.Skeleton.FindBone(parent.Direction_Facing == GlobalGameConstants.Direction.Left ? "rGunMuzzle" : "lGunMuzzle").WorldX, parent.LoadAnimation.Skeleton.FindBone(parent.Direction_Facing == GlobalGameConstants.Direction.Left ? "rGunMuzzle" : "lGunMuzzle").WorldY);
                    }

                    if (!bullet1.active)
                    {
                        bullet1 = new WaveMotionBullet(bulletPos, shotDirection);
                    }
                    else if (!bullet2.active)
                    {
                        bullet2 = new WaveMotionBullet(bulletPos, shotDirection);
                    }
                    else if (!bullet3.active)
                    {
                        bullet3 = new WaveMotionBullet(bulletPos, shotDirection);
                    }

                    AudioLib.playSoundEffect("waveShot");

                    state = WaveMotionState.Shooting;
                    parent.Animation_Time = 0.0f;

                    parent.LoopAnimation = false;
                }
                else
                {
                    parent.State = Player.playerState.Moving;
                    return;
                }
            }
            else if (state == WaveMotionState.Shooting)
            {
                shotTime += currentTime.ElapsedGameTime.Milliseconds;

                if (shotTime > shotWaitTime)
                {
                    parent.Disable_Movement = false;
                    parent.State            = Player.playerState.Moving;

                    state = WaveMotionState.Wait;
                }
            }
        }
        private void gameLogicUpdate(Microsoft.Xna.Framework.GameTime currentTime)
        {
            if (InputDevice2.IsPlayerButtonDown(InputDevice2.PPG_Player.Player_1, InputDevice2.PlayerButton.PauseButton) && !player1Dead)
            {
                state = LoadingState.LevelPaused;
                pauseDialogMinimumTime = 0;
                pauseMenuItem          = 0;
                AudioLib.playSoundEffect("monitorOpening");
            }

            if (GameCampaign.Player_Ammunition < 0)
            {
                GameCampaign.Player_Ammunition = 0;
            }
            if (GameCampaign.Player2_Ammunition < 0)
            {
                GameCampaign.Player2_Ammunition = 0;
            }

            if (GameCampaign.Player_Ammunition > 100)
            {
                GameCampaign.Player_Ammunition = 100;
            }
            if (GameCampaign.Player2_Ammunition > 100)
            {
                GameCampaign.Player2_Ammunition = 100;
            }

            if (messageQueueState == PushMessageQueueState.Wait)
            {
                if (pushMessageQueue.Count > 0)
                {
                    messageQueueState = PushMessageQueueState.FadeIn;
                    queueTimer        = 0;
                }
            }
            else if (messageQueueState == PushMessageQueueState.ShowMessage)
            {
                queueTimer += currentTime.ElapsedGameTime.Milliseconds;

                if (queueTimer > 1000f + (25 * pushMessageQueue.Peek().Length))
                {
                    messageQueueState = PushMessageQueueState.FadeOut;
                    queueTimer        = 0;
                }
            }
            else if (messageQueueState == PushMessageQueueState.FadeIn)
            {
                queueTimer += currentTime.ElapsedGameTime.Milliseconds;

                if (queueTimer > 200f)
                {
                    messageQueueState = PushMessageQueueState.ShowMessage;
                    queueTimer        = 0;
                }
            }
            else if (messageQueueState == PushMessageQueueState.FadeOut)
            {
                queueTimer += currentTime.ElapsedGameTime.Milliseconds;

                if (queueTimer > 200f)
                {
                    messageQueueState = PushMessageQueueState.Wait;
                    queueTimer        = 0;
                    pushMessageQueue.Dequeue();
                }
            }

            for (int i = 0; i < entityList.Count; i++)
            {
                if (Vector2.Distance(cameraFocus.CenterPoint, entityList[i].CenterPoint) < 800 || entityList[i] is Player)
                {
                    entityList[i].update(currentTime);
                }
            }

            elapsedLevelTime += currentTime.ElapsedGameTime.Milliseconds;

            particleSet.update(currentTime);

#if WINDOWS
            entityList.RemoveAll(en => en.Remove_From_List == true);
#elif XBOX
            XboxTools.RemoveAll(entityList, XboxTools.IsEntityToBeRemoved);
            XboxTools.RemoveAll(acidSpitters, XboxTools.IsEntityToBeRemoved);
#endif

            if (cameraFocus != null)
            {
                int pointX = (int)cameraFocus.CenterPoint.X;
                int pointY = (int)cameraFocus.CenterPoint.Y;

                camera = Matrix.CreateTranslation(new Vector3((pointX * -1) + (GlobalGameConstants.GameResolutionWidth / 2), (pointY * -1) + (GlobalGameConstants.GameResolutionHeight / 2), 0.0f));
                //camera = Matrix.CreateScale(0.1f);
            }

            gui.update(currentTime);

            if (player1Dead)
            {
                fadeOutTime += currentTime.ElapsedGameTime.Milliseconds;

                gui.BlackFadeOverlay = fadeOutTime / fadeOutDuration;

                if (fadeOutTime >= fadeOutDuration)
                {
                    BackGroundAudio.stopAllSongs();
                    isComplete = true;
                }
            }

            if (endFlagReached)
            {
                BackGroundAudio.stopAllSongs();
                isComplete = true;
            }

#if DEBUG
            if (InputDevice2.IsAnyControllerButtonDown(InputDevice2.PlayerButton.SwitchItem2) != InputDevice2.PlayerPad.NoPad)
            {
                showStats = true;
            }
            else
            {
                showStats = false;
            }
#endif
        }
        public override void knockBack(Vector2 direction, float magnitude, int damage, Entity attacker)
        {
            if (death == false)
            {
                if (molotovState == MolotovState.KnockedBack)
                {
                    return;
                }

                if (molotovState == MolotovState.Dying)
                {
                    parentWorld.Particles.pushBloodParticle(CenterPoint);
                    parentWorld.Particles.pushBloodParticle(CenterPoint);
                    parentWorld.Particles.pushBloodParticle(CenterPoint);

                    return;
                }

                direction.Normalize();
                velocity = direction * magnitude;

                health -= damage;

                if (health < 1 && !death && attacker != null & attacker is Player)
                {
                    GameCampaign.AlterAllegiance(0.015f);
                }

                knockBackTime = 0.0f;

                animation_time = 0;

                parentWorld.Particles.pushBloodParticle(CenterPoint);
                parentWorld.Particles.pushBloodParticle(CenterPoint);
                parentWorld.Particles.pushBloodParticle(CenterPoint);

                AudioLib.playSoundEffect("fleshyKnockBack");

                if (health > 0)
                {
                    molotovState = MolotovState.KnockedBack;
                }
                else
                {
                    molotovState = MolotovState.Dying;

                    death = true;

                    //parentWorld.pushCoin(CenterPoint, Coin.DropItemType.CoinDrop, (int)Coin.CoinValue.Laurier);
                    //parentWorld.pushCoin(CenterPoint, Coin.DropItemType.CoinDrop, (int)Coin.CoinValue.MacDonald);

                    dimensions /= 8;

                    directionAnims[(int)direction_facing].Animation = directionAnims[(int)direction_facing].Skeleton.Data.FindAnimation(deathAnims[Game1.rand.Next() % 3]);
                    parentWorld.pushCoin(this);
                }

                if (attacker == null)
                {
                    return;
                }
                else if (attacker.Enemy_Type != enemy_type && attacker.Enemy_Type != EnemyType.NoType)
                {
                    entity_found = attacker;
                    enemy_found  = true;
                }
            }
        }
        private void pausedUpdate(Microsoft.Xna.Framework.GameTime currentTime)
        {
            pauseDialogMinimumTime += currentTime.ElapsedGameTime.Milliseconds;

            if (!player1DownPressed && InputDevice2.IsPlayerButtonDown(InputDevice2.PPG_Player.Player_1, InputDevice2.PlayerButton.DownDirection))
            {
                player1DownPressed = true;
            }
            else if (player1DownPressed && !InputDevice2.IsPlayerButtonDown(InputDevice2.PPG_Player.Player_1, InputDevice2.PlayerButton.DownDirection))
            {
                player1DownPressed = false;

                pauseMenuItem = (pauseMenuItem + 1) % 2;
                AudioLib.playSoundEffect("menuSelect");
            }

            if (!player1UpPressed && InputDevice2.IsPlayerButtonDown(InputDevice2.PPG_Player.Player_1, InputDevice2.PlayerButton.UpDirection))
            {
                player1UpPressed = true;
            }
            else if (player1UpPressed && !InputDevice2.IsPlayerButtonDown(InputDevice2.PPG_Player.Player_1, InputDevice2.PlayerButton.UpDirection))
            {
                player1UpPressed = false;

                pauseMenuItem--;
                if (pauseMenuItem < 0)
                {
                    pauseMenuItem = 1;
                }
                AudioLib.playSoundEffect("menuSelect");
            }

            if (!player1ConfirmPressed && InputDevice2.IsPlayerButtonDown(InputDevice2.PPG_Player.Player_1, InputDevice2.PlayerButton.Confirm))
            {
                player1ConfirmPressed = true;
            }
            else if (player1ConfirmPressed && !InputDevice2.IsPlayerButtonDown(InputDevice2.PPG_Player.Player_1, InputDevice2.PlayerButton.Confirm))
            {
                player1ConfirmPressed = false;

                if (pauseMenuItem == 0)
                {
                    state = LoadingState.LevelRunning;
                }
                else if (pauseMenuItem == 1)
                {
                    returnToTitle = true;

                    isComplete = true;
                }
            }

            if (!pauseButtonDown && InputDevice2.IsPlayerButtonDown(InputDevice2.PPG_Player.Player_1, InputDevice2.PlayerButton.PauseButton))
            {
                pauseButtonDown = true;
            }
            else if (pauseButtonDown && !InputDevice2.IsPlayerButtonDown(InputDevice2.PPG_Player.Player_1, InputDevice2.PlayerButton.PauseButton))
            {
                pauseButtonDown = false;

                if (pauseDialogMinimumTime > 300)
                {
                    state = LoadingState.LevelRunning;
                }
            }
        }
        public override void update(GameTime currentTime)
        {
            animation_time      += currentTime.ElapsedGameTime.Milliseconds;
            deadCushySoundTimer += currentTime.ElapsedGameTime.Milliseconds;


            if (guardState == PatrolGuardState.InvalidState)
            {
                throw new Exception("Patrol Guard went into invalid state");
            }
            else if (guardState == PatrolGuardState.MoveWait)
            {
                moveWaitTimer += currentTime.ElapsedGameTime.Milliseconds;

                if (moveWaitStepping)
                {
                    switch (direction_facing)
                    {
                    case GlobalGameConstants.Direction.Up:
                        velocity = new Vector2(0.0f, -patrolMoveSpeed);
                        break;

                    case GlobalGameConstants.Direction.Down:
                        velocity = new Vector2(0.0f, patrolMoveSpeed);
                        break;

                    case GlobalGameConstants.Direction.Left:
                        velocity = new Vector2(-patrolMoveSpeed, 0.0f);
                        break;

                    case GlobalGameConstants.Direction.Right:
                        velocity = new Vector2(patrolMoveSpeed, 0.0f);
                        break;
                    }

                    directionAnims[(int)direction_facing].Animation = directionAnims[(int)direction_facing].Skeleton.Data.FindAnimation("run");
                }
                else
                {
                    velocity = Vector2.Zero;

                    directionAnims[(int)direction_facing].Animation = directionAnims[(int)direction_facing].Skeleton.Data.FindAnimation("idle");
                }

                if (moveWaitTimer > (moveWaitStepping ? moveStepTime : moveStepWaitTime))
                {
                    moveWaitStepping = !moveWaitStepping;
                    moveWaitTimer    = 0.0f;

                    if (moveWaitStepping)
                    {
                        direction_facing = (GlobalGameConstants.Direction)(((int)direction_facing + ((Game1.rand.Next() % 3) - 1) + 4) % 4);
                    }
                }

                if (target == null)
                {
                    sightBox        = new GunBullet();
                    sightBox.hitbox = new Vector2(100, 100);
                    switch (direction_facing)
                    {
                    case GlobalGameConstants.Direction.Down:
                        sightBox.position.X = CenterPoint.X - 50;
                        sightBox.position.Y = position.Y + dimensions.Y;
                        sightBox.hitbox.Y   = 150;
                        break;

                    case GlobalGameConstants.Direction.Up:
                        sightBox.position.X = CenterPoint.X - 50;
                        sightBox.position.Y = position.Y - 120;
                        sightBox.hitbox.Y   = 150;
                        break;

                    case GlobalGameConstants.Direction.Right:
                        sightBox.position.X = position.X + dimensions.X;
                        sightBox.position.Y = CenterPoint.Y - 50;
                        sightBox.hitbox.X   = 120;
                        break;

                    case GlobalGameConstants.Direction.Left:
                        sightBox.position.X = position.X - 120;
                        sightBox.position.Y = CenterPoint.Y - 50;
                        sightBox.hitbox.X   = 120;
                        break;
                    }

                    for (int it = 0; it < parentWorld.EntityList.Count; it++)
                    {
                        if (parentWorld.EntityList[it].Enemy_Type == Entity.EnemyType.Guard || parentWorld.EntityList[it] is Coin || parentWorld.EntityList[it] is Pickup || parentWorld.EntityList[it] is BetaEndLevelFag)
                        {
                            continue;
                        }

                        if (Vector2.Distance(parentWorld.EntityList[it].CenterPoint, chunkCenter) > 1000)
                        {
                            continue;
                        }

                        if (Vector2.Distance(parentWorld.EntityList[it].CenterPoint, CenterPoint) > GlobalGameConstants.TileSize.X * 10)
                        {
                            continue;
                        }

                        if (!sightBox.hitTestBullet(parentWorld.EntityList[it]))
                        {
                            continue;
                        }

                        if (parentWorld.EntityList[it].Enemy_Type != enemy_type || parentWorld.EntityList[it].Enemy_Type != EnemyType.NoType)
                        {
                            if (GameCampaign.PlayerAllegiance > 0.7f && parentWorld.EntityList[it] is Player)
                            {
                                continue;
                            }
                            else
                            {
                                target = parentWorld.EntityList[it];
                            }
                        }

                        else if (parentWorld.EntityList[it] is ShopKeeper)
                        {
                            target = parentWorld.EntityList[it];
                        }
                    }

                    if (target != null)
                    {
                        chaseWaitTime = 0f;
                        guardState    = PatrolGuardState.Chase;
                    }
                }
                else
                {
                    target = null;
                }

                if (Vector2.Distance(CenterPoint, chunkCenter) > 1000)
                {
                    guardState = PatrolGuardState.RetreatToCenter;
                }
            }
            else if (guardState == PatrolGuardState.RetreatToCenter)
            {
                retreatTimer += currentTime.ElapsedGameTime.Milliseconds;

                if (Vector2.Distance(CenterPoint, chunkCenter) < 350 || retreatTimer > retreatMaxTime)
                {
                    guardState   = PatrolGuardState.MoveWait;
                    retreatTimer = 0;
                    return;
                }

                double theta = Math.Atan2(CenterPoint.Y - chunkCenter.Y, CenterPoint.X - chunkCenter.X);

                if (theta < Math.PI / 4 || theta > (Math.PI * 2) - (Math.PI / 4))
                {
                    direction_facing = GlobalGameConstants.Direction.Down;
                }
                else if (theta > Math.PI / 4 && theta < Math.PI - (Math.PI / 4))
                {
                    direction_facing = GlobalGameConstants.Direction.Left;
                }
                else if (theta > Math.PI - (Math.PI / 4) / 4 && theta < Math.PI + (Math.PI / 4))
                {
                    direction_facing = GlobalGameConstants.Direction.Right;
                }
                else if (theta > Math.PI + (Math.PI / 4) / 4 && theta < (Math.PI * 2) - (Math.PI / 4))
                {
                    direction_facing = GlobalGameConstants.Direction.Up;
                }

                velocity = -patrolMoveSpeed * new Vector2((float)Math.Cos(theta), (float)Math.Sin(theta));

                directionAnims[(int)direction_facing].Animation = directionAnims[(int)direction_facing].Skeleton.Data.FindAnimation("run");
            }
            else if (guardState == PatrolGuardState.Chase)
            {
                //this employs short-circut evaluation for safe code, which I'm not sure if is a good idea
                if (target == null || target.Remove_From_List == true || target.Death == true)
                {
                    guardState = PatrolGuardState.MoveWait;

                    target = null;

                    return;
                }

                if (Vector2.Distance(target.CenterPoint, chunkCenter) > 1000)
                {
                    guardState = PatrolGuardState.RetreatToCenter;
                    target     = null;
                    return;
                }

                double theta = Math.Atan2(target.CenterPoint.Y - CenterPoint.Y, target.CenterPoint.X - CenterPoint.X);

                if (Math.Abs(Math.Sin(theta)) > Math.Abs(Math.Cos(theta)))
                {
                    if (Math.Sin(theta) < 0)
                    {
                        direction_facing = GlobalGameConstants.Direction.Up;
                    }
                    else
                    {
                        direction_facing = GlobalGameConstants.Direction.Down;
                    }
                }
                else
                {
                    if (Math.Cos(theta) < 0)
                    {
                        direction_facing = GlobalGameConstants.Direction.Left;
                    }
                    else
                    {
                        direction_facing = GlobalGameConstants.Direction.Right;
                    }
                }

                //approach player, but keep a distance
                float dist = Vector2.Distance(CenterPoint, target.CenterPoint);
                if (dist < GlobalGameConstants.TileSize.X * 3)
                {
                    //chaseWaitTime -= currentTime.ElapsedGameTime.Milliseconds;

                    velocity = -patrolChaseSpeed * new Vector2((float)Math.Cos(theta), (float)Math.Sin(theta));

                    if (direction_facing == GlobalGameConstants.Direction.Up || direction_facing == GlobalGameConstants.Direction.Down)
                    {
                        if (Math.Abs(CenterPoint.X - target.CenterPoint.X) > 10.0f)
                        {
                            if (CenterPoint.X < target.CenterPoint.X)
                            {
                                velocity.X += patrolChaseSpeed / 8;
                            }
                            else if (CenterPoint.X > target.CenterPoint.X)
                            {
                                velocity.X -= patrolChaseSpeed / 8;
                            }
                        }
                    }

                    if (direction_facing == GlobalGameConstants.Direction.Left || direction_facing == GlobalGameConstants.Direction.Right)
                    {
                        if (Math.Abs(CenterPoint.Y - target.CenterPoint.Y) > 10.0f)
                        {
                            if (CenterPoint.Y < target.CenterPoint.Y)
                            {
                                velocity.Y += patrolChaseSpeed / 8;
                            }
                            else if (CenterPoint.Y > target.CenterPoint.Y)
                            {
                                velocity.Y -= patrolChaseSpeed / 8;
                            }
                        }
                    }
                }
                else if (dist > GlobalGameConstants.TileSize.X * 4)
                {
                    //chaseWaitTime -= currentTime.ElapsedGameTime.Milliseconds;

                    velocity = patrolChaseSpeed * new Vector2((float)Math.Cos(theta), (float)Math.Sin(theta));

                    if (direction_facing == GlobalGameConstants.Direction.Up || direction_facing == GlobalGameConstants.Direction.Down)
                    {
                        if (Math.Abs(CenterPoint.X - target.CenterPoint.X) > 10.0f)
                        {
                            if (CenterPoint.X < target.CenterPoint.X)
                            {
                                velocity.X += patrolChaseSpeed / 8;
                            }
                            else if (CenterPoint.X > target.CenterPoint.X)
                            {
                                velocity.X -= patrolChaseSpeed / 8;
                            }
                        }
                    }

                    if (direction_facing == GlobalGameConstants.Direction.Left || direction_facing == GlobalGameConstants.Direction.Right)
                    {
                        if (Math.Abs(CenterPoint.Y - target.CenterPoint.Y) > 10.0f)
                        {
                            if (CenterPoint.Y < target.CenterPoint.Y)
                            {
                                velocity.Y += patrolChaseSpeed / 8;
                            }
                            else if (CenterPoint.Y > target.CenterPoint.Y)
                            {
                                velocity.Y -= patrolChaseSpeed / 8;
                            }
                        }
                    }
                }
                else
                {
                    chaseWaitTime += currentTime.ElapsedGameTime.Milliseconds;

                    velocity = Vector2.Zero;

                    if (chaseWaitTime > chaseWaitDuration)
                    {
                        chaseWaitTime  = 0.0f;
                        guardState     = PatrolGuardState.WindUp;
                        animation_time = 0.0f;
                    }
                }

                if (chaseWaitTime < 0)
                {
                    chaseWaitTime = 0f;
                }

                directionAnims[(int)direction_facing].Animation = directionAnims[(int)direction_facing].Skeleton.Data.FindAnimation("chase");
            }
            else if (guardState == PatrolGuardState.WindUp)
            {
                velocity = Vector2.Zero;

                windUpTime += currentTime.ElapsedGameTime.Milliseconds;

                if (windUpTime > windUpDuration)
                {
                    windUpTime     = 0.0f;
                    animation_time = 0.0f;
                    guardState     = PatrolGuardState.Shooting;

                    for (int i = 0; i < bulletSupply; i++)
                    {
                        if (!(bullets[i].active))
                        {
                            AudioLib.playSoundEffect("pistolTEST");
                            parentWorld.Particles.pushBulletCasing(new Vector2(directionAnims[(int)direction_facing].Skeleton.FindBone("gun").WorldX, directionAnims[(int)direction_facing].Skeleton.FindBone("gun").WorldY));
                            Vector2 muzzleLocation = new Vector2(directionAnims[(int)direction_facing].Skeleton.FindBone("muzzle").WorldX, directionAnims[(int)direction_facing].Skeleton.FindBone("muzzle").WorldY);
                            bullets[i] = new GunBullet(muzzleLocation, direction_facing, this);

                            parentWorld.Particles.pushPistolFlash(muzzleLocation, Color.White, direction_facing);

                            break;
                        }
                    }
                }

                directionAnims[(int)direction_facing].Animation = directionAnims[(int)direction_facing].Skeleton.Data.FindAnimation("windUp");
            }
            else if (guardState == PatrolGuardState.Shooting)
            {
                windUpTime += currentTime.ElapsedGameTime.Milliseconds;

                directionAnims[(int)direction_facing].Animation = directionAnims[(int)direction_facing].Skeleton.Data.FindAnimation("attack");

                if (windUpTime > windUpDuration)
                {
                    windUpTime     = 0.0f;
                    animation_time = 0.0f;
                    guardState     = PatrolGuardState.Chase;

                    directionAnims[(int)direction_facing].Animation = directionAnims[(int)direction_facing].Skeleton.Data.FindAnimation("chase");
                }
            }
            else if (guardState == PatrolGuardState.KnockBack)
            {
                if (health < 0)
                {
                    remove_from_list = true;
                    return;
                }

                directionAnims[(int)direction_facing].Animation = directionAnims[(int)direction_facing].Skeleton.Data.FindAnimation("hurt");

                knockBackTime += currentTime.ElapsedGameTime.Milliseconds;

                if (knockBackTime > knockBackDuration)
                {
                    //target = null;

                    guardState = PatrolGuardState.Chase;
                }
            }
            else if (guardState == PatrolGuardState.Dying)
            {
                directionAnims[(int)direction_facing].Animation = directionAnims[(int)direction_facing].Skeleton.Data.FindAnimation("die");

                death = true;

                velocity = Vector2.Zero;
            }

            Vector2 newPos   = position + (currentTime.ElapsedGameTime.Milliseconds * velocity);
            Vector2 finalPos = parentWorld.Map.reloactePosition(position, newPos, dimensions);

            position = finalPos;

            for (int i = 0; i < bulletSupply; i++)
            {
                bullets[i].update(parentWorld, currentTime);
            }

            directionAnims[(int)direction_facing].Animation.Apply(directionAnims[(int)direction_facing].Skeleton, animation_time / 1000f, (guardState == PatrolGuardState.MoveWait || guardState == PatrolGuardState.Chase || guardState == PatrolGuardState.RetreatToCenter) ? true : false);
        }
        public void pushCoin(Entity parent)
        {
            int total_coin_count = 0;
            int value            = 0;

            Coin.DropItemType drop_type = Coin.DropItemType.CoinDrop;

            if (parent.Enemy_Type == GameCampaign.currentContract.killTarget)
            {
                particleSet.pushContractParticle(parent.CenterPoint);
                particleSet.pushContractParticle(parent.CenterPoint);
                particleSet.pushContractParticle(parent.CenterPoint);
                particleSet.pushContractParticle(parent.CenterPoint);
                particleSet.pushContractParticle(parent.CenterPoint);
                AudioLib.playSoundEffect("chaching");

                total_coin_count = GameCampaign.currentContract.goldPerKill;
                drop_type        = Coin.DropItemType.CoinDrop;

                while (total_coin_count != 0)
                {
                    double coin_value = Game1.rand.NextDouble();

                    if (coin_value < 0.20)
                    {
                        if ((int)Coin.CoinValue.Borden <= total_coin_count)
                        {
                            total_coin_count -= (int)Coin.CoinValue.Borden;
                            value             = (int)Coin.CoinValue.Borden;
                        }
                        else
                        {
                            continue;
                        }
                    }
                    else if (coin_value < 0.35)
                    {
                        if ((int)Coin.CoinValue.Mackenzie <= total_coin_count)
                        {
                            value             = (int)Coin.CoinValue.Mackenzie;
                            total_coin_count -= value;
                        }
                        else
                        {
                            continue;
                        }
                    }
                    else if (coin_value < 0.45)
                    {
                        if ((int)Coin.CoinValue.Elizabeth <= total_coin_count)
                        {
                            value             = (int)Coin.CoinValue.Elizabeth;
                            total_coin_count -= value;
                        }
                        else
                        {
                            continue;
                        }
                    }
                    else if (coin_value < 0.55)
                    {
                        if ((int)Coin.CoinValue.MacDonald <= total_coin_count)
                        {
                            value             = (int)Coin.CoinValue.MacDonald;
                            total_coin_count -= value;
                        }
                        else
                        {
                            continue;
                        }
                    }
                    else if (coin_value < 0.70)
                    {
                        if ((int)Coin.CoinValue.Laurier <= total_coin_count)
                        {
                            value             = (int)Coin.CoinValue.Laurier;
                            total_coin_count -= value;
                        }
                        else
                        {
                            continue;
                        }
                    }
                    else if (coin_value < 0.85)
                    {
                        if ((int)Coin.CoinValue.Twoonie <= total_coin_count)
                        {
                            value             = (int)Coin.CoinValue.Twoonie;
                            total_coin_count -= value;
                        }
                        else
                        {
                            continue;
                        }
                    }
                    else if (coin_value <= 1.0)
                    {
                        if ((int)Coin.CoinValue.Loonie <= total_coin_count)
                        {
                            value             = (int)Coin.CoinValue.Loonie;
                            total_coin_count -= value;
                        }
                        else
                        {
                            continue;
                        }
                    }

                    int lastAt = freeCoinIndex;

                    do
                    {
                        freeCoinIndex = (freeCoinIndex + 1) % coinPoolSize;

                        if (coinPool[freeCoinIndex].State == Coin.DropState.Inactive)
                        {
                            coinPool[freeCoinIndex].activate(parent.CenterPoint, drop_type, value);
                            break;
                        }
                    }while (freeCoinIndex != lastAt);
                }
            }
            else
            {
                int number_of_items_drop = parent.numberDropItems;
                while (number_of_items_drop > 0)
                {
                    double drop_type_value = Game1.rand.NextDouble();

                    if (drop_type_value < parent.probItemDrop)
                    {
                        double health_or_ammo = Game1.rand.NextDouble();
                        drop_type_value = Game1.rand.NextDouble();
                        if (health_or_ammo < 0.5)
                        {
                            drop_type = Coin.DropItemType.MedDrop;
                            if (drop_type_value < 0.10)
                            {
                                value = (int)Coin.MedValue.fullPack;
                            }
                            else if (drop_type_value < 0.25)
                            {
                                value = (int)Coin.MedValue.largePack;
                            }
                            else if (drop_type_value < 0.50)
                            {
                                value = (int)Coin.MedValue.mediumPack;
                            }
                            else if (drop_type_value <= 1.0)
                            {
                                value = (int)Coin.MedValue.smallPack;
                            }
                        }
                        else
                        {
                            drop_type = Coin.DropItemType.AmmoDrop;
                            if (drop_type_value < 0.10)
                            {
                                value = (int)Coin.AmmoValue.fullAmmo;
                            }
                            else if (drop_type_value < 0.25)
                            {
                                value = (int)Coin.AmmoValue.largeAmmo;
                            }
                            else if (drop_type_value < 0.50)
                            {
                                value = (int)Coin.AmmoValue.mediumAmmo;
                            }
                            else if (drop_type_value <= 1.0)
                            {
                                value = (int)Coin.AmmoValue.smallAmmo;
                            }
                        }
                    }
                    else
                    {
                        drop_type       = Coin.DropItemType.CoinDrop;
                        drop_type_value = Game1.rand.NextDouble();
                        if (drop_type_value < 0.1)
                        {
                            value = (int)Coin.CoinValue.Borden;
                        }
                        else if (drop_type_value < 0.2)
                        {
                            value = (int)Coin.CoinValue.Mackenzie;
                        }
                        else if (drop_type_value < 0.35)
                        {
                            value = (int)Coin.CoinValue.Elizabeth;
                        }
                        else if (drop_type_value < 0.50)
                        {
                            value = (int)Coin.CoinValue.MacDonald;
                        }
                        else if (drop_type_value < 0.65)
                        {
                            value = (int)Coin.CoinValue.Laurier;
                        }
                        else if (drop_type_value < 0.80)
                        {
                            value = (int)Coin.CoinValue.Twoonie;
                        }
                        else if (drop_type_value <= 1.0)
                        {
                            value = (int)Coin.CoinValue.Loonie;
                        }
                    }

                    int lastAt = freeCoinIndex;

                    do
                    {
                        freeCoinIndex = (freeCoinIndex + 1) % coinPoolSize;

                        if (coinPool[freeCoinIndex].State == Coin.DropState.Inactive)
                        {
                            coinPool[freeCoinIndex].activate(parent.CenterPoint, drop_type, value);
                            break;
                        }
                    }while (freeCoinIndex != lastAt);

                    number_of_items_drop--;
                }
            }
        }
        public override void knockBack(Vector2 direction, float magnitude, int damage, Entity attacker)
        {
            if (!death)
            {
                if (disable_movement_time == 0.0)
                {
                    if (state != ChargerState.windUp && state != ChargerState.charge)
                    {
                        disable_movement = true;
                        animation_time   = 0;

                        AudioLib.playSoundEffect("fleshyKnockBack");

                        if (Math.Abs(direction.X) > (Math.Abs(direction.Y)))
                        {
                            if (direction.X < 0)
                            {
                                velocity = new Vector2(-5.51f * magnitude, direction.Y / 100 * magnitude);
                            }
                            else
                            {
                                velocity = new Vector2(5.51f * magnitude, direction.Y / 100 * magnitude);
                            }
                        }
                        else
                        {
                            if (direction.Y < 0)
                            {
                                velocity = new Vector2(direction.X / 100f * magnitude, -5.51f * magnitude);
                            }
                            else
                            {
                                velocity = new Vector2((direction.X / 100f) * magnitude, 5.51f * magnitude);
                            }
                        }
                    }

                    enemy_life = enemy_life - damage;

                    if (enemy_life < 1 && !death)
                    {
                        if (attacker != null & attacker is Player)
                        {
                            GameCampaign.AlterAllegiance(0.1f);
                        }
                    }
                }

                if (attacker == null)
                {
                    return;
                }
                if (attacker.Enemy_Type != enemy_type && attacker.Enemy_Type != EnemyType.NoType)
                {
                    enemy_found  = true;
                    entity_found = attacker;
                    switch (attacker.Direction_Facing)
                    {
                    case GlobalGameConstants.Direction.Right:
                        direction_facing = GlobalGameConstants.Direction.Left;
                        break;

                    case GlobalGameConstants.Direction.Left:
                        direction_facing = GlobalGameConstants.Direction.Right;
                        break;

                    case GlobalGameConstants.Direction.Up:
                        direction_facing = GlobalGameConstants.Direction.Down;
                        break;

                    default:
                        direction_facing = GlobalGameConstants.Direction.Up;
                        break;
                    }
                }
            }
            parentWorld.Particles.pushBloodParticle(CenterPoint);
            parentWorld.Particles.pushBloodParticle(CenterPoint);
            parentWorld.Particles.pushBloodParticle(CenterPoint);
        }
        protected override void doUpdate(Microsoft.Xna.Framework.GameTime currentTime)
        {
            CampaignLobbyState.lineOffset += (currentTime.ElapsedGameTime.Milliseconds * lineMoveSpeed);
            if (CampaignLobbyState.lineOffset > 16.0f)
            {
                CampaignLobbyState.lineOffset -= 16.0f;
            }

            if (!openingSoundMade)
            {
                AudioLib.playSoundEffect("monitorOpening");
                openingSoundMade = true;
            }

            if (state == LevelSelectStateState.AnimateIn && cursorAnimationTime > 500f)
            {
                state = LevelSelectStateState.Idle;
            }

            if (state == LevelSelectStateState.Idle)
            {
                if (InputDevice2.IsPlayerButtonDown(InputDevice2.PPG_Player.Player_1, InputDevice2.PlayerButton.DownDirection) && !downPressed)
                {
                    downPressed = true;
                }
                else if (!InputDevice2.IsPlayerButtonDown(InputDevice2.PPG_Player.Player_1, InputDevice2.PlayerButton.DownDirection) && downPressed)
                {
                    downPressed = false;

                    if (selectedLevelY < GameCampaign.levelMap.GetLength(1) - 1 && GameCampaign.levelMap[selectedLevelX, selectedLevelY + 1].visible && selectedLevelY - GameCampaign.PlayerFloorHeight < 1)
                    {
                        selectedLevelY++;
                        AudioLib.playSoundEffect(menuBlipSound);
                    }
                }

                if (InputDevice2.IsPlayerButtonDown(InputDevice2.PPG_Player.Player_1, InputDevice2.PlayerButton.UpDirection) && !upPressed)
                {
                    upPressed = true;
                }
                else if (!InputDevice2.IsPlayerButtonDown(InputDevice2.PPG_Player.Player_1, InputDevice2.PlayerButton.UpDirection) && upPressed)
                {
                    upPressed = false;

                    if (selectedLevelY > 0 && GameCampaign.levelMap[selectedLevelX, selectedLevelY - 1].visible && selectedLevelY - GameCampaign.PlayerFloorHeight > -1)
                    {
                        selectedLevelY--;
                        AudioLib.playSoundEffect(menuBlipSound);
                    }
                }

                selectedLevelX = GameCampaign.PlayerLevelProgress + 1;

                if (InputDevice2.IsPlayerButtonDown(InputDevice2.PPG_Player.Player_1, InputDevice2.PlayerButton.Confirm) && !confirmPressed)
                {
                    confirmPressed = true;
                }
                else if (!InputDevice2.IsPlayerButtonDown(InputDevice2.PPG_Player.Player_1, InputDevice2.PlayerButton.Confirm) && confirmPressed)
                {
                    confirmPressed = false;

                    GameCampaign.CurrentAlienRate    = GameCampaign.levelMap[selectedLevelX, selectedLevelY].alienRates;
                    GameCampaign.CurrentGuardRate    = GameCampaign.levelMap[selectedLevelX, selectedLevelY].guardRates;
                    GameCampaign.CurrentPrisonerRate = GameCampaign.levelMap[selectedLevelX, selectedLevelY].prisonerRates;

                    GameCampaign.currentContract = GameCampaign.levelMap[selectedLevelX, selectedLevelY].contract;

                    GameCampaign.PlayerLevelProgress = GameCampaign.PlayerLevelProgress + 1;
                    GameCampaign.PlayerFloorHeight   = selectedLevelY;

                    GameCampaign.floorProgress[GameCampaign.PlayerLevelProgress] = GameCampaign.PlayerFloorHeight;

                    state = LevelSelectStateState.AnimateOut;

                    isComplete = true;
                }
            }

            double cursorDir = Math.Atan2(((selectedLevelY * 96) + drawMapTestOffset.Y) - cursorPosition.Y, ((selectedLevelX * 128) + drawMapTestOffset.X) - cursorPosition.X);

            cursorPosition += currentTime.ElapsedGameTime.Milliseconds * cursorVelocity * new Vector2((float)(Math.Cos(cursorDir)), (float)(Math.Sin(cursorDir)));

            if (Vector2.Distance(cursorPosition, new Vector2(((selectedLevelX * 128) + drawMapTestOffset.X), ((selectedLevelY * 96) + drawMapTestOffset.Y))) < 10f)
            {
                cursorPosition = new Vector2(((selectedLevelX * 128) + drawMapTestOffset.X), ((selectedLevelY * 96) + drawMapTestOffset.Y));
            }

            cursorAnimationTime += currentTime.ElapsedGameTime.Milliseconds;
        }
Esempio n. 25
0
        public void update(Player parent, GameTime currentTime, LevelState parentWorld)
        {
            updateBullets(parent, currentTime, parentWorld);

            if ((parent.Index == InputDevice2.PPG_Player.Player_1 ? GameCampaign.Player_Ammunition : GameCampaign.Player2_Ammunition) >= 0.5)
            {
                if ((parent.Index == InputDevice2.PPG_Player.Player_1 ? GameCampaign.Player_Right_Item : GameCampaign.Player2_Item_1) == ItemType() && InputDevice2.IsPlayerButtonDown(parent.Index, InputDevice2.PlayerButton.UseItem1))
                {
                    fireTimer += currentTime.ElapsedGameTime.Milliseconds;

                    if (fireTimer > durationBetweenShots)
                    {
                        GameCampaign.Player_Ammunition -= energy_consumption;
                        fireTimer             = 0;
                        parent.Animation_Time = 0;
                        pushBullet(new Vector2(parent.LoadAnimation.Skeleton.FindBone(parent.Direction_Facing == GlobalGameConstants.Direction.Left ? "lGunMuzzle" : "rGunMuzzle").WorldX, parent.LoadAnimation.Skeleton.FindBone(parent.Direction_Facing == GlobalGameConstants.Direction.Left ? "lGunMuzzle" : "rGunMuzzle").WorldY), (float)((int)(parent.Direction_Facing) * (Math.PI / 2)));
                        AudioLib.playSoundEffect("pistolTEST");
                        parent.LoadAnimation.Animation = parent.LoadAnimation.Skeleton.Data.FindAnimation(parent.Direction_Facing == GlobalGameConstants.Direction.Left ? "lPistol" : "rPistol");
                        parentWorld.Particles.pushBulletCasing(new Vector2(parent.LoadAnimation.Skeleton.FindBone(parent.Direction_Facing == GlobalGameConstants.Direction.Left ? "lGun" : "rGun").WorldX, parent.LoadAnimation.Skeleton.FindBone(parent.Direction_Facing == GlobalGameConstants.Direction.Left ? "lGun" : "rGun").WorldY));
                        parent.Velocity = Vector2.Zero;
                    }
                }
                else if ((parent.Index == InputDevice2.PPG_Player.Player_1 ? GameCampaign.Player_Left_Item : GameCampaign.Player2_Item_2) == ItemType() && InputDevice2.IsPlayerButtonDown(parent.Index, InputDevice2.PlayerButton.UseItem2))
                {
                    fireTimer += currentTime.ElapsedGameTime.Milliseconds;

                    if (fireTimer > durationBetweenShots)
                    {
                        if (parent.Index == InputDevice2.PPG_Player.Player_1)
                        {
                            GameCampaign.Player_Ammunition -= energy_consumption;
                        }
                        else
                        {
                            GameCampaign.Player2_Ammunition -= energy_consumption;
                        }

                        fireTimer             = 0;
                        parent.Animation_Time = 0;
                        pushBullet(new Vector2(parent.LoadAnimation.Skeleton.FindBone(parent.Direction_Facing == GlobalGameConstants.Direction.Left ? "rGunMuzzle" : "lGunMuzzle").WorldX, parent.LoadAnimation.Skeleton.FindBone(parent.Direction_Facing == GlobalGameConstants.Direction.Left ? "rGunMuzzle" : "lGunMuzzle").WorldY), (float)((int)(parent.Direction_Facing) * (Math.PI / 2)));
                        AudioLib.playSoundEffect("pistolTEST");
                        parent.LoadAnimation.Animation = parent.LoadAnimation.Skeleton.Data.FindAnimation(parent.Direction_Facing == GlobalGameConstants.Direction.Left ? "rPistol" : "lPistol");
                        parent.Velocity = Vector2.Zero;
                    }
                }
                else
                {
                    fireTimer = float.MaxValue;

                    parent.Disable_Movement = false;
                    parent.State            = Player.playerState.Moving;

                    parent.LoadAnimation.Animation = parent.LoadAnimation.Skeleton.Data.FindAnimation("idle");
                }
            }
            else
            {
                parent.State = Player.playerState.Moving;
                return;
            }
        }
Esempio n. 26
0
        public void daemonupdate(Player parent, GameTime currentTime, LevelState parentWorld)
        {
            time_explosion += currentTime.ElapsedGameTime.Milliseconds;
            bomb_timer     += currentTime.ElapsedGameTime.Milliseconds;

            switch (bomb_state)
            {
            case Bomb_State.placed:
                animation_time += currentTime.ElapsedGameTime.Milliseconds;
                if ((parent.Index == InputDevice2.PPG_Player.Player_1 ? GameCampaign.Player_Ammunition : GameCampaign.Player2_Ammunition) >= 10)
                {
                    if (bomb_timer > 1500f / time_explosion * 50.0f)
                    {
                        bomb_timer = 0.0f;
                        AudioLib.playSoundEffect("bombBeep");
                    }

                    if (time_explosion > 1500)
                    {
                        if (parent.Index == InputDevice2.PPG_Player.Player_1)
                        {
                            GameCampaign.Player_Ammunition -= ammo_consumption;
                        }
                        else
                        {
                            GameCampaign.Player2_Ammunition -= ammo_consumption;
                        }

                        hitbox         = hitbox_exploded;
                        position       = new Vector2(center_placed_bomb.X - hitbox.X / 2, center_placed_bomb.Y - hitbox.Y / 2);
                        bomb_state     = Bomb_State.exploded;
                        time_explosion = 0.0f;
                        AudioLib.playSoundEffect("testExplosion");
                        animation_time = 0.0f;
                    }
                }
                else
                {
                    parent.State = Player.playerState.Moving;
                    bomb_state   = Bomb_State.none;
                    return;
                }
                break;

            case Bomb_State.exploded:
                //where hit test is done
                if (time_explosion > 700)
                {
                    bomb_state     = Bomb_State.reset;
                    time_explosion = 0.0f;
                }
                else
                {
                    foreach (Entity en in parentWorld.EntityList)
                    {
                        if (en is Player)
                        {
                            if (hitTest(en))
                            {
                                Vector2 direction = en.CenterPoint - center_placed_bomb;

                                float bomb_knockback_power = Vector2.Distance(center_placed_bomb, en.CenterPoint) / hitbox.X;

                                if (bomb_knockback_power < 1)
                                {
                                    bomb_knockback_power = 1.0f;
                                }

                                float temp_knockback_magnitude = knockback_magnitude / bomb_knockback_power;

                                en.knockBack(direction, temp_knockback_magnitude, bomb_damage, parent);
                            }
                        }
                        else if (en is Enemy || en is ShopKeeper)
                        {
                            if (hitTest(en))
                            {
                                Vector2 direction            = en.CenterPoint - center_placed_bomb;
                                float   bomb_knockback_power = Vector2.Distance(center_placed_bomb, en.CenterPoint) / hitbox.X;

                                if (bomb_knockback_power < 1)
                                {
                                    bomb_knockback_power = 1.0f;
                                }

                                float temp_knockback_magnitude = knockback_magnitude / bomb_knockback_power;

                                en.knockBack(direction, temp_knockback_magnitude, bomb_damage);
                            }
                        }
                    }
                }
                animation_time += currentTime.ElapsedGameTime.Milliseconds;
                break;

            case Bomb_State.none:
                break;

            default:
                hitbox         = hitbox_placed;
                animation_time = 0.0f;
                break;
            }
        }
Esempio n. 27
0
        public override void update(GameTime currentTime)
        {
            if (disable_movement == true)
            {
                disable_movement_time += currentTime.ElapsedGameTime.Milliseconds;
                if (disable_movement_time > 300)
                {
                    disable_movement      = false;
                    disable_movement_time = 0.0f;
                    velocity = Vector2.Zero;
                }
            }
            else
            {
                if (leader.Death == true && (state == SquadSoldierState.Patrol || state == SquadSoldierState.MoveIntoPosition))
                {
                    state = SquadSoldierState.IndividualPatrol;
                }


                switch (state)
                {
                case SquadSoldierState.Patrol:
                    change_direction_time += currentTime.ElapsedGameTime.Milliseconds;
                    reset_state_flag       = false;
                    float distance = Vector2.Distance(Leader.CenterPoint, CenterPoint);
                    if (leader != null && death == false)
                    {
                        direction_facing = Leader.Direction_Facing;
                    }

                    switch (direction_facing)
                    {
                    case GlobalGameConstants.Direction.Up:
                        current_skeleton = walk_up;
                        break;

                    case GlobalGameConstants.Direction.Down:
                        current_skeleton = walk_down;
                        break;

                    default:
                        current_skeleton = walk_right;
                        break;
                    }

                    if (distance > 96)
                    {
                        current_skeleton.Animation = current_skeleton.Skeleton.Data.FindAnimation("run");
                        distance_from_follow_pt    = Vector2.Distance(follow_point, CenterPoint);
                        angle    = (float)(Math.Atan2(follow_point.Y - CenterPoint.Y, follow_point.X - CenterPoint.X));
                        velocity = new Vector2(distance_from_follow_pt * (float)(Math.Cos(angle)) / 100.0f, distance_from_follow_pt * (float)(Math.Sin(angle)) / 100.0f);

                        if (Math.Abs(velocity.X) > (Math.Abs(velocity.Y)))
                        {
                            //enemy facing left
                            if (velocity.X < 0)
                            {
                                velocity = new Vector2(-1.5f, velocity.Y);
                            }
                            //enemy facing right
                            else
                            {
                                velocity = new Vector2(1.5f, velocity.Y);
                            }
                        }
                        else
                        {
                            //enemy facing up
                            if (velocity.Y < 0)
                            {
                                velocity = new Vector2(velocity.X, -1.5f);
                            }
                            //enemy facing down
                            else
                            {
                                velocity = new Vector2(velocity.X, 1.5f);
                            }
                        }
                    }
                    else
                    {
                        //current_skeleton.Animation = current_skeleton.Skeleton.Data.FindAnimation("idle");
                        velocity = Vector2.Zero;
                    }

                    if (enemy_found == true)
                    {
                        state      = SquadSoldierState.MoveIntoPosition;
                        move_timer = 0.0f;
                        switch (direction_facing)
                        {
                        case GlobalGameConstants.Direction.Up:
                            current_skeleton = walk_up;
                            break;

                        case GlobalGameConstants.Direction.Down:
                            current_skeleton = walk_down;
                            break;

                        default:
                            current_skeleton = walk_right;
                            break;
                        }
                        animation_time = 0.0f;
                    }
                    break;

                case SquadSoldierState.MoveIntoPosition:
                    distance_from_follow_pt = Vector2.Distance(follow_point, CenterPoint);
                    angle = (float)(Math.Atan2(follow_point.Y - CenterPoint.Y, follow_point.X - CenterPoint.X));
                    current_skeleton.Animation = current_skeleton.Skeleton.Data.FindAnimation("run");
                    move_timer += currentTime.ElapsedGameTime.Milliseconds;

                    if ((int)distance_from_follow_pt > 5 || move_timer < 1000)
                    {
                        velocity = new Vector2(distance_from_follow_pt * (float)(Math.Cos(angle)) / 100.0f, distance_from_follow_pt * (float)(Math.Sin(angle)) / 100.0f);

                        if (Math.Abs(velocity.X) > (Math.Abs(velocity.Y)))
                        {
                            //enemy facing left
                            if (velocity.X < 0)
                            {
                                velocity = new Vector2(-2.5f, velocity.Y);
                            }
                            //enemy facing right
                            else
                            {
                                velocity = new Vector2(2.5f, velocity.Y);
                            }
                        }
                        else
                        {
                            //enemy facing up
                            if (velocity.Y < 0)
                            {
                                velocity = new Vector2(velocity.X, -2.5f);
                            }
                            //enemy facing down
                            else
                            {
                                velocity = new Vector2(velocity.X, 2.5f);
                            }
                        }
                    }
                    else
                    {
                        velocity         = Vector2.Zero;
                        state            = SquadSoldierState.WindUp;
                        direction_facing = Leader.Direction_Facing;
                        animation_time   = 0.0f;
                        move_timer       = 0.0f;
                        wind_up_timer    = 0.0f;
                    }
                    break;

                case SquadSoldierState.WindUp:
                    current_skeleton.Animation = current_skeleton.Skeleton.Data.FindAnimation("windUp");
                    wind_up_timer += currentTime.ElapsedGameTime.Milliseconds;
                    if (wind_up_timer > 300)
                    {
                        state          = SquadSoldierState.Fire;
                        animation_time = 0.0f;
                        firing_timer   = 0.0f;
                        bullet_timer   = 0.0f;
                        wind_up_timer  = 0.0f;
                    }
                    break;

                case SquadSoldierState.Fire:
                    switch (direction_facing)
                    {
                    case GlobalGameConstants.Direction.Up:
                        current_skeleton = walk_up;
                        break;

                    case GlobalGameConstants.Direction.Down:
                        current_skeleton = walk_down;
                        break;

                    default:
                        current_skeleton = walk_right;
                        break;
                    }
                    current_skeleton.Animation = current_skeleton.Skeleton.Data.FindAnimation("attack");
                    bullet_timer += currentTime.ElapsedGameTime.Milliseconds;
                    firing_timer += currentTime.ElapsedGameTime.Milliseconds;
                    angle         = (float)Math.Atan2(current_skeleton.Skeleton.FindBone("muzzle").WorldY - current_skeleton.Skeleton.FindBone("gun").WorldY, current_skeleton.Skeleton.FindBone("muzzle").WorldX - current_skeleton.Skeleton.FindBone("gun").WorldX);

                    if (bullet_timer > 100)
                    {
                        for (int i = 0; i < max_bullet_count; i++)
                        {
                            if (!bullets[i].active)
                            {
                                AudioLib.playSoundEffect("machineGun");
                                parentWorld.Particles.pushBulletCasing(new Vector2(current_skeleton.Skeleton.FindBone("gun").WorldX, current_skeleton.Skeleton.FindBone("gun").WorldY));
                                bullets[i] = new SquadBullet(new Vector2(current_skeleton.Skeleton.FindBone("muzzle").WorldX, current_skeleton.Skeleton.FindBone("muzzle").WorldY), angle);

                                bullets[i].velocity = new Vector2((float)(12.0 * Math.Cos(angle)), (float)(12.0 * Math.Sin(angle)));
                                bullet_timer        = 0.0f;
                                break;
                            }
                        }
                    }

                    if (firing_timer > 3000)
                    {
                        reset_state_flag           = true;
                        enemy_found                = false;
                        firing_timer               = 0.0f;
                        bullet_timer               = 0.0f;
                        current_skeleton.Animation = current_skeleton.Skeleton.Data.FindAnimation("idle");
                        if (leader != null)
                        {
                            state = SquadSoldierState.Patrol;
                        }
                        else
                        {
                            state = SquadSoldierState.IndividualPatrol;
                        }
                    }
                    break;

                case SquadSoldierState.IndividualPatrol:
                    change_direction_time     += currentTime.ElapsedGameTime.Milliseconds;
                    current_skeleton.Animation = current_skeleton.Skeleton.Data.FindAnimation("run");

                    if (enemy_found == true)
                    {
                        state          = SquadSoldierState.WindUp;
                        velocity       = Vector2.Zero;
                        animation_time = 0.0f;
                    }
                    else
                    {
                        //checks where the player is
                        for (int i = 0; i < parentWorld.EntityList.Count; i++)
                        {
                            if (parentWorld.EntityList[i] == this || (parentWorld.EntityList[i] is Player && GameCampaign.PlayerAllegiance > 0.7))
                            {
                                continue;
                            }

                            if (parentWorld.EntityList[i].Enemy_Type != enemy_type && parentWorld.EntityList[i].Enemy_Type != EnemyType.NoType)
                            {
                                component.update(this, parentWorld.EntityList[i], currentTime, parentWorld);
                            }
                        }
                    }

                    switch (direction_facing)
                    {
                    case GlobalGameConstants.Direction.Up:
                        current_skeleton = walk_up;
                        break;

                    case GlobalGameConstants.Direction.Down:
                        current_skeleton = walk_down;
                        break;

                    default:
                        current_skeleton = walk_right;
                        break;
                    }
                    break;

                case SquadSoldierState.Dying:
                    velocity = Vector2.Zero;
                    break;

                default:
                    break;
                }
            }
            Vector2 pos      = new Vector2(position.X, position.Y);
            Vector2 nextStep = new Vector2(position.X + velocity.X, position.Y + velocity.Y);
            Vector2 finalPos = parentWorld.Map.reloactePosition(pos, nextStep, dimensions);

            position.X = finalPos.X;
            position.Y = finalPos.Y;

            animation_time += currentTime.ElapsedGameTime.Milliseconds / 1000f;
            current_skeleton.Animation.Apply(current_skeleton.Skeleton, animation_time, loop);

            for (int i = 0; i < max_bullet_count; i++)
            {
                if (bullets[i].active)
                {
                    bullets[i].update(parentWorld, currentTime, this);
                }
            }

            if (enemy_life <= 0 && death == false)
            {
                //remove_from_list = true;
                death = true;
                current_skeleton.Animation = current_skeleton.Skeleton.Data.FindAnimation(deathAnims[Game1.rand.Next() % 3]);
                loop           = false;
                animation_time = 0.0f;
                state          = SquadSoldierState.Dying;
                parentWorld.pushCoin(this);
            }
        }
        public void update(Player parent, GameTime currentTime, LevelState parentWorld)
        {
            for (int i = 0; i < laser_projectile.Count(); i++)
            {
                if (laser_projectile[i].active)
                {
                    laser_projectile[i].update(parentWorld, currentTime, parent);
                }
            }
            item_direction = parent.Direction_Facing;
            if (fire_projectile)
            {
                for (int i = 0; i < laser_projectile.Count(); i++)
                {
                    if (laser_projectile[i].active)
                    {
                        continue;
                    }
                    else
                    {
                        float bullet_angle = 0.0f;
                        if (item_direction == GlobalGameConstants.Direction.Right || item_direction == GlobalGameConstants.Direction.Left)
                        {
                            bullet_angle = 0.0f;
                        }
                        else
                        {
                            bullet_angle = (float)Math.PI / 2;
                        }

                        if ((GameCampaign.Player_Right_Item == ItemType() && InputDevice2.IsPlayerButtonDown(parent.Index, InputDevice2.PlayerButton.UseItem1)))
                        {
                            if ((parent.Index == InputDevice2.PPG_Player.Player_1 ? GameCampaign.Player_Ammunition : GameCampaign.Player2_Ammunition) >= ammo_consumption)
                            {
                                AudioLib.playSoundEffect("lazorFire");
                                laser_projectile[i] = new laserProjectile(new Vector2(parent.LoadAnimation.Skeleton.FindBone(parent.Direction_Facing == GlobalGameConstants.Direction.Left ? "lGunMuzzle" : "rGunMuzzle").WorldX, parent.LoadAnimation.Skeleton.FindBone(parent.Direction_Facing == GlobalGameConstants.Direction.Left ? "lGunMuzzle" : "rGunMuzzle").WorldY), (parent.Direction_Facing == GlobalGameConstants.Direction.Right) ? new Vector2(10, 0) : (parent.Direction_Facing == GlobalGameConstants.Direction.Left) ? new Vector2(-10, 0) : (parent.Direction_Facing == GlobalGameConstants.Direction.Up) ? new Vector2(0, -10) : new Vector2(0, 10), bullet_angle);
                                if (parent.Index == InputDevice2.PPG_Player.Player_1)
                                {
                                    GameCampaign.Player_Ammunition -= ammo_consumption;
                                }
                                else
                                {
                                    GameCampaign.Player2_Ammunition -= ammo_consumption;
                                }
                            }
                        }
                        else if ((GameCampaign.Player_Left_Item == ItemType() && InputDevice2.IsPlayerButtonDown(parent.Index, InputDevice2.PlayerButton.UseItem2)))
                        {
                            if ((parent.Index == InputDevice2.PPG_Player.Player_1 ? GameCampaign.Player_Ammunition : GameCampaign.Player2_Ammunition) >= ammo_consumption)
                            {
                                AudioLib.playSoundEffect("lazorFire");

                                laser_projectile[i] = new laserProjectile(new Vector2(parent.LoadAnimation.Skeleton.FindBone(parent.Direction_Facing == GlobalGameConstants.Direction.Left ? "rGunMuzzle" : "lGunMuzzle").WorldX, parent.LoadAnimation.Skeleton.FindBone(parent.Direction_Facing == GlobalGameConstants.Direction.Left ? "rGunMuzzle" : "lGunMuzzle").WorldY), (parent.Direction_Facing == GlobalGameConstants.Direction.Right) ? new Vector2(15, 0) : (parent.Direction_Facing == GlobalGameConstants.Direction.Left) ? new Vector2(-15, 0) : (parent.Direction_Facing == GlobalGameConstants.Direction.Up) ? new Vector2(0, -15) : new Vector2(0, 15), bullet_angle);
                                if (parent.Index == InputDevice2.PPG_Player.Player_1)
                                {
                                    GameCampaign.Player_Ammunition -= ammo_consumption;
                                }
                                else
                                {
                                    GameCampaign.Player2_Ammunition -= ammo_consumption;
                                }
                            }
                        }
                        parent.State = Player.playerState.Moving;
                        parent.LoadAnimation.Animation = parent.LoadAnimation.Skeleton.Data.FindAnimation(parent.Direction_Facing == GlobalGameConstants.Direction.Left ? "lLaser" : "rLaser");
                        fire_timer      = 0.0f;
                        fire_projectile = false;
                        return;
                    }
                }
            }
            else
            {
                parent.State = Player.playerState.Moving;
            }
        }
Esempio n. 29
0
        public override void update(GameTime currentTime)
        {
            if (bullet_number > 0)
            {
                bullet_inactive_number = 0;
                for (int i = 0; i < bullet_number; i++)
                {
                    if (bullets[i].active)
                    {
                        bullets[i].update(parentWorld, this, currentTime);
                    }
                    else
                    {
                        bullet_inactive_number++;
                    }
                }

                if (bullet_inactive_number == max_number_bullets)
                {
                    bullet_number          = 0;
                    bullet_inactive_number = 0;
                }
            }

            if (sound_alert && state == SquadLeaderState.Patrol && entity_found == null)
            {
                state = SquadLeaderState.Alert;
            }

            if (death)
            {
                velocity = Vector2.Zero;
            }

            if (death == false)
            {
                if (disable_movement == true)
                {
                    disable_movement_time += currentTime.ElapsedGameTime.Milliseconds;
                    if (disable_movement_time > 300)
                    {
                        disable_movement      = false;
                        disable_movement_time = 0.0f;
                        velocity = Vector2.Zero;
                    }
                }
                else
                {
                    switch (state)
                    {
                    case SquadLeaderState.Patrol:
                        change_direction_time     += currentTime.ElapsedGameTime.Milliseconds;
                        current_skeleton.Animation = current_skeleton.Skeleton.Data.FindAnimation("run");
                        loop = true;

                        if (enemy_found == false)
                        {
                            for (int i = 0; i < parentWorld.EntityList.Count; i++)
                            {
                                if (parentWorld.EntityList[i] == this || (parentWorld.EntityList[i] is Player && GameCampaign.PlayerAllegiance > 0.7))
                                {
                                    continue;
                                }
                                else if (parentWorld.EntityList[i].Enemy_Type != enemy_type && parentWorld.EntityList[i].Enemy_Type != EnemyType.NoType && parentWorld.EntityList[i].Death == false)
                                {
                                    component.update(this, parentWorld.EntityList[i], currentTime, parentWorld);
                                    if (enemy_found)
                                    {
                                        entity_found = parentWorld.EntityList[i];
                                        break;
                                    }
                                }
                            }
                        }
                        switch (direction_facing)
                        {
                        case GlobalGameConstants.Direction.Right:
                            follow_point_1   = new Vector2((float)(CenterPoint.X + 64 * Math.Cos(-3 * Math.PI / 4)), (float)(CenterPoint.Y + 64 * Math.Sin(-3 * Math.PI / 4)));
                            follow_point_2   = new Vector2((float)(CenterPoint.X + 64 * Math.Cos(3 * Math.PI / 4)), (float)(CenterPoint.Y + 64 * Math.Sin(3 * Math.PI / 4)));
                            current_skeleton = walk_right;
                            break;

                        case GlobalGameConstants.Direction.Left:
                            follow_point_1   = new Vector2((float)(CenterPoint.X + 64 * Math.Cos(Math.PI / 4)), (float)(CenterPoint.Y + 64 * Math.Sin(Math.PI / 4)));
                            follow_point_2   = new Vector2((float)(CenterPoint.X + 64 * Math.Cos(-1 * Math.PI / 4)), (float)(CenterPoint.Y + 64 * Math.Sin(-1 * Math.PI / 4)));
                            current_skeleton = walk_right;
                            break;

                        case GlobalGameConstants.Direction.Up:
                            follow_point_1   = new Vector2((float)(CenterPoint.X + 64 * Math.Cos(3 * Math.PI / 4)), (float)(CenterPoint.Y + 64 * Math.Sin(3 * Math.PI / 4)));
                            follow_point_2   = new Vector2((float)(CenterPoint.X + 64 * Math.Cos(Math.PI / 4)), (float)(CenterPoint.Y + 64 * Math.Sin(Math.PI / 4)));
                            current_skeleton = walk_up;
                            break;

                        default:
                            follow_point_1   = new Vector2((float)(CenterPoint.X + 64 * Math.Cos(-1 * Math.PI / 4)), (float)(CenterPoint.Y + 64 * Math.Sin(-1 * Math.PI / 4)));
                            follow_point_2   = new Vector2((float)(CenterPoint.X + 64 * Math.Cos(-3 * Math.PI / 4)), (float)(CenterPoint.Y + 64 * Math.Sin(-3 * Math.PI / 4)));
                            current_skeleton = walk_down;
                            break;
                        }
                        if (squad_mates[0] != null)
                        {
                            squad_mates[0].Follow_Point = follow_point_1;
                        }
                        if (squad_mates[1] != null)
                        {
                            squad_mates[1].Follow_Point = follow_point_2;
                        }

                        if (enemy_found)
                        {
                            if ((squad_mates[0] != null && !squad_mates[0].Death) || (squad_mates[1] != null && !squad_mates[1].Death))
                            {
                                state = SquadLeaderState.Direct;

                                switch (direction_facing)
                                {
                                case GlobalGameConstants.Direction.Right:
                                    follow_point_1.X = 128 + follow_point_1.X;
                                    follow_point_2.X = 128 + follow_point_2.X;
                                    break;

                                case GlobalGameConstants.Direction.Left:
                                    follow_point_1.X = follow_point_1.X - 128;
                                    follow_point_2.X = follow_point_2.X - 128;
                                    break;

                                case GlobalGameConstants.Direction.Up:
                                    follow_point_1.Y = follow_point_1.Y - 128;
                                    follow_point_2.Y = follow_point_2.Y - 128;
                                    break;

                                default:
                                    follow_point_1.Y = follow_point_1.Y + 128;
                                    follow_point_2.Y = follow_point_2.Y + 128;
                                    break;
                                }

                                squad_mates[0].Enemy_Found  = true;
                                squad_mates[0].Entity_Found = entity_found;
                                squad_mates[1].Enemy_Found  = true;
                                squad_mates[1].Entity_Found = entity_found;

                                velocity = Vector2.Zero;
                            }
                            else
                            {
                                state = SquadLeaderState.WindUp;
                                current_skeleton.Animation = current_skeleton.Skeleton.Data.FindAnimation("idle");
                                animation_time             = 0.0f;
                                velocity = Vector2.Zero;
                            }
                        }
                        break;

                    case SquadLeaderState.Alert:
                        current_skeleton.Animation = current_skeleton.Skeleton.Data.FindAnimation("idle");

                        alert_timer += currentTime.ElapsedGameTime.Milliseconds;

                        if (sound_alert && entity_found == null)
                        {
                            //if false then sound didn't hit a wall
                            if (!parentWorld.Map.soundInSight(this, sound_position))
                            {
                                current_skeleton.Animation = current_skeleton.Skeleton.Data.FindAnimation("run");
                                alert_timer += currentTime.ElapsedGameTime.Milliseconds;
                                for (int i = 0; i < parentWorld.EntityList.Count; i++)
                                {
                                    if (parentWorld.EntityList[i].Enemy_Type != enemy_type && parentWorld.EntityList[i].Enemy_Type != EnemyType.NoType && parentWorld.EntityList[i].Death == false)
                                    {
                                        float distance = Vector2.Distance(CenterPoint, parentWorld.EntityList[i].CenterPoint);
                                        if (distance <= range_distance)
                                        {
                                            enemy_found    = true;
                                            entity_found   = parentWorld.EntityList[i];
                                            state          = SquadLeaderState.Patrol;
                                            animation_time = 0.0f;
                                            sound_alert    = false;
                                            alert_timer    = 0.0f;
                                            windup_timer   = 0.0f;
                                            animation_time = 0.0f;
                                            velocity       = Vector2.Zero;
                                            break;
                                        }
                                    }
                                }

                                if (alert_timer > 3000 || ((int)CenterPoint.X == (int)sound_position.X && (int)CenterPoint.Y == (int)sound_position.Y))
                                {
                                    entity_found   = null;
                                    enemy_found    = false;
                                    sound_alert    = false;
                                    state          = state = SquadLeaderState.Patrol;
                                    velocity       = Vector2.Zero;
                                    animation_time = 0.0f;
                                    windup_timer   = 0.0f;
                                    animation_time = 0.0f;
                                }
                            }
                            else
                            {
                                entity_found   = null;
                                enemy_found    = false;
                                sound_alert    = false;
                                state          = SquadLeaderState.Patrol;
                                velocity       = Vector2.Zero;
                                animation_time = 0.0f;
                                windup_timer   = 0.0f;
                                animation_time = 0.0f;
                            }
                        }
                        else if (entity_found != null)
                        {
                            sound_alert = false;
                            float distance = Vector2.Distance(CenterPoint, entity_found.CenterPoint);
                            if (parentWorld.Map.enemyWithinRange(entity_found, this, range_distance) && distance < range_distance)
                            {
                                state          = SquadLeaderState.Patrol;
                                animation_time = 0.0f;
                            }
                            else
                            {
                                entity_found   = null;
                                enemy_found    = false;
                                state          = SquadLeaderState.Patrol;
                                velocity       = Vector2.Zero;
                                animation_time = 0.0f;
                                windup_timer   = 0.0f;
                                animation_time = 0.0f;
                            }
                        }
                        break;

                    case SquadLeaderState.Direct:

                        current_skeleton.Animation = current_skeleton.Skeleton.Data.FindAnimation("idle");
                        float angle = (float)(Math.Atan2(entity_found.CenterPoint.Y - CenterPoint.Y, entity_found.CenterPoint.X - CenterPoint.X));

                        if (squad_mates[0] != null)
                        {
                            squad_mates[0].Follow_Point = follow_point_1;
                        }
                        if (squad_mates[1] != null)
                        {
                            squad_mates[1].Follow_Point = follow_point_2;
                        }

                        switch (direction_facing)
                        {
                        case GlobalGameConstants.Direction.Right:
                            if (angle < -1 * Math.PI / 4)
                            {
                                squad_mates[0].Direction_Facing = GlobalGameConstants.Direction.Up;
                                squad_mates[1].Direction_Facing = GlobalGameConstants.Direction.Right;
                            }
                            else if (angle > -1 * Math.PI / 4 && angle < Math.PI / 4)
                            {
                                squad_mates[0].Direction_Facing = GlobalGameConstants.Direction.Right;
                                squad_mates[1].Direction_Facing = GlobalGameConstants.Direction.Right;
                            }
                            else if (angle > Math.PI / 4)
                            {
                                squad_mates[0].Direction_Facing = GlobalGameConstants.Direction.Right;
                                squad_mates[1].Direction_Facing = GlobalGameConstants.Direction.Down;
                            }
                            break;

                        case GlobalGameConstants.Direction.Left:
                            if (angle > -3 * Math.PI / 4 && angle < 0)
                            {
                                squad_mates[0].Direction_Facing = GlobalGameConstants.Direction.Left;
                                squad_mates[1].Direction_Facing = GlobalGameConstants.Direction.Up;
                            }
                            else if (angle > 3 * Math.PI / 4 || angle < -3 * Math.PI / 4)
                            {
                                squad_mates[0].Direction_Facing = GlobalGameConstants.Direction.Left;
                                squad_mates[1].Direction_Facing = GlobalGameConstants.Direction.Left;
                            }
                            else if (angle < 3 * Math.PI / 4 && angle > 0)
                            {
                                squad_mates[0].Direction_Facing = GlobalGameConstants.Direction.Down;
                                squad_mates[1].Direction_Facing = GlobalGameConstants.Direction.Left;
                            }
                            break;

                        case GlobalGameConstants.Direction.Up:
                            if (angle < -3 * Math.PI / 4)
                            {
                                squad_mates[0].Direction_Facing = GlobalGameConstants.Direction.Up;
                                squad_mates[1].Direction_Facing = GlobalGameConstants.Direction.Right;
                            }
                            else if (angle < -1 * Math.PI / 4 && angle > -3 * Math.PI / 4)
                            {
                                squad_mates[0].Direction_Facing = GlobalGameConstants.Direction.Up;
                                squad_mates[1].Direction_Facing = GlobalGameConstants.Direction.Up;
                            }
                            else if (angle > -1 * Math.PI / 4)
                            {
                                squad_mates[0].Direction_Facing = GlobalGameConstants.Direction.Left;
                                squad_mates[1].Direction_Facing = GlobalGameConstants.Direction.Up;
                            }
                            break;

                        default:
                            if (angle < Math.PI / 4)
                            {
                                squad_mates[0].Direction_Facing = GlobalGameConstants.Direction.Right;
                                squad_mates[1].Direction_Facing = GlobalGameConstants.Direction.Down;
                            }
                            else if (angle > Math.PI / 4 && angle < 3 * Math.PI / 4)
                            {
                                squad_mates[0].Direction_Facing = GlobalGameConstants.Direction.Down;
                                squad_mates[1].Direction_Facing = GlobalGameConstants.Direction.Down;
                            }
                            else if (angle > 3 * Math.PI / 4)
                            {
                                squad_mates[0].Direction_Facing = GlobalGameConstants.Direction.Down;
                                squad_mates[1].Direction_Facing = GlobalGameConstants.Direction.Left;
                            }
                            break;
                        }

                        if ((squad_mates[0] != null && squad_mates[1] != null && squad_mates[0].Reset_State_Flag == true && squad_mates[1].Reset_State_Flag == true) || squad_mates[0] != null && squad_mates[0].Reset_State_Flag == true || squad_mates[1] != null && squad_mates[1].Reset_State_Flag == true)
                        {
                            state = SquadLeaderState.Alert;
                        }

                        if ((squad_mates[0] != null && squad_mates[1] != null && squad_mates[0].Death == true && squad_mates[1].Death == true))
                        {
                            state = SquadLeaderState.Alert;
                        }

                        float distance_from_enemy = Vector2.Distance(position, entity_found.Position);
                        break;

                    case SquadLeaderState.WindUp:
                        windup_timer += currentTime.ElapsedGameTime.Milliseconds;
                        current_skeleton.Animation = current_skeleton.Skeleton.Data.FindAnimation("windUp");

                        if (windup_timer > 400)
                        {
                            state          = SquadLeaderState.Fight;
                            animation_time = 0.0f;
                        }
                        break;

                    case SquadLeaderState.Fight:
                        //firing bullet
                        animation_time             = 0.0f;
                        time_between_shots        += currentTime.ElapsedGameTime.Milliseconds;
                        reset_timer               += currentTime.ElapsedGameTime.Milliseconds;
                        current_skeleton.Animation = current_skeleton.Skeleton.Data.FindAnimation("idleAim");

                        if (bullet_number < max_number_bullets && time_between_shots > time_between_shots_threshold)
                        {
                            current_skeleton.Animation = current_skeleton.Skeleton.Data.FindAnimation("attack");
                            loop = false;
                            Vector2 bullet_velocity;
                            switch (direction_facing)
                            {
                            case GlobalGameConstants.Direction.Right:
                                bullet_velocity = new Vector2(10, 0);
                                break;

                            case GlobalGameConstants.Direction.Left:
                                bullet_velocity = new Vector2(-10, 0);
                                break;

                            case GlobalGameConstants.Direction.Down:
                                bullet_velocity = new Vector2(0, 10);
                                break;

                            default:
                                bullet_velocity = new Vector2(0, -10);
                                break;
                            }

                            AudioLib.playSoundEffect("magnum");
                            parentWorld.Particles.pushBulletCasing(new Vector2(current_skeleton.Skeleton.FindBone("gun").WorldX, current_skeleton.Skeleton.FindBone("gun").WorldY));
                            bullets[bullet_number] = new Bullet(new Vector2(current_skeleton.Skeleton.FindBone("muzzle").WorldX, current_skeleton.Skeleton.FindBone("muzzle").WorldY), bullet_velocity);
                            bullet_number++;
                            time_between_shots = 0.0f;
                            animation_time     = 0.0f;
                        }

                        if (reset_timer > 1000)
                        {
                            reset_timer        = 0.0f;
                            state              = SquadLeaderState.Patrol;
                            time_between_shots = 0.0f;
                            loop        = true;
                            enemy_found = false;
                            switch (direction_facing)
                            {
                            case GlobalGameConstants.Direction.Right:
                                velocity = new Vector2(1, 0);
                                break;

                            case GlobalGameConstants.Direction.Left:
                                velocity = new Vector2(-1, 0);
                                break;

                            case GlobalGameConstants.Direction.Down:
                                velocity = new Vector2(0, 1);
                                break;

                            default:
                                velocity = new Vector2(0, -1);
                                break;
                            }
                        }
                        break;

                    default:
                        break;
                    }
                }
            }

            if (squad_mates[0] != null && squad_mates[0].Death == false)
            {
                squad_mates[0].Follow_Point = follow_point_1;
            }
            if (squad_mates[1] != null && squad_mates[1].Death == false)
            {
                squad_mates[1].Follow_Point = follow_point_2;
            }

            Vector2 pos      = new Vector2(position.X, position.Y);
            Vector2 nextStep = new Vector2(position.X + velocity.X, position.Y + velocity.Y);
            Vector2 finalPos = parentWorld.Map.reloactePosition(pos, nextStep, dimensions);

            position.X = finalPos.X;
            position.Y = finalPos.Y;

            animation_time += currentTime.ElapsedGameTime.Milliseconds / 1000f;
            current_skeleton.Animation.Apply(current_skeleton.Skeleton, animation_time, loop);

            for (int i = 0; i < max_number_bullets; i++)
            {
                if (bullets[i].active == true)
                {
                    bullets[i].update(parentWorld, this, currentTime);
                }
            }

            if (enemy_life <= 0 && death == false)
            {
                current_skeleton.Animation = current_skeleton.Skeleton.Data.FindAnimation(deathAnims[Game1.rand.Next() % 3]);
                state          = SquadLeaderState.Dying;
                animation_time = 0.0f;
                loop           = false;
                death          = true;
                parentWorld.pushCoin(this);
                //remove_from_list = true;
            }
        }
Esempio n. 30
0
        public void update(Player parent, GameTime currentTime, LevelState parentWorld)
        {
            item_direction  = parent.Direction_Facing;
            parent.Velocity = Vector2.Zero;

            item_state_time += currentTime.ElapsedGameTime.Milliseconds;

            if (sword_state == Sword_State.preslash)
            {
                //sword is on the right hand side of the player, if hitboxes are different dimensions, need to adjust the position of sword.
                parent.Animation_Time = 0.0f;

                if ((parent.Index == InputDevice2.PPG_Player.Player_1 ? GameCampaign.Player_Right_Item : GameCampaign.Player2_Item_1) == ItemType() && InputDevice2.IsPlayerButtonDown(parent.Index, InputDevice2.PlayerButton.UseItem1))
                {
                    parent.LoadAnimation.Animation = parent.LoadAnimation.Skeleton.Data.FindAnimation(parent.Direction_Facing == GlobalGameConstants.Direction.Left ? "lSlash" : "rSlash");
                }
                else if ((parent.Index == InputDevice2.PPG_Player.Player_1 ? GameCampaign.Player_Left_Item : GameCampaign.Player2_Item_2) == ItemType() && InputDevice2.IsPlayerButtonDown(parent.Index, InputDevice2.PlayerButton.UseItem2))
                {
                    parent.LoadAnimation.Animation = parent.LoadAnimation.Skeleton.Data.FindAnimation(parent.Direction_Facing == GlobalGameConstants.Direction.Left ? "rSlash" : "lSlash");
                }

                switch (item_direction)
                {
                case GlobalGameConstants.Direction.Right:
                    position.X = parent.Position.X + parent.Dimensions.X;
                    position.Y = parent.Position.Y;
                    break;

                case GlobalGameConstants.Direction.Left:
                    position.X = parent.Position.X - hitbox.X;
                    position.Y = parent.Position.Y;
                    break;

                case GlobalGameConstants.Direction.Up:
                    position.Y = parent.Position.Y - hitbox.Y;
                    position.X = parent.CenterPoint.X - hitbox.X / 2;
                    break;

                default:
                    position.Y = parent.CenterPoint.Y + parent.Dimensions.Y / 2;
                    position.X = parent.CenterPoint.X - hitbox.X / 2;
                    break;
                }
                if (item_state_time > delay)
                {
                    sword_state = Sword_State.slash;
                    sword_swing = true;

                    AudioLib.playSoundEffect(swordSound);
                }
            }
            else if (sword_state == Sword_State.slash)
            {
                for (int i = 0; i < parentWorld.EntityList.Count; i++)
                {
                    if (parentWorld.EntityList[i] is Enemy || parentWorld.EntityList[i] is ShopKeeper || parentWorld.EntityList[i] is Key || parentWorld.EntityList[i] is Coin || parentWorld.EntityList[i] is Pickup)
                    {
                        if (hitTest(parentWorld.EntityList[i]))
                        {
                            Vector2 direction = parentWorld.EntityList[i].CenterPoint - parent.CenterPoint;
                            parentWorld.EntityList[i].knockBack(direction, knockback_magnitude, sword_damage, parent);
                            AudioLib.playSoundEffect(hitSound);
                        }
                    }
                }

                sword_state = Sword_State.endslash;
            }
            //time delay for the player to be in this state
            else if (sword_state == Sword_State.endslash)
            {
                parent.State            = Player.playerState.Moving;
                item_state_time         = 0.0f;
                parent.Disable_Movement = true;
                sword_swing             = false;
                sword_state             = Sword_State.preslash;
            }
        }