Example #1
0
        public bool CheckAttack(Vector2 pos, int faceDir, float power, float maxDist, int maxHits, Robot gameHero)
        {
            float mindist = 10000f;
            Robot target = null;
            int numHits = 0;

            foreach (Robot r in Enemies)
            {
                if ((r.Position - pos).Length() < mindist && (r.Position - pos).Length()<maxDist && r.Active)
                {
                    if ((faceDir == 1 && r.Position.X > pos.X) || (faceDir == -1 && r.Position.X < pos.X))
                    {
                        if (r.Position.Y > pos.Y - 30f && r.Position.Y < pos.Y + 30f)
                        {
                            numHits++;
                            if(numHits<=maxHits)
                                r.DoHit(pos, power, faceDir, gameHero);
                            mindist = (r.Position - pos).Length();
                        }
                    }
                }
            }

            return (numHits > 0);
        }
Example #2
0
        public void Spawn(Robot owner)
        {
            int item = rand.Next(3);

            Item newItem = null;

            switch (item)
            {
                case 0:
                    // crowbar
                    newItem = new Crowbar(itemTex, sourceDict["crowbar"]);
                    break;
                case 1:
                    // laserpistol
                    newItem = new LaserPistol(itemTex, sourceDict["laserpistol"]);
                    break;
                case 2:
                    // axe
                    newItem = new Axe(itemTex, sourceDict["axe"]);
                    break;
            }

            newItem.Owner = owner;
            owner.Item = newItem;
            Items.Add(newItem);
        }
Example #3
0
        public override void Use(int faceDir, float attackCharge, Robot gameHero)
        {
            if (coolDownTime > 0) return;

            if (Owner.IsPlayer)
            {
                ProjectileManager.Instance.Add(Owner.Position + new Vector2(Owner.faceDir * 60, -107), Owner.landingHeight - 1f, new Vector2(Owner.faceDir * 10f, 0f), 2000, true, ProjectileType.Laser, 15f, Color.Red);

                Health -= 7f;
                AudioController.PlaySFX("laser", 0.5f, 0f,0f);
            }
            else
            {
                if (Owner.landingHeight > gameHero.landingHeight-30 && Owner.landingHeight<gameHero.landingHeight+30)
                {
                    ProjectileManager.Instance.Add(Owner.Position + new Vector2(Owner.faceDir * 60, -107), Owner.landingHeight - 1f, new Vector2(Owner.faceDir * 10f, 0f), 2000, false, ProjectileType.Laser, 10f, Color.Red);

                    Health -= 1f;
                    AudioController.PlaySFX("laser", 0.5f, 0f, 0f);

                }
            }

            base.Use(faceDir, attackCharge, gameHero);
        }
Example #4
0
        public Robot(Vector2 spawnpos, bool isPlayer, Robot gameHero)
        {
            IsPlayer = isPlayer;
            spawnPosition = spawnpos;

            Position = spawnPosition;
            if (Position.X > gameHero.Position.X) faceDir = -1; else faceDir = 1;
        }
Example #5
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);
 }
Example #6
0
        public Item ClosestItem(Robot robot)
        {
            float dist = 10000f;
            Item returnItem = null;

            foreach (Item i in Items)
            {
                if (i.Health > 0f && !i.Dead && i.InWorld)
                {
                    if ((robot.Position - i.Position).Length() < dist)
                    {
                        dist = (robot.Position - i.Position).Length();
                        returnItem = i;
                    }
                }
            }

            return returnItem;
        }
Example #7
0
        public void Update(GameTime gameTime, Robot gameHero)
        {
            healthWidth = (int)gameHero.Health;
            if (gameHero.Item != null)
                weapWidth = (int)gameHero.Item.Health;
            else weapWidth = 0;

            Score = gameHero.Score;

            if (gameHero.Health <= 25f)
            {
                lowHealthBlinkTime += gameTime.ElapsedGameTime.TotalMilliseconds;
                if (lowHealthBlinkTime > 500)
                {
                    lowHealthBlinkTime = 0;
                    lowHealthBlink = !lowHealthBlink;
                    //if (lowHealthBlink) AudioController.PlaySFX("alert", 0.8f, 0f, 0f);
                }
            }
            else
                lowHealthBlink = false;
        }
