Exemplo n.º 1
0
 public Viewport(int x, int y, Element target, int width, int height)
 {
     this.X = x;
     this.Y = y;
     this.TrackTarget = target;
     this.Width = width;
     this.Height = height;
 }
Exemplo n.º 2
0
        private static GameScreen FindGameScreenForElement(GameScreen gameScreen, Element e)
        {
            var level = gameScreen;

            if (level.Elements.Contains(e))
                return level;

            foreach (GameScreen gs in gameScreen.Children)
            {
                var result = FindGameScreenForElement(gs, e);

                if (result != null)
                {
                    return result;
                }
            }

            return null;
        }
Exemplo n.º 3
0
        private static void RemoveScreenElement(Element element)
        {
            var screen = FindGameScreenForElement(ExGame.GameRef.GameScreen, element);

            if (screen != null)
            {
                FindGameScreenForElement(ExGame.GameRef.GameScreen, element).Elements.Remove(element);
            }
        }
Exemplo n.º 4
0
        public static bool CheckIntersect(Element a, Rectangle rect)
        {
            if (a.IsBackgroundElement)
                return false;

            var ax = a.X;
            var ay = a.Y;
            var aw = a.Sprite.Width;
            var ah = a.Sprite.Height;

            var bx = rect.X;
            var by = rect.Y;
            var bw = rect.Width;
            var bh = rect.Height;

            if (
                (ax >= bx && ax <= bx + bw) // top left dot lies within b horizontally
                &&
                (ay >= by && ay <= by + bh) // top left dot lies within b vertically
            )
            {
                return true;
            }

            if (
                (ax + aw >= bx && ax + aw <= bx + bw) // top right dot lies within b horizontally
                &&
                (ay >= by && ay <= by + bh) // top right dot lies within b vertically
            )
            {
                return true;
            }

            if (
                (ax + aw >= bx && ax + aw <= bx + bw) // bottom right dot lies within b horizontally
                &&
                (ay + ah >= by && ay + ah <= by + bh) // bottom right dot lies within b vertically
            )
            {
                return true;
            }

            if (
                (ax >= bx && ax <= bx + bw) // bottom left dot lies within b horizontally
                &&
                (ay + ah >= by && ay + ah <= by + bh) // bottom left dot lies within b vertically
            )
            {
                return true;
            }

            // repeat tests in reverse in case a encompasses b

            if (
                (bx >= ax && bx <= ax + aw) // top left dot lies within a horizontally
                &&
                (by >= ay && by <= ay + ah) // top left dot lies within a vertically
            )
            {
                return true;
            }

            if (
                (bx + bw >= ax && bx + bw <= ax + aw) // bottom right dot lies within b horizontally
                &&
                (by + bh >= ay && by + bh <= ay + ah) // bottom right dot lies within b vertically
            )
            {
                return true;
            }

            if (
                (bx + bw >= ax && bx + bw <= ax + aw) // top right dot lies within b horizontally
                &&
                (by >= ay && by <= ay + ah) // top right dot lies within b vertically
            )
            {
                return true;
            }

            if (
                (bx >= ax && bx <= ax + aw) // bottom left dot lies within b horizontally
                &&
                (by + bh >= ay && by + bh <= ay + ah) // bottom left dot lies within b vertically
            )
            {
                return true;
            }

            return false;
        }
Exemplo n.º 5
0
        public static List<Element> GetIntersections(Element a, List<Type> types)
        {
            List<Element> IntersectionList = new List<Element>();

            foreach (Element e in GetScreenElements().Where(c => types.Contains(c.GetType())))
            {
                if (CheckIntersect(a, e))
                    IntersectionList.Add(e);
            }

            return IntersectionList;
        }
Exemplo n.º 6
0
        public static List<Element> GetIntersections(Element a, List<Element> elements)
        {
            List<Element> IntersectionList = new List<Element>();

            foreach (Element e in elements)
            {
                if (CheckIntersect(a, e))
                    IntersectionList.Add(e);
            }

            return IntersectionList;
        }
Exemplo n.º 7
0
        public static List<Element> GetIntersections(Element a)
        {
            List<Element> IntersectionList = new List<Element>();

            foreach (Element e in GetScreenElements().Where(c => !c.Equals(a)))
            {
                if (CheckIntersect(a, e))
                    IntersectionList.Add(e);
            }

            return IntersectionList;
        }
Exemplo n.º 8
0
 public static bool CheckIntersect(Element a, Element b)
 {
     return CheckIntersect(a, new Rectangle(b.X, b.Y, b.Sprite.Width, b.Sprite.Height));
 }