private void TryMove(Collide c)
 {
     if (Collide.CanMove(c, map.CurrenStage))
     {
         player.Location = c;
     }
 }
Example #2
0
 // Ctor
 public Player(double posIni)
 {
     Velocity = 4;
     Img      = new Rectangle {
         Width  = SIZE,
         Height = SIZE,
         Fill   = Brushes.Yellow
     };
     Location = new Collide(posIni, posIni, SIZE + posIni, SIZE + posIni);
     Canvas.SetTop(Img, Location.Y1);
     Canvas.SetLeft(Img, Location.X1);
 }
Example #3
0
        // Estático.
        public static bool CanMove(Collide l, List <Collide> map)
        {
            bool result = true;
            int  pos    = 0;

            while (pos < map.Count && result)
            {
                // Comprueba si hay intersección entre dos cuadrados.
                result = !((map[pos].X2 > l.X1 && map[pos].X1 < l.X2) && (map[pos].Y2 > l.Y1 && map[pos].Y1 < l.Y2));

                // Si no hay intersección entre dos cuadrados, comprueba si está dentro de otro.
                if (result)
                {
                    result = !(l.X1 >= map[pos].X1 && l.Y1 >= map[pos].Y1 && l.X2 <= map[pos].X2 && l.Y2 <= map[pos].Y2);
                }
                pos++;
            }
            return(result);
        }
Example #4
0
        public Collide Copy()
        {
            Collide copy = (Collide)this.MemberwiseClone();

            return(copy);
        }