예제 #1
0
        /// <summary>
        /// Gets the cell ID for a position within a landblock
        /// </summary>
        public static uint GetCell(this Position p)
        {
            var landblock = LScape.get_landblock(p.LandblockId.Raw);

            // dungeons
            // TODO: investigate dungeons that are below actual traversable overworld terrain
            // ex., 010AFFFF
            //if (landblock.IsDungeon)
            if (p.Indoors)
            {
                return(GetIndoorCell(p));
            }

            // outside - could be on landscape, in building, or underground cave
            var cellID   = GetOutdoorCell(p);
            var landcell = LScape.get_landcell(cellID) as LandCell;

            if (landcell == null)
            {
                return(cellID);
            }

            if (landcell.has_building())
            {
                var envCells = landcell.Building.get_building_cells();
                foreach (var envCell in envCells)
                {
                    if (envCell.point_in_cell(p.Pos))
                    {
                        return(envCell.ID);
                    }
                }
            }

            // handle underground areas ie. caves
            // get the terrain Z-height for this X/Y
            Physics.Polygon walkable    = null;
            var             terrainPoly = landcell.find_terrain_poly(p.Pos, ref walkable);

            if (walkable != null)
            {
                Vector3 terrainPos = p.Pos;
                walkable.Plane.set_height(ref terrainPos);

                // are we below ground? if so, search all of the indoor cells for this landblock
                if (terrainPos.Z > p.Pos.Z)
                {
                    var envCells = landblock.get_envcells();
                    foreach (var envCell in envCells)
                    {
                        if (envCell.point_in_cell(p.Pos))
                        {
                            return(envCell.ID);
                        }
                    }
                }
            }

            return(cellID);
        }
예제 #2
0
        /// <summary>
        /// Returns TRUE if outdoor position is located on walkable slope
        /// </summary>
        public static bool IsWalkable(this Position p)
        {
            if (p.Indoors)
            {
                return(true);
            }

            var landcell = (LandCell)LScape.get_landcell(p.Cell);

            Physics.Polygon walkable    = null;
            var             terrainPoly = landcell.find_terrain_poly(p.Pos, ref walkable);

            if (walkable == null)
            {
                return(false);
            }

            return(Physics.PhysicsObj.is_valid_walkable(walkable.Plane.Normal));
        }
예제 #3
0
        public static float GetTerrainZ(this Position p)
        {
            var cellID   = GetOutdoorCell(p);
            var landcell = (LandCell)LScape.get_landcell(cellID);

            if (landcell == null)
            {
                return(p.Pos.Z);
            }

            Physics.Polygon walkable = null;
            if (!landcell.find_terrain_poly(p.Pos, ref walkable))
            {
                return(p.Pos.Z);
            }

            Vector3 terrainPos = p.Pos;

            walkable.Plane.set_height(ref terrainPos);

            return(terrainPos.Z);
        }
예제 #4
0
        // TODO change return type to void?
        public string LoadLevel(XDocument xDoc, ref Vector2 startingCenterScreenPos)
        {
            isLevelLoaded = false;
            try
            {
                //XDocument xDoc = XDocument.Load(fileName);
                XElement curElement, childElement;
                curElement = xDoc.Root.Element("BasicInfo");
                levelName = curElement.Element("Name").Value;
                pxWidth = uint.Parse(curElement.Element("Width").Value);
                pxHeight = uint.Parse(curElement.Element("Height").Value);
                childElement = curElement.Element("StartingScreenPos");
                startingCenterScreenPos.X = uint.Parse(childElement.Element("X").Value);
                startingCenterScreenPos.Y = uint.Parse(childElement.Element("Y").Value);

                curElement = xDoc.Root.Element("Backgrounds");
                numBackgroundLayers = (uint)curElement.Attribute("NumLayers");
                backgroundRowTiles = new uint[numBackgroundLayers];
                backgroundRowColumns = new uint[numBackgroundLayers];
                backgrounds = new BackgroundTile[numBackgroundLayers][][];
                if (numBackgroundLayers > 0)
                {
                    IEnumerable<XElement> bgList = curElement.Elements("Background");
                    foreach (XElement bgElem in bgList)
                    {
                        uint layerNum, numRows, numColumns;
                        string texturePath;
                        layerNum = uint.Parse(bgElem.Element("Layer").Value);
                        texturePath = bgElem.Element("TexturePath").Value;
                        numColumns = uint.Parse(bgElem.Element("NumColumns").Value);
                        numRows = uint.Parse(bgElem.Element("NumRows").Value);
                        Texture2D tempTexture = contentManager.Load<Texture2D>(texturePath);
                        backgroundRowTiles[layerNum] = numColumns;
                        backgroundRowColumns[layerNum] = numRows;
                        //Initialize the tiles for this layer
                        backgrounds[layerNum] = new BackgroundTile[numColumns][];
                        for (uint x = 0; x < numColumns; ++x)
                        {
                            backgrounds[layerNum][x] = new BackgroundTile[numRows];
                            for (uint y = 0; y < numRows; ++y)
                            {
                                backgrounds[layerNum][x][y] = new BackgroundTile(tempTexture, x, y);
                            }
                        }
                    }
                } // if (numBackgroundLayers > 0)
                // TODO verify starting position is in level
                // TODO verify total level width and height are greater than our max resolution

                Vector2[] offsets = new Vector2[4];
                offsets[0] = new Vector2(0, 0);
                offsets[1] = new Vector2(0, pxHeight);
                offsets[2] = new Vector2(pxWidth, pxHeight);
                offsets[3] = new Vector2(pxWidth, 0);
                Physics.Polygon tempPoly = new Physics.Polygon(Vector2.Zero, offsets, Vector2.Zero, 4, true);
                collisionPolygons.Add(tempPoly);

                foreach (Physics.Polygon poly in collisionPolygons)
                    poly.SetPosition(Vector2.Zero, Vector2.Zero, 0);
            }
            catch (Exception ex)
            {
                //TODO log
                //Error loading the level
                //TODO show messagebox
                Environment.Exit(0);
            }
            isLevelLoaded = true;
            return null;
        }