Ejemplo n.º 1
0
 //Returns a list of loot the player should get
 public List<Item> LootMe(Player player)
 {
     List<Item> Looted = new List<Item>();
     if (YesLootable)
     {
         foreach (Item I in Loot)
         {
             if (_r.Next(0, 2) == 1) //Give 1/3 of the possible loot
             {
                 Looted.Add(I);
                 if (_r.Next(1, 3) == 2)
                 {
                     player.PistolAmmo += _r.Next(0, 2) * 12;
                 }
             }
         }
         YesLootable = false;
     }
     return Looted;
 }
Ejemplo n.º 2
0
        public void Update(ref List<Bullet> bullets, Texture2D imgB, Player player, ref List<Zombie> zombies, ref List<NumberFloat> numberfloats, Texture2D sNumberFloat)
        {
            bool wasstopped = false;
            double range = Math.Abs(Math.Sqrt((Pos.X - player.Pos.X) * (Pos.X - player.Pos.X) + (Pos.Y - player.Pos.Y) * (Pos.Y - player.Pos.Y)));
            UpdateFrame();
            Animating = 0;
            /*
            foreach (Zombie Z in zombies)
            {
                if (!(Z == this))
                {
                     range = Math.Abs(Math.Sqrt((Pos.X - player.Pos.X) * (Pos.X - player.Pos.X) + (Pos.Y - player.Pos.Y) * (Pos.Y - player.Pos.Y)));
                     double zrange = Math.Abs(Math.Sqrt((player.Pos.X - Z.Pos.X) * (player.Pos.X - Z.Pos.X) + (player.Pos.Y - Z.Pos.Y) * (player.Pos.Y - Z.Pos.Y)));
                     if (range > zrange && range-zrange < 10 && range < 20)
                     {
                         Pos.Y += (float)new Random().Next(-30, 30) / 10; // add random
                         Pos.X += (float)new Random().Next(-30, 30) / 10; // add random
                         wasstopped = true;
                     }
                }
            }
             */
            if (range < 850)
            {
                if (TimeToStrike == 0 && range < 20)
                {
                    TimeToStrike = 3;
                    if (player.Health <= 0)
                    {
                        //DEAD
                    }
                    else
                    {
                        player.Health -= (float)Math.Round(Damage);
                        numberfloats.Add(new NumberFloat(player.Pos, sNumberFloat, new Point(0, 0), (int)Math.Round(Damage), new Color(255, 122, 0)));
                    }
                }
                if (TimeToStrike > 0)
                {
                    TimeToStrike -= 0.1f;
                    if (TimeToStrike < 0.1)
                    {
                        TimeToStrike = 0;
                    }
                }
                if (!(range < 10 || wasstopped))
                {
                    if (TimeToTrip == 0)
                    {
                        TimeToTrip = TripRand.Next(10, 20) / 10;
                        TripSpeed = TripRand.Next(-30, 60) / 50; //tweak this for speed difference
                    }
                    if (TimeToTrip > 0)
                    {
                        TimeToTrip -= 0.1f;
                        if (TimeToTrip < 0.1)
                        {
                            TimeToTrip = 0;
                        }
                    }
                    if (TimeToTrip < 0.25)
                        TripSpeed = 0;

                    Xmovement = 0;
                    //move towards player's X axis
                    Xmovement -= ((Pos.X - player.Pos.X) / Math.Abs((Pos.X - player.Pos.X))) * Math.Min(0.5, Math.Abs((Pos.X - player.Pos.X)) * 0.03);
                    //move away from zombie's X axis
                    foreach (Zombie Z in zombies)
                    {
                        if (!(Z == this))
                        {
                            double zrange = Math.Abs(Math.Sqrt((Pos.X - Z.Pos.X) * (Pos.X - Z.Pos.X) + (Pos.Y - Z.Pos.Y) * (Pos.Y - Z.Pos.Y)));
                            if (zrange < 15)
                            {
                                Xmovement -= ((Pos.X - Z.Pos.X) / Math.Abs((Pos.X - Z.Pos.X))) * Math.Min(0.5, Math.Abs((Pos.X - Z.Pos.X)) * 0.03) * -1;
                            }
                        }
                    }
                    if (player.Pos.X > Pos.X)
                    {
                        Dir = "East";
                        Xmovement += TripSpeed;
                        Animating = 1;
                    }
                    if (player.Pos.X < Pos.X)
                    {
                        Dir = "West";
                        Xmovement -=TripSpeed;
                        Animating = 1;
                    }
                    Pos.X += (float)Xmovement;
                    Ymovement = 0;
                    //move towards player's Y axis
                    Ymovement -= ((Pos.Y - player.Pos.Y) / Math.Abs((Pos.Y - player.Pos.Y)))*Math.Min( 0.5, Math.Abs((Pos.Y - player.Pos.Y)) * 0.03);
                    //move away from zombie's Y axis
                    foreach (Zombie Z in zombies)
                    {
                        if (!(Z == this))
                        {
                            double zrange = Math.Abs(Math.Sqrt((Pos.X - Z.Pos.X) * (Pos.X - Z.Pos.X) + (Pos.Y - Z.Pos.Y) * (Pos.Y - Z.Pos.Y)));
                            if (zrange < 15)
                            {
                                Ymovement -= ((Pos.Y - Z.Pos.Y) / Math.Abs((Pos.Y - Z.Pos.Y))) * Math.Min(0.5, Math.Abs((Pos.Y - Z.Pos.Y)) * 0.03) *-1;
                            }
                        }
                    }
                    Pos.Y += (float)Ymovement;
                    /*
                    if (player.Pos.Y > Pos.Y)
                    {
                        Pos.Y += 0.5f + TripSpeed;
                        Animating = 1;
                    }
                    if (player.Pos.Y < Pos.Y)
                    {
                        Pos.Y -= 0.5f + TripSpeed;
                        Animating = 1;
                    }
                     */
                }

            }
            int i = -1;
            while (i < bullets.Count() - 1)
            {
                i += 1;
                if (bullets[i].Pos.X > Pos.X - FrameWidth / 2) if (bullets[i].Pos.Y > Pos.Y - FrameHeight)
                    {
                        if (bullets[i].Pos.X < Pos.X + FrameWidth / 2) if (bullets[i].Pos.Y < Pos.Y)
                            {
                                Health -= (float)Math.Round(bullets[i].Damage);
                                numberfloats.Add(new NumberFloat(Pos, sNumberFloat, new Point(0, 0), (int)Math.Round(bullets[i].Damage), new Color(255, 0, 0)));
                                bullets[i].Damage = (float)Math.Round((double)Damage / 2) - 1;
                                bullets[i].Pos.X -= 24;
                                if (bullets[i].Damage < 4)
                                {
                                    bullets.RemoveAt(i);
                                }
                                if (Health <= 0)
                                {
                                    zombies.Remove(this);
                                }
                            }
                    }
            }
        }