Exemplo n.º 1
0
        public bool PlaceAt(int x, int y, Map map)
        {
            if (x >= 0 && x < Map.MAP_WIDTH &&
                y >= 0 && y < Map.MAP_HEIGHT)
            {
                if (!_isOnMap || map != _currentMap)
                {
                    if (_currentMap != null)
                    {
                        _currentMap.RemoveLight(this);
                    }
                    _currentMap = map;
                    map.AddLight(this);
                    _tcodmap = new TCODMap(Map.MAP_WIDTH, Map.MAP_HEIGHT);
                    _tcodmap.copy(map.TCODMap);
                }
                PosX = x;
                PosY = y;
                _tcodmap.computeFov(PosX, PosY, _radius, true);
                _isOnMap = true;

                return(true);
            }
            return(false);
        }
Exemplo n.º 2
0
        public void BuildFOV(TCODMap viewmap, int xpos, int ypos)
        {
            float Distance;
            Point currentLoc = new Point(0, 0);
            Point playerLoc  = new Point(xpos, ypos);
            float intensity  = 0.0f;

            viewmap.clear(false, false);
            for (int x = 0; x < 300; x++)
            {
                for (int y = 0; y < 200; y++)
                {
                    viewmap.setProperties(x, y, this.Cells[x, y].Walkable, this.Cells[x, y].Walkable);
                }
            }
            viewmap.computeFov(xpos, ypos, 9, true, TCODFOVTypes.ShadowFov);

            for (int x = 0; x < 300; x++)
            {
                for (int y = 0; y < 200; y++)
                {
                    if (this.Cells[x, y].Visible == Visiblity.Visible)
                    {
                        this.Cells[x, y].Visible = Visiblity.Previously;
                    }
                    if (viewmap.isInFov(x, y))
                    {
                        this.Cells[x, y].Visible = Visiblity.Visible;
                    }
                    this.Cells[x, y].LightIntensity = 0.0f;
                }
            }

            for (int x = 0; x < 300; x++)
            {
                for (int y = 0; y < 200; y++)
                {
                    if (this.Cells[x, y].Visible == Visiblity.Visible)
                    {
                        currentLoc.Set(x, y);
                        Distance  = (float)currentLoc.Dist(playerLoc);
                        intensity = 0.5f - Distance / 12;
                        if (intensity < 0.0f)
                        {
                            intensity = 0.0f;
                        }
                        this.Cells[x, y].LightIntensity = intensity;
                    }

                    if (this.Cells[x, y].Visible == Visiblity.Visible)
                    {
                        this.Cells[x, y].Visible = Visiblity.Previously;
                    }
                    if (viewmap.isInFov(x, y))
                    {
                        this.Cells[x, y].Visible = Visiblity.Visible;
                    }
                }
            }
        }
Exemplo n.º 3
0
        public LightSource(Point Position, int Radius, TCODColor Colour, float Intensity, Map mapData)
        {
            float Distance;
            Point currentLoc       = new Point(0, 0);
            float workingIntensity = 0.0f;

            position  = new Point(Position);
            radius    = Radius;
            colour    = new TCODColor();
            colour    = Colour;
            intensity = Intensity;
            int mapSize = 1 + (Radius * 2);

            lightMap = new TCODMap(300, 200);
            lightMap.clear(false, false);

            //for (int dx = Position.X - Radius; dx <= Position.X + Radius; dx++)
            for (int dx = 0; dx < 300; dx++)
            {
                //for (int dy = Position.Y - Radius; dy <= Position.Y + Radius; dy++)
                for (int dy = 0; dy < 200; dy++)
                {
                    lightMap.setProperties(dx, dy, mapData.Cells[dx, dy].Walkable, mapData.Cells[dx, dy].Walkable);
                }
            }
            lightMap.computeFov(Position.X, Position.Y, Radius, true, TCODFOVTypes.ShadowFov);

            //for (int dx = Position.X - Radius; dx < Position.X + Radius; dx++)
            for (int dx = 0; dx < 300; dx++)
            {
                //for (int dy = Position.Y - Radius; dy <= Position.Y + Radius; dy++)
                for (int dy = 0; dy < 200; dy++)
                {
                    if (lightMap.isInFov(dx, dy))
                    {
                        currentLoc.Set(dx, dy);
                        Distance         = (float)currentLoc.Dist(Position);
                        workingIntensity = Intensity - Distance / 12;
                        if (workingIntensity < 0.0f)
                        {
                            workingIntensity = 0.0f;
                        }
                        mapData.Cells[dx, dy].AmbientLight       = workingIntensity;
                        mapData.Cells[dx, dy].AmbientLightColour = TCODColor.Interpolate(TCODColor.black, Colour, workingIntensity);
                    }
                }
            }
        }
Exemplo n.º 4
0
 public void generateFOV(int playerX, int playerY)
 {
     tcodMap.computeFov(playerX, playerY, 10, true, TCODFOVTypes.ShadowFov);
 }
Exemplo n.º 5
0
 public void CalculateFoV(int x, int y, int maxRadius)
 {
     _currentMap.computeFov(x, y, maxRadius, true, TCODFOVTypes.DiamondFov);
 }
Exemplo n.º 6
0
 public void ComputeFov(int xOrigin, int yOrigin, int radius, bool lightWalls)
 {
     TCODMap.computeFov(xOrigin, yOrigin, radius, lightWalls);
 }
Exemplo n.º 7
0
        public int[,] RecalulateLightmap(ref TCODMap los_map, int map_x, int map_y)
        {
            if (!recalc)
                return Lightmap;

            Lightmap = new int[radius * 2, radius * 2];
            if (LightRadius == 0)
            {
                for (int x = -radius; x < radius; x++)
                {
                    for (int y = -radius; y < radius; y++)
                    {
                        Lightmap[x + radius, y + radius] = 0;
                    }
                }

                SetRecalculated();
                return Lightmap;
            }

            int l;
            double coef, sqdist;

            los_map.computeFov(X - map_x, Y - map_y, radius, true, TCODFOVTypes.RestrictiveFov);

            for (int x = -radius; x < radius; x++)
            {
                for (int y = -radius; y < radius; y++)
                {
                    if (los_map.isInFov(X-map_x+x, Y-map_y+y))
                    {
                        //l = (int)Math.Round((float)level - Math.Pow(Util.CalculateDistance(x, y, 0, 0),1.5f));
                        sqdist = x * x + y * y;
                        //coef = ((1.0 / (1.0 + Math.Pow(Util.CalculateDistance(x, y, 0, 0), 2.0f) / 20)) - 1.0 / (1.0 + radius * radius)) / (1.0 - 1.0 / (1.0 + radius * radius));
                        coef = 1.0f / (1.0f + sqdist/20);
                        coef -= 1.0f / (1.0f + (radius * radius)/20);
                        coef /= 1.0f - 1.0f / (1.0f + (radius * radius));

                        l = (int)Math.Floor(level * coef);
                        Lightmap[x + LightRadius, y + LightRadius] = l >= 0 ? l : 0;
                    }
                }
            }

            SetRecalculated();

            return Lightmap;
        }