Esempio n. 1
0
 public void ClearMap()
 {
     for (int x = 0; x < TileLayer.Width; x++)
     {
         for (int y = 0; y < TileLayer.Height; y++)
         {
             if (TileLayer.GetCellMovability(x, y))
             {
                 distanceMap[x, y] = float.MaxValue;
             }
             else
             {
                 distanceMap[x, y] = -1.0f;
             }
         }
     }
 }
Esempio n. 2
0
        // Return true on collision
        public static bool RayTest(Vector2 startPos, Vector2 endPos)
        {
            for (int x = 0; x < TileLayer.Width; x++)
            {
                for (int y = 0; y < TileLayer.Height; y++)
                {
                    if (!TileLayer.GetCellMovability(x, y))
                    {
                        if (SegmentIntersectRectangle(new Vector2(x, y), new Vector2(x + 1, y + 1), startPos, endPos))
                        {
                            return(true);
                        }
                    }
                }
            }

            return(false);
        }
Esempio n. 3
0
        public static TileLayer FromFile(ContentManager content, string fileName)
        {
            TileLayer          tileLayer;
            bool               readingPassable    = false;
            bool               readingNonPassable = false;
            bool               readingLevelMap    = false;
            List <TextureType> textureNames       = new List <TextureType>();
            List <List <int> > tempLayout         = new List <List <int> >();
            List <int>         passTiles          = new List <int>();
            List <int>         nonpassTiles       = new List <int>();

            using (StreamReader reader = new StreamReader(fileName))
            {
                while (!reader.EndOfStream)
                {
                    string line = reader.ReadLine().Trim();

                    if (string.IsNullOrEmpty(line))
                    {
                        continue;
                    }

                    if (line.Contains("[Passable]"))
                    {
                        readingPassable    = true;
                        readingNonPassable = false;
                        readingLevelMap    = false;
                    }
                    else if (line.Contains("[NonPassable]"))
                    {
                        readingPassable    = false;
                        readingNonPassable = true;
                        readingLevelMap    = false;
                    }
                    else if (line.Contains("[LevelMap]"))
                    {
                        readingPassable    = false;
                        readingNonPassable = false;
                        readingLevelMap    = true;
                    }
                    else if (line.Contains("[Character]") ||
                             line.Contains("[Enemy]") ||
                             line.Contains("[Pickups]"))
                    {
                        readingPassable    = false;
                        readingNonPassable = false;
                        readingLevelMap    = false;
                    }
                    else if (readingPassable || readingNonPassable)
                    {
                        textureNames.Add(new TextureType(line, readingPassable));
                    }
                    else if (readingLevelMap)
                    {
                        List <int> row = new List <int>();

                        string[] cells = line.Split(' ');

                        foreach (string c in cells)
                        {
                            if (!string.IsNullOrEmpty(c))
                            {
                                row.Add(int.Parse(c));
                            }
                        }

                        tempLayout.Add(row);
                    }
                }
            }

            int width  = tempLayout[0].Count;
            int height = tempLayout.Count;

            tileLayer = new TileLayer(width, height);

            for (int y = 0; y < height; y++)
            {
                for (int x = 0; x < width; x++)
                {
                    tileLayer.SetCellIndex(x, y, tempLayout[y][x]);
                }
            }

            tileLayer.LoadTileTextures(content, textureNames);


            navMap.Allocate();
            navMap.CalculateWeightMap(0, 0);

            return(tileLayer);
        }