Esempio n. 1
0
 public override void Use(int faceDir, float attackCharge, Robot gameHero)
 {
     if (Owner.IsPlayer)
     {
         if (EnemyManager.Instance.CheckAttack(Owner.Position, faceDir, 35f, Range, 2, gameHero)) Health -= 10f;
     }
     else
     {
         if ((Owner.Position - gameHero.Position).Length() < 100f)
         {
             gameHero.DoHit(Position, 18f, faceDir, gameHero);
             Health -= 2f;
         }
     }
     base.Use(faceDir, attackCharge, gameHero);
 }
Esempio n. 2
0
 public override void Use(int faceDir, float attackCharge, Robot gameHero)
 {
     if (Owner.IsPlayer)
     {
         if (EnemyManager.Instance.CheckAttack(Owner.Position, faceDir, 50f, Range, 4, gameHero))
         {
             Health -= 15f;
         }
     }
     else
     {
         if ((Owner.Position - gameHero.Position).Length() < 100f)
         {
             gameHero.DoHit(Position, 25f, faceDir, gameHero);
             Health -= 2f;
         }
     }
     base.Use(faceDir, attackCharge, gameHero);
 }
Esempio n. 3
0
        public void Update(GameTime gameTime, Camera gameCamera, Map gameMap, List <int> levelSectors, Dictionary <int, MapObjectLayer> walkableLayers, Robot gameHero)
        {
            if (Active)
            {
                float attackRange = 100f;
                if (Item != null)
                {
                    attackRange = Item.Range;
                }

                if (!IsPlayer)
                {
                    if (notMovedTime > 500)
                    {
                        if (CheckJump(gameMap, levelSectors, walkableLayers))
                        {
                            notMovedTime = 0;
                            Jump();
                        }
                    }

                    if (notMovedTime > 1000)
                    {
                        backingOff     = true;
                        targetPosition = MoveToRandomPosition(gameMap, levelSectors, walkableLayers);
                    }

                    if (!backingOff)
                    {
                        targetPosition.X = gameHero.Position.X;
                        targetPosition.Y = gameHero.landingHeight;
                    }
                    else
                    if (rand.Next(250) == 1)
                    {
                        backingOff = false;
                    }

                    if (Item == null)
                    {
                        Item tryItem = ItemManager.Instance.ClosestItem(this);
                        if (tryItem != null)
                        {
                            if ((Position - tryItem.Position).Length() < 400f)
                            {
                                if (rand.Next(100) == 1)
                                {
                                    targetPosition = tryItem.Position;
                                }

                                if (tryItem.Position.X > Position.X - 75f && tryItem.Position.X < Position.X + 75f)
                                {
                                    if (tryItem.Position.Y > landingHeight - 30f && tryItem.Position.Y < landingHeight + 30f)
                                    {
                                        if (rand.Next(10) == 1)
                                        {
                                            Pickup();
                                        }
                                    }
                                }
                            }
                        }
                    }

                    if ((new Vector2(Position.X, landingHeight) - targetPosition).Length() < 100f)
                    {
                        if (rand.Next(50) == 1)
                        {
                            backingOff       = true;
                            targetPosition.X = (gameHero.Position.X - 300f) + (600f * (float)rand.NextDouble());
                            targetPosition.Y = (gameHero.landingHeight - 100f) + (200f * (float)rand.NextDouble());
                        }
                    }

                    if (targetPosition.X - 50 > Position.X)
                    {
                        MoveLeftRight(1);
                    }

                    if (targetPosition.X + 50 < Position.X)
                    {
                        MoveLeftRight(-1);
                    }

                    if (targetPosition.Y - landingHeight < -5 || targetPosition.Y - landingHeight > 5)
                    {
                        if (targetPosition.Y > landingHeight)
                        {
                            MoveUpDown(1);
                        }

                        if (targetPosition.Y < landingHeight)
                        {
                            MoveUpDown(-1);
                        }
                    }

                    if (gameHero.Position.X > Position.X)
                    {
                        faceDir = 1;
                    }
                    else
                    {
                        faceDir = -1;
                    }

                    // Attacking
                    if (!AIchargingAttack && rand.Next(100) == 1)
                    {
                        AIchargingAttack = true;
                    }

                    if (AIchargingAttack)
                    {
                        Attack(true);
                    }
                    else
                    {
                        Attack(false);
                    }



                    if ((gameHero.Position - Position).Length() < attackRange && gameHero.Active)
                    {
                        if ((faceDir == 1 && gameHero.Position.X > Position.X) || (faceDir == -1 && gameHero.Position.X < Position.X))
                        {
                            if (gameHero.Position.Y > Position.Y - 30f && gameHero.Position.Y < Position.Y + 30f)
                            {
                                if (rand.Next(20) == 1)
                                {
                                    if (!AIchargingAttack)
                                    {
                                        AIchargingAttack = true;
                                    }
                                    else
                                    {
                                        Attack(false);
                                    }
                                }
                            }
                        }
                    }

                    ///////////////
                }

                if ((int)Position.X > furthestX)
                {
                    furthestX = (int)Position.X;
                    Score++;
                }

                if (!walking && !jumping && knockbackTime <= 0)
                {
                    Animations["walk"].Apply(skeleton, 0f, false);
                }

                if (walking && !jumping && knockbackTime <= 0)
                {
                    animTime += (gameTime.ElapsedGameTime.Milliseconds / 1000f) * 2;

                    Animations["walk"].Mix(skeleton, animTime, true, 0.3f);
                }

                if (pickingUp)
                {
                    pickupTime += gameTime.ElapsedGameTime.TotalMilliseconds;
                    animTime   += (gameTime.ElapsedGameTime.Milliseconds / 1000f) * 3;

                    Animations["pickup"].Apply(skeleton, animTime, false);

                    if (pickupTime > 150 && !hasPickedUp)
                    {
                        ItemManager.Instance.AttemptPickup(this);
                        hasPickedUp = true;
                    }
                    if (pickupTime >= 300)
                    {
                        pickingUp   = false;
                        hasPickedUp = false;
                    }
                }

                if (knockbackTime > 0)
                {
                    knockbackTime -= gameTime.ElapsedGameTime.TotalMilliseconds;

                    animTime += (gameTime.ElapsedGameTime.Milliseconds / 1000f) * 3;
                    Animations["knockback"].Mix(skeleton, animTime, true, 0.3f);

                    CheckCollision(gameTime, gameMap, levelSectors, walkableLayers, gameHero.Sector);
                    Position += (Speed);

                    if (Speed.X > 0)
                    {
                        Speed.X -= 0.1f;
                    }
                    else if (Speed.X < 0)
                    {
                        Speed.X += 0.1f;
                    }

                    if (fistSound.Volume > 0f)
                    {
                        fistSound.Volume = MathHelper.Clamp(fistSound.Volume -= 0.1f, 0f, 1f);
                    }
                    if (fistSound.Pitch > -1f)
                    {
                        fistSound.Pitch = MathHelper.Clamp(fistSound.Pitch - 0.1f, -0.9f, 0.9f);
                    }

                    //if (Speed.X > -0.1f && Speed.X < 0.1f) knockbackTime = 0;
                }
                else
                {
                    if (jumping)
                    {
                        Position  += JumpSpeed;
                        JumpSpeed += gravity;
                        if (JumpSpeed.Y > 0f)
                        {
                            jumping = false; falling = true;
                        }

                        animTime += gameTime.ElapsedGameTime.Milliseconds / 1000f;
                        //Animations["jump"].Mix(skeleton, animTime, false, 0.5f);
                    }

                    if (!jumping && !falling)
                    {
                        landingHeight = Position.Y;
                    }

                    if (punchHeld && !punchReleased)
                    {
                        if (Item == null)
                        {
                            attackCharge += 0.25f * (IsPlayer?2f:1f);
                            Animations["punch-hold"].Apply(skeleton, 1f, false);

                            fistSound.Volume = MathHelper.Clamp((0.2f / 50f) * (attackCharge), 0f, 1f);
                            fistSound.Pitch  = MathHelper.Clamp(-1f + ((2f / 50f) * (attackCharge)), -0.9f, 0.9f);
                        }
                        else if (Item.Type == ItemType.Melee)
                        {
                            attackCharge += 0.25f;
                            Animations["punch-hold"].Apply(skeleton, 1f, false);
                        }
                        else if (Item.Type == ItemType.Projectile)
                        {
                            attackCharge += 0.25f;
                            Animations["punch-release"].Apply(skeleton, 1f, false);
                            if (IsPlayer || rand.Next(50) == 0)
                            {
                                Item.Use(faceDir, attackCharge, gameHero);
                            }
                        }

                        if (rand.Next(51 - (int)attackCharge) == 0 && Item == null)
                        {
                            ParticleManager.Instance.Add(ParticleType.Standard, (Position - new Vector2(faceDir * 50, 75)) + (new Vector2(-15f + ((float)rand.NextDouble() * 30f), -10f + ((float)rand.NextDouble() * 20f))), (landingHeight - 10f) + ((float)rand.NextDouble() * 20f), new Vector2(-0.5f + (float)rand.NextDouble() * 1f, -0.5f + (float)rand.NextDouble() * 1f), 0f, true, new Rectangle(0, 0, 2, 2), 0f, Color.DeepSkyBlue);
                        }
                    }
                    else if (punchReleased)
                    {
                        AIchargingAttack = false;

                        if (Item == null)
                        {
                            if (punchReleaseTime == 0)
                            {
                                AudioController.PlaySFX("swipe", 0.5f, -0.25f + ((float)rand.NextDouble() * 0.5f), 0f);
                                if (IsPlayer)
                                {
                                    EnemyManager.Instance.CheckAttack(Position, faceDir, attackCharge, attackRange, 1, gameHero);
                                }
                                else
                                if ((Position - gameHero.Position).Length() < attackRange)
                                {
                                    gameHero.DoHit(Position, attackCharge, faceDir, gameHero);
                                }
                            }
                        }
                        else if (Item.Type == ItemType.Melee)
                        {
                            if (punchReleaseTime == 0)
                            {
                                AudioController.PlaySFX("swipe", 0.5f, -0.25f + ((float)rand.NextDouble() * 0.5f), 0f);
                                Item.Use(faceDir, attackCharge, gameHero);
                            }
                        }
                        else if (Item.Type == ItemType.Projectile)
                        {
                            punchReleaseTime = Item.Cooldown;
                        }

                        punchReleaseTime += gameTime.ElapsedGameTime.TotalMilliseconds;
                        if (punchReleaseTime >= (Item != null?Item.Cooldown:200))
                        {
                            punchReleaseTime = 0;
                            punchReleased    = false;
                            AIchargingAttack = false;
                            Animations["punch-release"].Apply(skeleton, 0f, false);
                        }

                        Animations["punch-release"].Apply(skeleton, 1f, false);


                        if (fistSound.Volume > 0f)
                        {
                            fistSound.Volume = MathHelper.Clamp(fistSound.Volume -= 0.1f, 0f, 1f);
                        }
                        if (fistSound.Pitch > -1f)
                        {
                            fistSound.Pitch = MathHelper.Clamp(fistSound.Pitch - 0.1f, -0.9f, 0.9f);
                        }

                        attackCharge = 0f;
                    }

                    attackCharge = MathHelper.Clamp(attackCharge, 0f, 50f);

                    Speed.Normalize();

                    if (Speed.Length() > 0f || pushingUp)
                    {
                        CheckCollision(gameTime, gameMap, levelSectors, walkableLayers, gameHero.Sector);
                        if (Speed.Length() > 0f)
                        {
                            Position += (Speed * 4f);
                        }
                    }

                    Speed = Vector2.Zero;
                }

                if (Item != null)
                {
                    if (fistSound.Volume > 0f)
                    {
                        fistSound.Volume = MathHelper.Clamp(fistSound.Volume -= 0.1f, 0f, 1f);
                    }
                    if (fistSound.Pitch > -1f)
                    {
                        fistSound.Pitch = MathHelper.Clamp(fistSound.Pitch - 0.1f, -0.9f, 0.9f);
                    }

                    if (Item.Type == ItemType.Melee)
                    {
                        skeleton.SetAttachment("melee-item", Item.Name);
                        skeleton.SetAttachment("projectile-item", null);
                    }
                    else
                    {
                        skeleton.SetAttachment("projectile-item", Item.Name);
                        skeleton.SetAttachment("melee-item", null);
                    }

                    //skeleton.FindSlot("fist-item").A = 1f;
                    if (skeleton.FindSlot("fist-item").A > 0f)
                    {
                        skeleton.FindSlot("fist-item").A -= 0.1f;
                    }
                }
                else
                {
                    if (attackCharge > 0f)
                    {
                        skeleton.FindSlot("fist-item").A = (1f / 50f) * attackCharge;
                    }
                    else
                    if (skeleton.FindSlot("fist-item").A > 0f)
                    {
                        skeleton.FindSlot("fist-item").A -= 0.1f;
                    }
                    skeleton.SetAttachment("fist-item", "fistweap" + (rand.Next(2) + 1).ToString());

                    skeleton.SetAttachment("melee-item", null);
                    skeleton.SetAttachment("projectile-item", null);
                }

                pushingUp = false;
            }

            if (Health <= 1f || !Active)
            {
                Active = false;

                animTime += (gameTime.ElapsedGameTime.Milliseconds / 1000f);
                Animations["knockout"].Mix(skeleton, animTime, true, 0.2f);

                deadTime += gameTime.ElapsedGameTime.TotalMilliseconds;
                if (deadTime > 0 && deadTime < 1000)
                {
                    CheckCollision(gameTime, gameMap, levelSectors, walkableLayers, gameHero.Sector);
                    Position.X += ((float)-faceDir) * (0.001f * (1000f - (float)deadTime));
                }
                if (deadTime > 2000 && alpha > 0f)
                {
                    alpha -= 0.025f;
                    alpha  = MathHelper.Clamp(alpha, 0f, 1f);
                }

                if (skeleton.FindSlot("fist-item").A > 0f)
                {
                    skeleton.FindSlot("fist-item").A -= 0.1f;
                }

                if (deadTime >= 3000)
                {
                    Dead = true;

                    fistSound.Stop();
                    fistSound.Dispose();
                }

                if (fistSound.Volume > 0f)
                {
                    fistSound.Volume = MathHelper.Clamp(fistSound.Volume -= 0.1f, 0f, 1f);
                }
                if (fistSound.Pitch > -1f)
                {
                    fistSound.Pitch = MathHelper.Clamp(fistSound.Pitch -= 0.1f, -0.9f, 0.9f);
                }
            }

            if (falling)
            {
                Position  += JumpSpeed;
                JumpSpeed += gravity;

                if (Position.Y >= landingHeight)
                {
                    falling    = false;
                    JumpSpeed  = Vector2.Zero;
                    Position.Y = landingHeight;
                    AudioController.PlaySFX("land", 1f, 0f, 0f);
                }
            }

            skeleton.A = alpha;
            foreach (Slot s in skeleton.Slots)
            {
                if (s.Data.Name != "melee-item" && s.Data.Name != "projectile-item" && s.Data.Name != "fist-item")
                {
                    s.A = skeleton.A;
                }
            }

            skeleton.RootBone.ScaleX = Scale;
            skeleton.RootBone.ScaleY = Scale;

            collisionRect.Location = new Point((int)Position.X - (collisionRect.Width / 2), (int)Position.Y - (collisionRect.Height));

            Position.X = MathHelper.Clamp(Position.X, 0, (gameMap.Width * gameMap.TileWidth) * levelSectors.Count);
            Position.Y = MathHelper.Clamp(Position.Y, 0, gameMap.Height * gameMap.TileHeight);

            skeleton.RootBone.X = Position.X;
            skeleton.RootBone.Y = Position.Y;

            if (faceDir == -1)
            {
                skeleton.FlipX = true;
            }
            else
            {
                skeleton.FlipX = false;
            }

            skeleton.UpdateWorldTransform();

            walking = false;

            if (Position.X > (gameMap.Width * gameMap.TileWidth) * (Sector + 1))
            {
                Sector++;
            }
            if (Position.X < (gameMap.Width * gameMap.TileWidth) * (Sector))
            {
                Sector--;
            }

            Health = MathHelper.Clamp(Health, 0f, 121f);

            if (fistSound.Volume < 0.01f)
            {
                fistSound.Volume = 0f;
            }
        }
