Category5.MegaTile.tryAddingVictim C# (CSharp) Метод

tryAddingVictim() приватный Метод

private tryAddingVictim ( VictimConfig vc ) : bool
vc VictimConfig
Результат bool
        private bool tryAddingVictim(VictimConfig vc)
        {
            rand.Next();

            //Pick random location to try adding the victim
            int maxWidth = bounds.Left + bounds.Width - vc.GroundAnim.FrameWidth;
            if (maxWidth < bounds.Left)
                maxWidth = bounds.Left;
            int maxHeight = bounds.Top + bounds.Height - vc.GroundAnim.FrameHeight;
            if (maxHeight < bounds.Top)
                maxHeight = bounds.Top;
            Vector2 randomLoc = new Vector2(rand.Next(bounds.Left, maxWidth),
                 rand.Next(bounds.Top, maxHeight));

            //check for collisions with existing objects
            //If a collision is found, return failure
            foreach (Victim v in victims)
            {
                if(v.Bounds.Intersects(new Rectangle2D(randomLoc.X, randomLoc.Y,
                vc.GroundAnim.FrameWidth, vc.GroundAnim.FrameHeight))){
                    return false;
                }
            }

            //Put the victim in a random location
            victims.Add(VictimFactory.CreateVictimOfClass(vc,
                randomLoc, this));

            //Check for a boss victim and notify level if one is created
            if (vc.VictimClass == VictimClass.BOSS)
            {
                level.NumberBossesAlive += 1;
            }

            return true;
        }