Beispiel #1
0
        public Basic2DObject CheckCollision(Basic2DObject Tester)
        {
            Vector2 MinPosition = (Tester.getUpperLeftCorner() - Min) / CellSize;
            Vector2 MaxPosition = (Tester.getLowerRightCorner() - Min) / CellSize;

            int MinCellX = (int)MathHelper.Clamp(MinPosition.X, 0, CellsX);
            int MinCellY = (int)MathHelper.Clamp(MinPosition.Y, 0, CellsY);
            int MaxCellX = (int)MathHelper.Clamp(MaxPosition.X, 0, CellsX) + 1;
            int MaxCellY = (int)MathHelper.Clamp(MaxPosition.Y, 0, CellsY) + 1;

            for (int x = MinCellX; x < MaxCellX; x++)
            {
                for (int y = MinCellY; y < MaxCellY; y++)
                {
                    Basic2DObject g = null;
                    g = Children[x, y].CheckCollision(Tester);

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

            return(null);
        }
Beispiel #2
0
        private void commitWorldBlocker(Basic2DObject w)
        {
            Vector2 UpperLeftCorner  = (w.getUpperLeftCorner() - Parent2DScene.MinBoundary.get()) / Divisor + new Vector2(0.5f);
            Vector2 LowerRightCorner = (w.getLowerRightCorner() - Parent2DScene.MinBoundary.get()) / Divisor + new Vector2(0.5f);
            Vector2 Center           = (w.getLowerRightCorner() - Parent2DScene.MinBoundary.get()) / Divisor;

            int MinX = (int)UpperLeftCorner.X;
            int MinY = (int)UpperLeftCorner.Y;
            int MaxX = (int)LowerRightCorner.X;
            int MaxY = (int)LowerRightCorner.Y;

            for (int x = MinX; x < MaxX + 1; x++)
            {
                for (int y = MinY; y < MaxY + 1; y++)
                {
                    CellGrid[x, y] = DeadCell;
                }
            }

            if (w.GetType().Equals(typeof(WallNode)))
            {
                WallNode s = (WallNode)w;
                if (s.wallConnector != null)
                {
                    UpperLeftCorner  = Logic.Min(UpperLeftCorner, (s.wallConnector.PositionNext - s.Size.get() / 2 - Parent2DScene.MinBoundary.get()) / Divisor + new Vector2(0.5f));
                    LowerRightCorner = Logic.Max(LowerRightCorner, (s.wallConnector.PositionNext + s.Size.get() / 2 - Parent2DScene.MinBoundary.get()) / Divisor + new Vector2(0.5f));

                    MinX = (int)UpperLeftCorner.X;
                    MinY = (int)UpperLeftCorner.Y;
                    MaxX = (int)LowerRightCorner.X;
                    MaxY = (int)LowerRightCorner.Y;

                    for (int x = MinX; x < MaxX + 1; x++)
                    {
                        for (int y = MinY; y < MaxY + 1; y++)
                        {
                            if (Logic.DistanceLineSegmentToPoint(s.Position.get(), s.wallConnector.PositionNext,
                                                                 (new Vector2(x, y) - new Vector2(0.5f)) * Divisor + Parent2DScene.MinBoundary.get()) < w.Size.X())
                            {
                                CellGrid[x, y] = DeadCell;
                            }
                        }
                    }
                }
            }
        }