Esempio n. 4
0
        public void Update(GameTime gameTime, Robot gameHero)
        {
            for (int p = 0; p < Projectiles.Count; p++)
            {
                if (Projectiles[p].Active)
                {
                    Projectiles[p].Position += Projectiles[p].Speed;

                    Projectiles[p].rot = Helper.V2ToAngle(Projectiles[p].Speed);


                    Projectiles[p].Life -= gameTime.ElapsedGameTime.TotalMilliseconds;
                    if (Projectiles[p].Life <= 0)
                    {
                        //if (Projectiles[p].Type == ProjectileType.Grenade || Projectiles[p].Type == ProjectileType.Rocket) ExplodeGrenade(Projectiles[p], false);

                        Projectiles[p].alpha -= 0.1f;
                        if (Projectiles[p].alpha <= 0f)
                        {
                            Projectiles[p].Active = false;
                        }
                    }

                    if (Projectiles[p].Life > 0 || Projectiles[p].alpha > 0)
                    {
                        //if (Projectiles[p].Type == ProjectileType.Grenade)
                        //{
                        //    Projectiles[p].Speed.Y += 0.1f;
                        //    //GameManager.ParticleController.Add(Projectiles[p].Position + new Vector2(((float)randomNumber.NextDouble() * 5f) - 2.5f, ((float)randomNumber.NextDouble() * 5f) - 2.5f), Vector2.Zero, 100f, false, false, new Rectangle(8,0,8,8), 0f, Color.Gray);

                        //    for (int i = 0; i < Projectiles.Count; i++)
                        //        if (Projectiles[i].OwnedByHero && Projectiles[i].Active)
                        //            if ((Projectiles[i].Position - Projectiles[p].Position).Length() <= 8) ExplodeGrenade(Projectiles[p], true);
                        //}



                        // do collision checks
                        if (Projectiles[p].OwnedByHero)
                        {
                            foreach (Robot e in EnemyManager.Instance.Enemies)
                            {
                                if (!Projectiles[p].Active)
                                {
                                    break;
                                }

                                if (Projectiles[p].Position.X > e.Position.X - 40 && Projectiles[p].Position.X <e.Position.X + 40 &&
                                                                                                                Projectiles[p].Position.Y> e.Position.Y - 150 && Projectiles[p].Position.Y <e.Position.Y &&
                                                                                                                                                                                            Projectiles[p].landingHeight> e.landingHeight - 30 && Projectiles[p].landingHeight < e.landingHeight + 30)
                                {
                                    if (e.Active)
                                    {
                                        e.DoHit(Projectiles[p].Position, Projectiles[p].Power, Projectiles[p].Speed.X > 0f ? 1 : -1, gameHero);
                                        Projectiles[p].Active = false;
                                    }
                                }
                            }
                        }
                        else
                        {
                            if (Projectiles[p].Position.X > gameHero.Position.X - 40 && Projectiles[p].Position.X <gameHero.Position.X + 40 &&
                                                                                                                   Projectiles[p].Position.Y> gameHero.Position.Y - 150 && Projectiles[p].Position.Y <gameHero.Position.Y &&
                                                                                                                                                                                                      Projectiles[p].landingHeight> gameHero.landingHeight - 30 && Projectiles[p].landingHeight < gameHero.landingHeight + 30)
                            {
                                gameHero.DoHit(Projectiles[p].Position, Projectiles[p].Power, Projectiles[p].Speed.X > 0f ? 1 : -1, gameHero);
                                Projectiles[p].Active = false;
                            }
                        }
                    }
                }
            }
        }