Example #8
0
        public int Spawn(Map gameMap, Camera gameCamera, List<int> levelSectors, Robot gameHero)
        {
            int numSpawned = 0;
            // Left or right side?

            bool weaponspawned = false;

            for (int num = 0; num < 1 + rand.Next(gameHero.Sector+2); num++)
            {
                if (numSpawned > largestNumberSpawned) break;

                int side = rand.Next(2);
                if (side == 0) side = -1;

                // Actual X spawn position
                Vector2 spawnPos = new Vector2(gameCamera.Position.X + (((gameCamera.Width / 2) + 50f + ((float)rand.NextDouble() * 100f)) * side), gameCamera.Position.Y - (gameCamera.Width / 2));

                // Detect a Y position
                bool spawned = false;
                for (float y = spawnPos.Y; y < spawnPos.Y + gameCamera.Height; y += 15f)
                {
                    if (!spawned)
                    {
                        for (int i = 0; i < levelSectors.Count; i++)
                        {
                            MapObjectLayer walkableLayer = gameMap.GetLayer("Walkable" + levelSectors[i].ToString()) as MapObjectLayer;
                            foreach (MapObject o in walkableLayer.Objects)
                            {
                                if (!spawned && Helper.IsPointInShape(new Vector2(spawnPos.X - ((gameMap.Width * gameMap.TileWidth) * i), y), o.LinePoints))
                                {
                                    if (rand.Next(3) == 1)
                                    {
                                        numSpawned++;
                                        spawned = true;

                                        Robot r = new Robot(new Vector2(spawnPos.X, y), false);

                                        if ((rand.Next(5) == 0 || spawnsWithoutWeapon == 3) && !weaponspawned)
                                        {
                                            spawnsWithoutWeapon = 0;
                                            ItemManager.Instance.Spawn(r);
                                            weaponspawned = true;
                                        }
                                        else spawnsWithoutWeapon++;

                                        r.LoadContent(skeletonRenderer, blankTex, AtlasDict["robo"], JsonDict["robo"]);
                                        Enemies.Add(r);
                                    }
                                }
                            }
                        }
                    }
                }
            }

            if (numSpawned > largestNumberSpawned) largestNumberSpawned = numSpawned;

            return numSpawned;
        }
Example #9
0
        public void Update(GameTime gameTime, Camera gameCamera, Map gameMap, List<int> levelSectors, Dictionary<int, MapObjectLayer> walkableLayers, Robot gameHero)
        {
            foreach (Robot r in Enemies)
            {
                r.Update(gameTime, gameCamera, gameMap, levelSectors, walkableLayers, gameHero);
                r.Position = Vector2.Clamp(r.Position, gameCamera.Position - (new Vector2(gameCamera.Width + 300f, gameCamera.Height*2) / 2), gameCamera.Position + (new Vector2(gameCamera.Width + 300f, gameCamera.Height*2) / 2));
            }

            for (int i = Enemies.Count - 1; i >= 0; i--)
            {
                if (Enemies[i].Dead) Enemies.RemoveAt(i);
            }
        }
Example #10
0
 public virtual void Use(int faceDir, float attackCharge, Robot gameHero)
 {
     coolDownTime = Cooldown;
 }
Example #11
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;
                            }

                        }
                    }
                }
            }
        }
Example #12
0
        internal void DoHit(Vector2 pos, float power, int face, Robot gameHero)
        {
            if (knockbackTime > 0) return;

            if (power > 5f && knockbackTime <= 0)
            {
                knockbackTime = (double)((power * 100f) / 2f);
                if (IsPlayer) knockbackTime *= 0.5;
                Speed.X = 10f * (float)face;

                if (jumping)
                {
                    jumping = false;
                    falling = true;
                }
            }

            if (IsPlayer)
                Health -= (power / 2f);
            else
            {
                gameHero.Score += (int)power;
                Health -= power;
            }

            AudioController.PlaySFX("hit" + (1 + rand.Next(3)).ToString(), 1f, -0.25f + ((float)rand.NextDouble() * 0.5f), 0f);
            AudioController.PlaySFX("thud", 0.8f,0f,0f);

            ParticleManager.Instance.AddHurt(Position + new Vector2(0,-75f), new Vector2((power/5f) * face,0f), landingHeight, tint);

            AIchargingAttack = false;
            attackCharge = 0f;

            if (Health <= 0)
            {
                AudioController.PlaySFX("powerdown", 0.5f, 0f, 0f);

                if (Item != null)
                {
                    Item.InWorld = true;
                    Item.Position = Position + new Vector2(0, -75);
                    Item.DroppedPosition = Position;
                    Item.Speed.Y = 2f;
                    Item = null;
                }

                if (!IsPlayer)
                {
                    gameHero.Score += 500;

                    if ((int)gameHero.Health < 120)
                    {
                        for (int i = 0; i < ((120 - (int)gameHero.Health)/2) + (rand.Next((120 - (int)gameHero.Health)) / 2); i++)
                        {
                            ParticleManager.Instance.Add(ParticleType.Health, Position + new Vector2(0, -75f), (landingHeight - 10f) + ((float)rand.NextDouble() * 20f), new Vector2(-10f + ((float)rand.NextDouble() * 20f), 0), 2000, true, new Rectangle(11, 0, 15, 8), (float)rand.NextDouble() * MathHelper.TwoPi, Color.Red);
                        }
                    }
                }
            }
        }
Example #13
0
        internal void AttemptPickup(Robot robot)
        {
            if (robot.Item != null)
            {
                Item dropItem = robot.Item;
                robot.Item = null;
                dropItem.InWorld = true;
                dropItem.Position = robot.Position + new Vector2(0, 0);
                dropItem.DroppedPosition = robot.Position;
                AudioController.PlaySFX("pickup", 1f, 0f, 0f);

            }
            else
            {
                foreach (Item i in Items.OrderBy(it => (it.Position-robot.Position).Length()))
                {
                    if (i.Health > 0f && !i.Dead && i.InWorld)
                    {
                        if (i.Position.X > robot.Position.X - 75f && i.Position.X < robot.Position.X + 75f)
                        {
                            if (i.Position.Y > robot.landingHeight - 30f && i.Position.Y < robot.landingHeight + 30f)
                            {
                                i.InWorld = false;
                                robot.Item = i;
                                i.Owner = robot;
                                AudioController.PlaySFX("pickup", 1f, 0f, 0f);

                                break;
                            }
                        }
                    }
                }
            }
        }
