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; } } } }
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); } } } }
public int IntensityAt(int x, int y) { if (!_tcodmap.isInFov(x, y)) { return(0); } int dist = _distanceFunc(x, y, PosX, PosY); float mult = 1f; if (_capacity > 0) { mult = 1f - (float)System.Math.Pow((float)_elapsed / _capacity, 2); } int ret = (int)((_intensity + (int)(dist * _coef)) * mult); return(ret >= 0 ? ret : 0); }
public bool getInFOV(int x, int y) { return(tcodMap.isInFov(x, y)); }
public bool IsVisible(int x, int y) { return(_currentMap.isInFov(x, y)); }
public bool IsInFov(int x, int y) { return(TCODMap.isInFov(x, y)); }
public Cell GetCell(int x, int y) { return(new Cell(x, y, TCODMap.isTransparent(x, y), TCODMap.isWalkable(x, y), TCODMap.isInFov(x, y))); }
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; }