Esempio n. 5
0
        public void Update(GameTime gameTime, Robot gameHero)
        {
            for (int p = 0; p < Projectiles.Count; p++)
            {
                if (Projectiles[p].Active)
                {
                    Projectiles[p].Position += Projectiles[p].Speed;

                    Projectiles[p].rot = Helper.V2ToAngle(Projectiles[p].Speed);

                    Projectiles[p].Life -= gameTime.ElapsedGameTime.TotalMilliseconds;
                    if (Projectiles[p].Life <= 0)
                    {
                        //if (Projectiles[p].Type == ProjectileType.Grenade || Projectiles[p].Type == ProjectileType.Rocket) ExplodeGrenade(Projectiles[p], false);

                        Projectiles[p].alpha -= 0.1f;
                        if (Projectiles[p].alpha <= 0f) Projectiles[p].Active = false;
                    }

                    if (Projectiles[p].Life > 0 || Projectiles[p].alpha > 0)
                    {
                        //if (Projectiles[p].Type == ProjectileType.Grenade)
                        //{
                        //    Projectiles[p].Speed.Y += 0.1f;
                        //    //GameManager.ParticleController.Add(Projectiles[p].Position + new Vector2(((float)randomNumber.NextDouble() * 5f) - 2.5f, ((float)randomNumber.NextDouble() * 5f) - 2.5f), Vector2.Zero, 100f, false, false, new Rectangle(8,0,8,8), 0f, Color.Gray);

                        //    for (int i = 0; i < Projectiles.Count; i++)
                        //        if (Projectiles[i].OwnedByHero && Projectiles[i].Active)
                        //            if ((Projectiles[i].Position - Projectiles[p].Position).Length() <= 8) ExplodeGrenade(Projectiles[p], true);
                        //}

                        // do collision checks
                        if (Projectiles[p].OwnedByHero)
                        {
                            foreach (Robot e in EnemyManager.Instance.Enemies)
                            {
                                if (!Projectiles[p].Active) break;

                                if (Projectiles[p].Position.X>e.Position.X-40 && Projectiles[p].Position.X<e.Position.X+40 &&
                                    Projectiles[p].Position.Y>e.Position.Y-150 && Projectiles[p].Position.Y<e.Position.Y &&
                                    Projectiles[p].landingHeight>e.landingHeight-30 && Projectiles[p].landingHeight<e.landingHeight+30)
                                {
                                    if (e.Active)
                                    {
                                        e.DoHit(Projectiles[p].Position, Projectiles[p].Power, Projectiles[p].Speed.X > 0f ? 1 : -1, gameHero);
                                        Projectiles[p].Active = false;
                                    }
                                }
                            }
                        }
                        else
                        {
                            if (Projectiles[p].Position.X > gameHero.Position.X - 40 && Projectiles[p].Position.X < gameHero.Position.X + 40 &&
                                    Projectiles[p].Position.Y > gameHero.Position.Y - 150 && Projectiles[p].Position.Y < gameHero.Position.Y &&
                                    Projectiles[p].landingHeight > gameHero.landingHeight - 30 && Projectiles[p].landingHeight < gameHero.landingHeight + 30)
                            {
                                gameHero.DoHit(Projectiles[p].Position, Projectiles[p].Power, Projectiles[p].Speed.X > 0f ? 1 : -1, gameHero);
                                Projectiles[p].Active = false;
                            }

                        }
                    }
                }
            }
        }
