Пример #1
0
        /// <summary>
        /// Calculates the Z Coordinate in World Units at the given Position.
        /// </summary>
        /// <param name="point">Koordinate</param>
        /// <returns>Z Coordinate</returns>
        public float GetHeight(Vector2 point)
        {
            if (Tiles == null)
            {
                throw new NotSupportedException("Map is not Initialized");
            }

            // Determinate the right Cell
            Index2 cellCount = GetCellCount();
            Index2 cell      = Map.GetCellIndex(point, cellCount);

            // Calculate Height based on the Cell Type
            return(Map.GetHeight(Tiles[cell.X, cell.Y],
                                 new Vector2(
                                     point.X - (cell.X * Map.CELLSIZE),
                                     point.Y - (cell.Y * Map.CELLSIZE))));
        }
Пример #2
0
        /// <summary>
        ///     Ermittelt die Zelle, in der sich die angegebene Position gefindet
        ///     und limitiert das Ergebnis auf die verfügbaren Zellen.
        /// </summary>
        /// <param name="position">Gegebene Position</param>
        /// <param name="cellCount">Zellenmenge</param>
        /// <returns>Zellenindex</returns>
        public static Index2 GetCellIndex(Vector2 position, Index2 cellCount)
        {
            var indexX = (int)(position.X / CELLSIZE);
            var indexY = (int)(position.Y / CELLSIZE);

            if (indexX < 0)
            {
                indexX = 0;
            }
            if (indexY < 0)
            {
                indexY = 0;
            }
            if (indexX >= cellCount.X)
            {
                indexX = cellCount.X - 1;
            }
            if (indexY >= cellCount.Y)
            {
                indexY = cellCount.Y - 1;
            }

            return(new Index2(indexX, indexY));
        }
Пример #3
0
        /// <summary>
        ///     Führt eine Plausibilitätsprüfung der Karten-Einstellungen durch
        /// </summary>
        public void CheckMap()
        {
            // Tiles prüfen
            if (Tiles == null)
            {
                throw new InvalidMapException("Tiles Array is null");
            }

            Index2 cells = GetCellCount();

            // Karten Dimensionen checken
            if (cells.X < MIN_WIDTH)
            {
                throw new InvalidMapException(string.Format("Map must have at least {0} Columns", MIN_WIDTH));
            }
            if (cells.X > MAX_WIDTH)
            {
                throw new InvalidMapException(string.Format("Map must have a maximum of {0} Columns", MAX_WIDTH));
            }

            if (cells.Y < MIN_HEIGHT)
            {
                throw new InvalidMapException(string.Format("Map must have at least {0} Rows", MIN_HEIGHT));
            }
            if (cells.Y > MAX_HEIGHT)
            {
                throw new InvalidMapException(string.Format("Map must have a maximum of {0} Rows", MAX_HEIGHT));
            }

            // Startpunkte überprüfen
            if (StartPoints == null)
            {
                throw new InvalidMapException("The List of StartPoints is null");
            }

            // Spieleranzahl prüfen
            if (GetPlayerCount() < MIN_STARTPOINTS)
            {
                throw new InvalidMapException(string.Format("There must be at least {0} player", MIN_STARTPOINTS));
            }
            if (GetPlayerCount() > MAX_STARTPOINTS)
            {
                throw new InvalidMapException(string.Format("The maximum Player Count is {0}", MAX_STARTPOINTS));
            }

            // Alles Tiles prüfen
            string message;

            for (int y = 0; y < Tiles.GetLength(1); y++)
            {
                for (int x = 0; x < Tiles.GetLength(0); x++)
                {
                    if (!CheckCell(x, y, out message))
                    {
                        throw new InvalidMapException(string.Format("Cell {0}/{1} has the following Error: {2}", x, y,
                                                                    message));
                    }
                }
            }

            // Alle Startpunkte überprüfen
            for (int i = 0; i < StartPoints.Length; i++)
            {
                // Prüfen, ob die Zelle existiert
                Index2 startPoint = StartPoints[i];
                if (startPoint.X < 0 || startPoint.X >= Tiles.GetLength(0) ||
                    startPoint.Y < 0 || startPoint.Y >= Tiles.GetLength(1))
                {
                    throw new InvalidMapException(string.Format("StartPoint {0} is out of map bounds", i));
                }

                // Prüfen, ob es sich um eine flache Zelle handelt
                if (Tiles[startPoint.X, startPoint.Y].Shape != TileShape.Flat)
                {
                    throw new InvalidMapException(string.Format("StartPoint {0} is not placed on a plane Cell", i));
                }

                // Prüfen, ob noch ein anderer Startpoint auf der selben Zelle ist.
                for (int j = 0; j < StartPoints.Length; j++)
                {
                    if (i != j && StartPoints[i] == StartPoints[j])
                    {
                        throw new InvalidMapException(string.Format("StartPoints {0} and {1} are on the same Cell", i, j));
                    }
                }
            }
        }
Пример #4
0
        /// <summary>
        /// Calculcates the real Map Size in World Units.
        /// </summary>
        /// <returns>Size of tha Map in World Units</returns>
        public Vector2 GetSize()
        {
            Index2 cells = GetCellCount();

            return(new Vector2(cells.X * Map.CELLSIZE, cells.Y * Map.CELLSIZE));
        }