示例#1
0
        // This is to be private. Only the FOVManager should update.
        private void UpdateFOV(IMapCore map, Point viewPoint, int viewableDistance)
        {
            // We do +2 just to make sure we don't get any border effects. 
            int viewableRadius = viewableDistance + 2;

            // We're going to only setup an area around the viewPoint as "viewable" if it is, so we don't 
            // have to traverse the entire map. 
            Point upperLeftPointViewRange = map.CoercePointOntoMap(viewPoint - new Point(viewableRadius, viewableRadius));
            Point lowerRightPointViewRange = map.CoercePointOntoMap(viewPoint + new Point(viewableRadius, viewableRadius));
            Point viewRange = lowerRightPointViewRange - upperLeftPointViewRange;

            m_physicsMap.Clear();

            for (int i = upperLeftPointViewRange.X; i < upperLeftPointViewRange.X + viewRange.X; ++i)
            {
                for (int j = upperLeftPointViewRange.Y; j < upperLeftPointViewRange.Y + viewRange.Y; ++j)
                {
                    bool isFloor = map.GetTerrainAt(i, j) == TerrainType.Floor;
                    m_physicsMap.Cells[i, j].Transparent = isFloor;
                }
            }

            foreach (MapObject obj in map.MapObjects.Where(x => x.IsSolid))
            {
                m_physicsMap.Cells[obj.Position.X, obj.Position.Y].Transparent = obj.IsTransarent;
            }

            foreach (Monster m in map.Monsters)
            {
                m_physicsMap.Cells[m.Position.X, m.Position.Y].Transparent = false;
            }
        }