Esempio n. 6
0
        public void Update(GameTime gameTime, Camera gameCamera, Map gameMap, List<int> levelSectors, Dictionary<int, MapObjectLayer> walkableLayers, Robot gameHero)
        {
            if (Active)
            {
                float attackRange = 100f;
                if (Item != null) attackRange = Item.Range;

                if (!IsPlayer)
                {

                    if (notMovedTime > 500)
                    {
                        if (CheckJump(gameMap, levelSectors, walkableLayers))
                        {
                            notMovedTime = 0;
                            Jump();
                        }
                    }

                    if (notMovedTime > 1000)
                    {
                        backingOff = true;
                        targetPosition = MoveToRandomPosition(gameMap, levelSectors, walkableLayers);
                    }

                    if (!backingOff)
                    {
                        targetPosition.X = gameHero.Position.X;
                        targetPosition.Y = gameHero.landingHeight;
                    }
                    else
                        if (rand.Next(250) == 1) backingOff = false;

                    if (Item == null)
                    {
                        Item tryItem = ItemManager.Instance.ClosestItem(this);
                        if (tryItem != null)
                        {
                            if ((Position - tryItem.Position).Length() < 400f)
                            {
                                if (rand.Next(100) == 1)
                                    targetPosition = tryItem.Position;

                                if (tryItem.Position.X > Position.X - 75f && tryItem.Position.X < Position.X + 75f)
                                {
                                    if (tryItem.Position.Y > landingHeight - 30f && tryItem.Position.Y < landingHeight + 30f)
                                    {
                                        if (rand.Next(10) == 1)
                                            Pickup();
                                    }
                                }
                            }
                        }
                    }

                    if ((new Vector2(Position.X, landingHeight) - targetPosition).Length() < 100f)
                    {
                        if (rand.Next(50) == 1)
                        {
                            backingOff = true;
                            targetPosition.X = (gameHero.Position.X - 300f) + (600f * (float)rand.NextDouble());
                            targetPosition.Y = (gameHero.landingHeight - 100f) + (200f * (float)rand.NextDouble());
                        }
                    }

                    if (targetPosition.X - 50 > Position.X)
                        MoveLeftRight(1);

                    if (targetPosition.X + 50 < Position.X)
                        MoveLeftRight(-1);

                    if (targetPosition.Y - landingHeight < -5 || targetPosition.Y - landingHeight > 5)
                    {
                        if (targetPosition.Y > landingHeight)
                            MoveUpDown(1);

                        if (targetPosition.Y < landingHeight)
                            MoveUpDown(-1);
                    }

                    if (gameHero.Position.X > Position.X) faceDir = 1; else faceDir = -1;

                    // Attacking
                    if (!AIchargingAttack && rand.Next(100) == 1)
                    {
                        AIchargingAttack = true;
                    }

                    if (AIchargingAttack) Attack(true);
                    else Attack(false);

                    if ((gameHero.Position - Position).Length() < attackRange && gameHero.Active)
                    {
                        if ((faceDir == 1 && gameHero.Position.X > Position.X) || (faceDir == -1 && gameHero.Position.X < Position.X))
                        {
                            if (gameHero.Position.Y > Position.Y - 30f && gameHero.Position.Y < Position.Y + 30f)
                            {
                                if (rand.Next(20) == 1)
                                {
                                    if (!AIchargingAttack) AIchargingAttack = true;
                                    else Attack(false);
                                }
                            }
                        }
                    }

                    ///////////////
                }

                if ((int)Position.X > furthestX)
                {
                    furthestX = (int)Position.X;
                    Score++;
                }

                if (!walking && !jumping && knockbackTime <= 0)
                {
                    Animations["walk"].Apply(skeleton, 0f, false);
                }

                if (walking && !jumping && knockbackTime <= 0)
                {
                    animTime += (gameTime.ElapsedGameTime.Milliseconds / 1000f) * 2;

                    Animations["walk"].Mix(skeleton, animTime, true, 0.3f);
                }

                if (pickingUp)
                {
                    pickupTime += gameTime.ElapsedGameTime.TotalMilliseconds;
                    animTime += (gameTime.ElapsedGameTime.Milliseconds / 1000f) * 3;

                    Animations["pickup"].Apply(skeleton, animTime, false);

                    if (pickupTime > 150 && !hasPickedUp)
                    {
                        ItemManager.Instance.AttemptPickup(this);
                        hasPickedUp = true;
                    }
                    if (pickupTime >= 300)
                    {
                        pickingUp = false;
                        hasPickedUp = false;
                    }
                }

                if (knockbackTime > 0)
                {
                    knockbackTime -= gameTime.ElapsedGameTime.TotalMilliseconds;

                    animTime += (gameTime.ElapsedGameTime.Milliseconds / 1000f) * 3;
                    Animations["knockback"].Mix(skeleton, animTime, true, 0.3f);

                    CheckCollision(gameTime, gameMap, levelSectors, walkableLayers, gameHero.Sector);
                    Position += (Speed);

                    if (Speed.X > 0) Speed.X -= 0.1f;
                    else if (Speed.X < 0) Speed.X += 0.1f;

                    if (fistSound.Volume > 0f) fistSound.Volume = MathHelper.Clamp(fistSound.Volume -= 0.1f,0f,1f);
                    if (fistSound.Pitch > -1f) fistSound.Pitch = MathHelper.Clamp(fistSound.Pitch - 0.1f,-0.9f,0.9f);

                    //if (Speed.X > -0.1f && Speed.X < 0.1f) knockbackTime = 0;
                }
                else
                {

                    if (jumping)
                    {
                        Position += JumpSpeed;
                        JumpSpeed += gravity;
                        if (JumpSpeed.Y > 0f) { jumping = false; falling = true; }

                        animTime += gameTime.ElapsedGameTime.Milliseconds / 1000f;
                        //Animations["jump"].Mix(skeleton, animTime, false, 0.5f);
                    }

                    if (!jumping && !falling) landingHeight = Position.Y;

                    if (punchHeld && !punchReleased)
                    {

                        if (Item == null)
                        {
                            attackCharge += 0.25f * (IsPlayer?2f:1f);
                            Animations["punch-hold"].Apply(skeleton, 1f, false);

                            fistSound.Volume = MathHelper.Clamp((0.2f / 50f) * (attackCharge), 0f,1f);
                            fistSound.Pitch = MathHelper.Clamp(-1f + ((2f / 50f) * (attackCharge)), -0.9f,0.9f);
                        }
                        else if (Item.Type == ItemType.Melee)
                        {
                            attackCharge += 0.25f;
                            Animations["punch-hold"].Apply(skeleton, 1f, false);

                        }
                        else if (Item.Type == ItemType.Projectile)
                        {
                            attackCharge += 0.25f;
                            Animations["punch-release"].Apply(skeleton, 1f, false);
                            if(IsPlayer || rand.Next(50)==0)
                                Item.Use(faceDir, attackCharge, gameHero);
                        }

                        if(rand.Next(51 - (int)attackCharge)==0 && Item==null)
                            ParticleManager.Instance.Add(ParticleType.Standard, (Position - new Vector2(faceDir * 50, 75)) + (new Vector2(-15f + ((float)rand.NextDouble() * 30f), -10f + ((float)rand.NextDouble() * 20f))), (landingHeight - 10f) + ((float)rand.NextDouble() * 20f), new Vector2(-0.5f + (float)rand.NextDouble() * 1f, -0.5f + (float)rand.NextDouble() * 1f), 0f, true, new Rectangle(0, 0, 2, 2), 0f, Color.DeepSkyBlue);

                    }
                    else if (punchReleased)
                    {
                        AIchargingAttack = false;

                        if (Item == null)
                        {
                            if (punchReleaseTime == 0)
                            {
                                AudioController.PlaySFX("swipe",0.5f, -0.25f + ((float)rand.NextDouble() * 0.5f),0f);
                                if (IsPlayer)
                                    EnemyManager.Instance.CheckAttack(Position, faceDir, attackCharge, attackRange, 1, gameHero);
                                else
                                    if ((Position - gameHero.Position).Length() < attackRange) gameHero.DoHit(Position, attackCharge, faceDir, gameHero);
                            }
                        }
                        else if (Item.Type == ItemType.Melee)
                        {
                            if (punchReleaseTime == 0)
                            {
                                AudioController.PlaySFX("swipe",0.5f,-0.25f + ((float)rand.NextDouble() * 0.5f), 0f);
                                Item.Use(faceDir, attackCharge, gameHero);

                            }
                        }
                        else if (Item.Type == ItemType.Projectile)
                        {
                            punchReleaseTime = Item.Cooldown;
                        }

                        punchReleaseTime += gameTime.ElapsedGameTime.TotalMilliseconds;
                        if (punchReleaseTime >= (Item!=null?Item.Cooldown:200))
                        {
                            punchReleaseTime = 0;
                            punchReleased = false;
                            AIchargingAttack = false;
                            Animations["punch-release"].Apply(skeleton, 0f, false);
                        }

                        Animations["punch-release"].Apply(skeleton, 1f, false);

                        if (fistSound.Volume > 0f) fistSound.Volume = MathHelper.Clamp(fistSound.Volume -= 0.1f, 0f, 1f);
                        if (fistSound.Pitch > -1f) fistSound.Pitch = MathHelper.Clamp(fistSound.Pitch - 0.1f, -0.9f, 0.9f);

                        attackCharge = 0f;
                    }

                    attackCharge = MathHelper.Clamp(attackCharge, 0f, 50f);

                    Speed.Normalize();

                    if (Speed.Length() > 0f || pushingUp)
                    {
                        CheckCollision(gameTime, gameMap, levelSectors, walkableLayers, gameHero.Sector);
                        if (Speed.Length() > 0f)
                            Position += (Speed * 4f);
                    }

                    Speed = Vector2.Zero;
                }

                if (Item != null)
                {
                    if (fistSound.Volume > 0f) fistSound.Volume = MathHelper.Clamp(fistSound.Volume -= 0.1f, 0f, 1f);
                    if (fistSound.Pitch > -1f) fistSound.Pitch = MathHelper.Clamp(fistSound.Pitch - 0.1f, -0.9f, 0.9f);

                    if (Item.Type == ItemType.Melee)
                    {
                        skeleton.SetAttachment("melee-item", Item.Name);
                        skeleton.SetAttachment("projectile-item", null);
                    }
                    else
                    {
                        skeleton.SetAttachment("projectile-item", Item.Name);
                        skeleton.SetAttachment("melee-item", null);
                    }

                    //skeleton.FindSlot("fist-item").A = 1f;
                    if (skeleton.FindSlot("fist-item").A > 0f) skeleton.FindSlot("fist-item").A -= 0.1f;
                }
                else
                {
                    if (attackCharge > 0f)
                        skeleton.FindSlot("fist-item").A = (1f / 50f) * attackCharge;
                    else
                        if (skeleton.FindSlot("fist-item").A > 0f) skeleton.FindSlot("fist-item").A -= 0.1f;
                    skeleton.SetAttachment("fist-item", "fistweap" + (rand.Next(2) + 1).ToString());

                    skeleton.SetAttachment("melee-item", null);
                    skeleton.SetAttachment("projectile-item", null);
                }

                pushingUp = false;
            }

            if (Health <= 1f ||!Active)
            {
                Active = false;

                animTime += (gameTime.ElapsedGameTime.Milliseconds / 1000f);
                Animations["knockout"].Mix(skeleton, animTime, true, 0.2f);

                deadTime += gameTime.ElapsedGameTime.TotalMilliseconds;
                if (deadTime > 0 && deadTime<1000)
                {
                    CheckCollision(gameTime, gameMap, levelSectors, walkableLayers, gameHero.Sector);
                    Position.X += ((float)-faceDir) * (0.001f * (1000f - (float)deadTime));
                }
                if (deadTime > 2000 && alpha > 0f)
                {
                    alpha -= 0.025f;
                    alpha = MathHelper.Clamp(alpha, 0f, 1f);
                }

                if (skeleton.FindSlot("fist-item").A > 0f) skeleton.FindSlot("fist-item").A -= 0.1f;

                if (deadTime >= 3000)
                {
                    Dead = true;

                    fistSound.Stop();
                    fistSound.Dispose();
                }

                if (fistSound.Volume > 0f) fistSound.Volume = MathHelper.Clamp(fistSound.Volume -= 0.1f, 0f, 1f);
                if (fistSound.Pitch > -1f) fistSound.Pitch = MathHelper.Clamp(fistSound.Pitch -= 0.1f, -0.9f, 0.9f);
            }

            if (falling)
            {
                Position += JumpSpeed;
                JumpSpeed += gravity;

                if (Position.Y >= landingHeight)
                {
                    falling = false;
                    JumpSpeed = Vector2.Zero;
                    Position.Y = landingHeight;
                    AudioController.PlaySFX("land", 1f, 0f, 0f);

                }
            }

            skeleton.A = alpha;
            foreach (Slot s in skeleton.Slots)
            {
                if (s.Data.Name != "melee-item" && s.Data.Name != "projectile-item" && s.Data.Name != "fist-item")
                {
                    s.A = skeleton.A;
                }
            }

            skeleton.RootBone.ScaleX = Scale;
            skeleton.RootBone.ScaleY = Scale;

            collisionRect.Location = new Point((int)Position.X - (collisionRect.Width / 2), (int)Position.Y - (collisionRect.Height));

            Position.X = MathHelper.Clamp(Position.X, 0, (gameMap.Width * gameMap.TileWidth) * levelSectors.Count);
            Position.Y = MathHelper.Clamp(Position.Y, 0, gameMap.Height * gameMap.TileHeight);

            skeleton.RootBone.X = Position.X;
            skeleton.RootBone.Y = Position.Y;

            if (faceDir == -1) skeleton.FlipX = true; else skeleton.FlipX = false;

            skeleton.UpdateWorldTransform();

            walking = false;

            if (Position.X > (gameMap.Width * gameMap.TileWidth) * (Sector + 1))
                Sector++;
            if (Position.X < (gameMap.Width * gameMap.TileWidth) * (Sector))
                Sector--;

            Health = MathHelper.Clamp(Health, 0f, 121f);

            if (fistSound.Volume < 0.01f) fistSound.Volume = 0f;
        }