Beispiel #1
0
        private void AddColliderIfNeeded(MapColliderContext colliderContext, int x, int y)
        {
            if (map.IsEmpty(x, y))
            {
                return;
            }

            AddColliderIfOnSide(colliderContext, x, y);
            colliderContext.Flush();
        }
Beispiel #2
0
        public IEnumerable <Vector2[]> GetCollisionPoints(int fromY, int toY)
        {
            var colliderContext = new MapColliderContext(map.Configuration.width, toY - fromY, fromY);

            for (int y = fromY; y < toY; y++)
            {
                for (int x = 0; x < map.Configuration.width; x++)
                {
                    AddColliderIfNeeded(colliderContext, x, y);
                }
            }
            return(colliderContext.GetCollisionPoints());
        }
Beispiel #3
0
        private void AddColliderIfOnSide(MapColliderContext colliderContext, int x, int y)
        {
            bool shouldAddCollider = false;

            shouldAddCollider |= map.IsEmpty(x - 1, y);
            shouldAddCollider |= map.IsEmpty(x + 1, y);
            shouldAddCollider |= map.IsEmpty(x, y - 1);
            shouldAddCollider |= map.IsEmpty(x, y + 1);

            if (shouldAddCollider)
            {
                colliderContext.AddSquareCollider(x, y);
            }
        }