Example #14
0
        public void Update(GameTime gameTime, Camera gameCamera, Map gameMap, List<int> levelSectors, Dictionary<int, MapObjectLayer> walkableLayers, Robot gameHero)
        {
            foreach (Item i in Items)
            {
                i.Update(gameTime);
            }

            for (int i = Items.Count - 1; i >= 0; i--)
            {
                if (Items[i].Dead) Items.RemoveAt(i);
            }
        }
Example #15
0
        public void Update(GameTime gameTime, Robot gameHero, Map gameMap, List<int> levelSectors, Dictionary<int, MapObjectLayer> walkableLayers)
        {
            foreach (Particle p in Particles.Where(part => part.Active))
            {

                p.Life -= gameTime.ElapsedGameTime.TotalMilliseconds;

                if (p.Life > 0 || (p.Alpha>0f && p.Type!= ParticleType.Health))
                {
                    p.Position += p.Velocity;
                    p.Rotation += p.RotationSpeed;

                    if (p.AffectedByGravity) p.Velocity.Y += 0.2f;

                    if (p.Position.Y >= p.LandingHeight)
                    {
                        p.Velocity.Y = -(p.Velocity.Y / 2);
                        p.Velocity.X /= (2f + (float)Rand.NextDouble());
                        p.RotationSpeed = 0f;
                    }
                }

                if (p.AffectedByGravity)
                    if (CheckCollision(p.Position, p.LandingHeight, gameMap, levelSectors, walkableLayers, gameHero.Sector)) p.Velocity.X = 0f;

                if (p.Type != ParticleType.Health)
                {
                    if (p.Life <= 0)
                    {
                        p.Alpha -= 0.01f;
                        if (p.Alpha < 0.05f) p.Active = false;
                    }
                }

                switch (p.Type)
                {
                    case ParticleType.Health:
                        if ((p.Position - gameHero.Position).Length() < 200 && p.Velocity.Length()<1f && p.Life<=0 && !gameHero.Dead)
                        {
                            p.Position = Vector2.Lerp(p.Position, gameHero.Position + new Vector2(0, -75f), 0.1f);
                            if ((p.Position - (gameHero.Position + new Vector2(0, -75f))).Length() < 50f)
                            {
                                p.Alpha = 0f;
                                p.Active = false;
                                gameHero.Health += 1f;
                                if ((int)gameHero.Health > 121) gameHero.Score += 5;
                                gameHero.Health = MathHelper.Clamp(gameHero.Health, 0f, 121f);

                                AudioController.PlaySFX("health",0.5f,-0.25f + ((float)Rand.NextDouble()*0.5f), 0f);

                            }
                        }
                        break;
                }
            }
        }
Example #16
0
        /// <summary>
        /// LoadContent will be called once per game and is the place to load
        /// all of your content.
        /// </summary>
        protected override void LoadContent()
        {
            // Create a new SpriteBatch, which can be used to draw textures.
            spriteBatch = new SpriteBatch(GraphicsDevice);

            AudioController.LoadContent(Content);

            gameMap = Content.Load<Map>("testmap");

            enemyManager.LoadContent(Content, GraphicsDevice);
            itemManager.LoadContent(Content, GraphicsDevice);
            projectileManager.LoadContent(Content);
            particleManager.LoadContent(Content);
            gameHud = new HUD(GraphicsDevice.Viewport);
            gameHud.LoadContent(Content);

            parallaxManager = new ParallaxManager(GraphicsDevice.Viewport);
            parallaxManager.Layers.Add(new ParallaxLayer(Content.Load<Texture2D>("bg/bg0"), new Vector2(0, 0), 0.25f, false, Color.White * 0.75f));
            parallaxManager.Layers.Add(new ParallaxLayer(Content.Load<Texture2D>("bg/bg1"), new Vector2(0, 0), 0.15f, false, Color.White * 0.75f));

            for (int i = 0; i < NUM_SECTORS; i++)
            {
                WalkableLayers.Add(i, gameMap.GetLayer("Walkable" + i) as MapObjectLayer);
            }

            gameHero = new Robot(Helper.PtoV((gameMap.GetLayer("Spawn") as MapObjectLayer).Objects[0].Location.Center), true);
            gameHero.LoadContent(Content, GraphicsDevice);

            gameCamera = new Camera(GraphicsDevice.Viewport, gameMap);

            skyTex = Content.Load<Texture2D>("sky");
            titleTex = Content.Load<Texture2D>("title");

            font = Content.Load<SpriteFont>("font");

            ResetGame();

            currentSectorColor = sectorColors[0];

            showingTitleScreen = true;
        }
Example #17
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;
        }