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); }
public IMap Clone() { TCODMap map = new TCODMap(Width, Height); map.copy(TCODMap); return(new LibtcodMap(map)); }
public static int Main(string[] args) { TCODConsole.initRoot(100, 75, "my game", false); TCODMap map = new TCODMap(100, 75); // first, create a new map. look under fov toolkit for more on this for (int x = 0; x < 100; x++) { // time to fill in our map details for (int y = 0; y < 75; y++) { map.setProperties(x, y, true, true); // i'm setting the entire map to walkable. here is where you need to set the walkable status, based on the map generated } } TCODPath path = new TCODPath(map, 1.0f); // here we create the path object, using our map. the diagonal movement cost here is set to 1.0f int creatureX = 25; // TCODRandom.getInstance().getInt(0, 99); // let's start our creature at a random point int creatureY = 25; //TCODRandom.getInstance().getInt(0, 74); int destinationX = 75; //TCODRandom.getInstance().getInt(0, 99); // and let's give our beast a random destination int destinationY = 50; // TCODRandom.getInstance().getInt(0, 74); path.compute(creatureX, creatureY, destinationX, destinationY); // now we compute the path while (!path.isEmpty()) { // a little while loop that ends when the destination is reached TCODConsole.root.putCharEx(creatureX, creatureY, '@', TCODColor.white, TCODColor.black); TCODConsole.flush(); // here is where we draw the creature on the screen. we won't be overwriting anything, so he'll leave a trail path.walk(ref creatureX, ref creatureY, true); // here we walk the path. by setting the last arg to true, we'll automatically recompute the path if the path is blocked TCODConsole.waitForKeypress(true); // a little something so that you can watch the movement in a action. just click any key to move } return 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; } } } }
public LightSource() { position = new Point(0, 0); radius = 0; colour = new TCODColor(0, 0, 0); intensity = 0; lightMap = new TCODMap(300, 200); lightMap.clear(false, false); }
public Fov(Actor owner, params object[] args) : base(owner, args) { if (args.Length > 0) { if (args[0].GetType() == typeof(string)) { fovRadius = int.Parse((string)args[0]); } else { fovRadius = (int)args[0]; } } if (args.Length > 1) { if (args[1].GetType() == typeof(string)) { strenght = byte.Parse((string)args[1]); } else { strenght = (byte)(int)args[1]; } } if (args.Length > 2) { try { System.Reflection.PropertyInfo property = typeof(libtcod.TCODColor).GetProperty(args[2].ToString().ToLower()); if (property != null) { color = (libtcod.TCODColor)property.GetValue(color, null); } } catch (Exception exc) { Console.WriteLine(exc.Message); } } mapx = (fovRadius); mapy = (fovRadius); height = mapx; width = mapy; fovMaps = new TCODMap[2]; fovMaps[0] = new TCODMap(width * 2, height * 2); fovMaps[1] = new TCODMap(width * 2, height * 2); calculatedMaps = new byte[width * 2, height * 2, fovMaps.Length]; lightmap = new TCODConsole(map.renderWidth, map.renderHeight); lightmap.setBackgroundColor(TCODColor.black); lightmap.setKeyColor(TCODColor.black); update(); }
public Map(Level level, int renderX, int renderY, int renderWidth, int renderHeight) { this.width = 101; this.height = 101; tiles = new Tile[width, height]; map = new TCODMap(width, height); this.renderHeight = renderHeight; this.renderWidth = renderWidth; this.renderX = renderX; this.renderY = renderY; this.level = level; }
public void OnUpdate(TCODMap currentMap) { _currentMap.copy(currentMap); if (_currentPath == null) { return; } _currentPath.Dispose(); _currentPath = new TCODPath(_currentMap, 1.14f); ComputePath(_currentX, _currentY, _destX, _destY); }
public override void load(Actor owner) { base.load(owner); lightmap = new TCODConsole(map.renderWidth, map.renderHeight); lightmap.setBackgroundColor(TCODColor.black); lightmap.setKeyColor(TCODColor.black); fovMaps = new TCODMap[2]; fovMaps[0] = new TCODMap(width * 2, height * 2); fovMaps[1] = new TCODMap(width * 2, height * 2); calculatedMaps = new byte[width * 2, height * 2, fovMaps.Length]; initializeFov = true; }
public DynamicFov() : base() { mapx = 0; mapy = 0; height = map.renderHeight + (mapy); width = map.renderWidth + (mapx); fovMaps = new TCODMap[1]; fovMaps[0] = new TCODMap(width, height); lightmap = new TCODConsole(map.renderWidth, map.renderHeight); lightmap.setBackgroundColor(TCODColor.black); lightmap.setKeyColor(TCODColor.black); update(); }
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 override void load(Actor owner) { base.load(owner); mapx = 0; mapy = 0; height = map.renderHeight + (mapy); width = map.renderWidth + (mapx); fovMaps = new TCODMap[1]; fovMaps[0] = new TCODMap(width, height); lightmap = new TCODConsole(map.renderWidth, map.renderHeight); lightmap.setBackgroundColor(TCODColor.black); lightmap.setKeyColor(TCODColor.black); initializeFov = true; update(); }
public void load(Level level) { map = new TCODMap(width, height); tiles = new Tile[width, height]; for (int x = 0; x < width; x++) { for (int y = 0; y < height; y++) { tiles[x, y].transparent = _transparent[tileIndex(x, y)]; tiles[x, y].canWalk = _canWalk[tileIndex(x, y)]; tiles[x, y].explored = _explored[tileIndex(x, y)]; tiles[x, y].tileID = _tileID[tileIndex(x, y)]; map.setProperties(x, y, tiles[x, y].transparent, tiles[x, y].canWalk); } } this.level = level; }
public Map(String name, int level) { rand = new Random(); this.name = name; this.terrain = new byte[45, 40]; this.items = new Item[45, 40]; this.tcodMap = new TCODMap(45, 40); this.monsters = new ArrayList(); this.level = level; generateTerrainMap(); generateTCODMap(); generateMonsters(); generateItems(); this.trans = new Transision(rand.Next(1, 44), rand.Next(1, 39)); }
public Map(String name, int level) { rand = new Random(); this.name = name; this.terrain = new byte[45, 40]; this.items = new Item[45, 40]; this.tcodMap = new TCODMap(45, 40); this.monsters = new ArrayList(); this.level = level; generateTerrainMap(); generateTCODMap(); generateMonsters(); generateItems(); this.trans = new Transision(rand.Next(1, 44), rand.Next(1 , 39)); }
public Map(Game game) { _currentMonsterNum = 0; _game = game; MaxMonster = 10; TCODMap = new TCODMap(MAP_WIDTH, MAP_HEIGHT); _known = new bool[MAP_WIDTH, MAP_HEIGHT]; _lights = new List<Light>(); _monsters = new List<Monster>(); _items = new List<Item>(); _dead = new List<Monster>(); _deadLights = new List<Light>(); Dijkstra = new Dijkstra(this); for (int i = 0; i < MAP_WIDTH; i++) for (int j = 0; j < MAP_HEIGHT; j++) { this[i, j] = true; } }
public void generate(Type mapGenerator) { engine = Program.engine; engine.gameStatus = GameStatus.LOADING; engine.loadingGui = new GUI.LoadingGui(); tiles = new Tile[width, height]; map = new TCODMap(width, height); level.actorHandler.actors = new List <Actor>(); Message.lines = new List <Line>(); rooms = new List <Generators.Room>(); generator = (Generators.MapGenerator)Activator.CreateInstance(mapGenerator, level); generator.generate(); updateFov = true; Console.WriteLine("..Succeed!");/* * TCODConsole console = new TCODConsole(width, height); * console.clear(); * for (int x = 0; x < width; x++) * { * for (int y = 0; y < height; y++) * { * console.setCharBackground(x, y, * isWall(x, y) ? darkWall : darkGround); * } * } * while (true) * { * * * * TCODConsole.blit(console, 0, 0, * console.getWidth(), console.getHeight(), TCODConsole.root, 0, 0, 1F,1F); * Program.engine.update(); * TCODConsole.flush(); * } */ }
public Map(Game game) { _currentMonsterNum = 0; _game = game; MaxMonster = 10; TCODMap = new TCODMap(MAP_WIDTH, MAP_HEIGHT); _known = new bool[MAP_WIDTH, MAP_HEIGHT]; _lights = new List <Light>(); _monsters = new List <Monster>(); _items = new List <Item>(); _dead = new List <Monster>(); _deadLights = new List <Light>(); Dijkstra = new Dijkstra(this); for (int i = 0; i < MAP_WIDTH; i++) { for (int j = 0; j < MAP_HEIGHT; j++) { this[i, j] = true; } } }
public void Copy(IMap sourceMap, int left = 0, int top = 0) { if (sourceMap.Width + left > Width) { throw new ArgumentException("Source map 'width' + 'left' cannot be larger than the destination map width", "destinationMap"); } if (sourceMap.Height + top > Height) { throw new ArgumentException("Source map 'height' + 'top' cannot be larger than the destination map height", "destinationMap"); } if (sourceMap is LibtcodMap && left == 0 && top == 0) { LibtcodMap mapToCopyFrom = sourceMap as LibtcodMap; TCODMap.copy(mapToCopyFrom.TCODMap); } else { foreach (Cell cell in sourceMap.GetAllCells()) { SetCellProperties(cell.X + left, cell.Y + top, cell.IsTransparent, cell.IsWalkable); } } }
public void LoadFromFile(string file) { Point pos = new Point(0, 0); Width = 0; using (StreamReader r = new StreamReader(file)) { string line; while ((line = r.ReadLine()) != null) { foreach (char c in line.ToCharArray().ToList <char>()) { switch (c) { case '#': Terrain.Add(new Terrain(pos, TerrainType.Wall)); break; case '.': Terrain.Add(new Terrain(pos, TerrainType.Floor)); break; } Width = Math.Max(Width, pos.X); pos.X++; } pos.X = 0; pos.Y++; } } Width++; Height = pos.Y; Map = new TCODMap(Width, Height); foreach (Terrain t in Terrain) { Map.setProperties(t.Position.X, t.Position.Y, t.Transparent, !t.Solid); } }
public void Initialize(int width, int height) { TCODMap = new TCODMap(width, height); }
public IMap Clone() { TCODMap map = new TCODMap( Width, Height ); map.copy( TCODMap ); return new LibtcodMap( map ); }
public bool this[int x, int y] { get { return(!TCODMap.isWalkable(x, y)); } set { TCODMap.setProperties(x, y, !value, !value); } }
public void Clear(bool isTransparent = false, bool isWalkable = false) { TCODMap.clear(isTransparent, isWalkable); }
public bool IsInFov(int x, int y) { return(TCODMap.isInFov(x, y)); }
public RMap() { _fovMap = new TCODMap(Columns, Rows); }
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; }
void render_path(bool first, TCODKey key) { if (map == null) { // initialize the map map = new TCODMap(SAMPLE_SCREEN_WIDTH, SAMPLE_SCREEN_HEIGHT); for (int y = 0; y < SAMPLE_SCREEN_HEIGHT; y++) { for (int x = 0; x < SAMPLE_SCREEN_WIDTH; x++) { if (smap[y][x] == ' ') map.setProperties(x, y, true, true);// ground else if (smap[y][x] == '=') map.setProperties(x, y, true, false); // window } } } if (first) { TCODSystem.setFps(30); // fps limited to 30 // we draw the foreground only the first time. // during the player movement, only the @ is redrawn. // the rest impacts only the background color // draw the help text & player @ sampleConsole.clear(); sampleConsole.setForegroundColor(TCODColor.white); sampleConsole.print(1, 1, "IJKL / mouse :\nmove destination\nTAB : A*/dijkstra"); sampleConsole.print(1, 4, "Using : A*"); sampleConsole.setForegroundColor(TCODColor.black); sampleConsole.putChar(px, py, '@'); // draw windows for (int y = 0; y < SAMPLE_SCREEN_HEIGHT; y++) { for (int x = 0; x < SAMPLE_SCREEN_WIDTH; x++) { if (smap[y][x] == '=') { sampleConsole.putChar(x, y, '='); } } } recalculatePath = true; } if (recalculatePath) { if (usingAstar) { if (AStrPath == null) AStrPath = new TCODPath(map, 1.41f); AStrPath.compute(px, py, dx, dy); } else { if (DijkstraPath == null) DijkstraPath = new TCODDijkstra(map, 1.41f); dijkstraDist = 0.0f; /* compute the distance grid */ DijkstraPath.compute(px, py); /* get the maximum distance (needed for ground shading only) */ for (int y = 0; y < SAMPLE_SCREEN_HEIGHT; y++) { for (int x = 0; x < SAMPLE_SCREEN_WIDTH; x++) { float d = DijkstraPath.getDistance(x, y); if (d > dijkstraDist) dijkstraDist = d; } } // compute the path DijkstraPath.setPath(dx, dy); } recalculatePath = false; busy = .2f; } // draw the dungeon for (int y = 0; y < SAMPLE_SCREEN_HEIGHT; y++) { for (int x = 0; x < SAMPLE_SCREEN_WIDTH; x++) { bool wall = smap[y][x] == '#'; sampleConsole.setCharBackground(x, y, (wall ? darkWall : darkGround), TCODBackgroundFlag.Set); } } // draw the path if (usingAstar) { for (int i = 0; i < AStrPath.size(); i++) { int x, y; AStrPath.get(i, out x, out y); sampleConsole.setCharBackground(x, y, lightGround, TCODBackgroundFlag.Set); } } else { for (int y = 0; y < SAMPLE_SCREEN_HEIGHT; y++) { for (int x = 0; x < SAMPLE_SCREEN_WIDTH; x++) { bool wall = smap[y][x] == '#'; if (!wall) { float d = DijkstraPath.getDistance(x, y); sampleConsole.setCharBackground(x, y, TCODColor.Interpolate(lightGround, darkGround, (float)0.9 * d / dijkstraDist), TCODBackgroundFlag.Set); } } } for (int i = 0; i < DijkstraPath.size(); i++) { int x, y; DijkstraPath.get(i, out x, out y); sampleConsole.setCharBackground(x, y, lightGround, TCODBackgroundFlag.Set); } } // move the creature busy -= TCODSystem.getLastFrameLength(); if (busy <= 0.0f) { busy += 0.2f; if (usingAstar) { if (!AStrPath.isEmpty()) { sampleConsole.putChar(px, py, ' ', TCODBackgroundFlag.None); AStrPath.walk(ref px, ref py, true); sampleConsole.putChar(px, py, '@', TCODBackgroundFlag.None); } } else { if (!DijkstraPath.isEmpty()) { sampleConsole.putChar(px, py, ' ', TCODBackgroundFlag.None); DijkstraPath.walk(ref px, ref py); sampleConsole.putChar(px, py, '@', TCODBackgroundFlag.None); recalculatePath = true; } } } if ((key.Character == 'I' || key.Character == 'i') && dy > 0) { // destination move north sampleConsole.putChar(dx, dy, oldChar, TCODBackgroundFlag.None); dy--; oldChar = sampleConsole.getChar(dx, dy); sampleConsole.putChar(dx, dy, '+', TCODBackgroundFlag.None); if (smap[dy][dx] == ' ') { recalculatePath = true; } } else if ((key.Character == 'K' || key.Character == 'k') && dy < SAMPLE_SCREEN_HEIGHT - 1) { // destination move south sampleConsole.putChar(dx, dy, oldChar, TCODBackgroundFlag.None); dy++; oldChar = sampleConsole.getChar(dx, dy); sampleConsole.putChar(dx, dy, '+', TCODBackgroundFlag.None); if (smap[dy][dx] == ' ') { recalculatePath = true; } } else if ((key.Character == 'J' || key.Character == 'j') && dx > 0) { // destination move west sampleConsole.putChar(dx, dy, oldChar, TCODBackgroundFlag.None); dx--; oldChar = sampleConsole.getChar(dx, dy); sampleConsole.putChar(dx, dy, '+', TCODBackgroundFlag.None); if (smap[dy][dx] == ' ') { recalculatePath = true; } } else if ((key.Character == 'L' || key.Character == 'l') && dx < SAMPLE_SCREEN_WIDTH - 1) { // destination move east sampleConsole.putChar(dx, dy, oldChar, TCODBackgroundFlag.None); dx++; oldChar = sampleConsole.getChar(dx, dy); sampleConsole.putChar(dx, dy, '+', TCODBackgroundFlag.None); if (smap[dy][dx] == ' ') { recalculatePath = true; } } else if (key.KeyCode == TCODKeyCode.Tab) { usingAstar = !usingAstar; sampleConsole.setForegroundColor(TCODColor.white); if (usingAstar) sampleConsole.print(1, 4, "Using : A* "); else sampleConsole.print(1, 4, "Using : Dijkstra"); sampleConsole.setForegroundColor(TCODColor.black); recalculatePath = true; } TCODMouseData mouse = TCODMouse.getStatus(); int mx = mouse.CellX - SAMPLE_SCREEN_X; int my = mouse.CellY - SAMPLE_SCREEN_Y; if (mx >= 0 && mx < SAMPLE_SCREEN_WIDTH && my >= 0 && my < SAMPLE_SCREEN_HEIGHT && (dx != mx || dy != my)) { sampleConsole.putChar(dx, dy, oldChar, TCODBackgroundFlag.None); dx = mx; dy = my; oldChar = sampleConsole.getChar(dx, dy); sampleConsole.putChar(dx, dy, '+', TCODBackgroundFlag.None); if (smap[dy][dx] == ' ') { recalculatePath = true; } } }
void render_fov(bool first, TCODKey key) { if (map == null) { // initialize the map for the fov toolkit map = new TCODMap(SAMPLE_SCREEN_WIDTH, SAMPLE_SCREEN_HEIGHT); for (int y = 0; y < SAMPLE_SCREEN_HEIGHT; y++) { for (int x = 0; x < SAMPLE_SCREEN_WIDTH; x++) { if (smap[y][x] == ' ') map.setProperties(x, y, true, true);// ground else if (smap[y][x] == '=') map.setProperties(x, y, true, false); // window } } // 1d noise used for the torch flickering map_noise = new TCODNoise(1); } if (first) { TCODSystem.setFps(30); // fps limited to 30 // we draw the foreground only the first time. // during the player movement, only the @ is redrawn. // the rest impacts only the background color // draw the help text & player @ sampleConsole.clear(); sampleConsole.setForegroundColor(TCODColor.white); string prompt = "IJKL : move around\nT : torch fx " + (torch ? "off" : "on ") + " : light walls " + (light_walls ? "off" : "on ") + "\n+-: algo " + algo_names[(int)algonum]; sampleConsole.print(1, 1, prompt); sampleConsole.setForegroundColor(TCODColor.black); sampleConsole.putChar(px, py, '@'); // draw windows for (int y = 0; y < SAMPLE_SCREEN_HEIGHT; y++) { for (int x = 0; x < SAMPLE_SCREEN_WIDTH; x++) { if (smap[y][x] == '=') { sampleConsole.putChar(x, y, '='); } } } } if (recomputeFov) { // calculate the field of view from the player position recomputeFov = false; map.computeFov(px, py, torch ? (int)TORCH_RADIUS : 0, light_walls, algonum); } // torch position & intensity variation float dx = 0.0f, dy = 0.0f, di = 0.0f; if (torch) { // slightly change the perlin noise parameter torchx += 0.2f; // randomize the light position between -1.5 and 1.5 float[] tdx = { torchx + 20.0f }; dx = map_noise.getPerlinNoise(tdx) * 1.5f; tdx[0] += 30.0f; dy = map_noise.getPerlinNoise(tdx) * 1.5f; // randomize the light intensity between -0.2 and 0.2 float[] torchxArray = { torchx }; di = 0.2f * map_noise.getPerlinNoise(torchxArray); } // draw the dungeon for (int y = 0; y < SAMPLE_SCREEN_HEIGHT; y++) { for (int x = 0; x < SAMPLE_SCREEN_WIDTH; x++) { bool visible = map.isInFov(x, y); bool wall = (smap[y][x] == '#'); if (!visible) { sampleConsole.setCharBackground(x, y, (wall ? darkWall : darkGround), TCODBackgroundFlag.Set); } else { if (!torch) { sampleConsole.setCharBackground(x, y, wall ? lightWall : lightGround, TCODBackgroundFlag.Set); } else { // torch flickering fx TCODColor baseColor = wall ? darkWall : darkGround; TCODColor light = wall ? lightWall : lightGround; // cell distance to torch (squared) float r = (float)((x - px + dx) * (x - px + dx) + (y - py + dy) * (y - py + dy)); if (r < SQUARED_TORCH_RADIUS) { // l = 1.0 at player position, 0.0 at a radius of 10 cells float l = (SQUARED_TORCH_RADIUS - r) / SQUARED_TORCH_RADIUS + di; // clamp between 0 and 1 if (l < 0.0f) l = 0.0f; else if (l > 1.0f) l = 1.0f; // interpolate the color baseColor = new TCODColor((byte)(baseColor.Red + (light.Red - baseColor.Red) * l), (byte)(baseColor.Green + (light.Green - baseColor.Green) * l), (byte)(baseColor.Blue + (light.Blue - baseColor.Blue) * l)); } sampleConsole.setCharBackground(x, y, baseColor, TCODBackgroundFlag.Set); } } } } if (key.Character == 'I' || key.Character == 'i') { // player move north if (smap[py - 1][px] == ' ') { sampleConsole.putChar(px, py, ' ', TCODBackgroundFlag.None); py--; sampleConsole.putChar(px, py, '@', TCODBackgroundFlag.None); recomputeFov = true; } } else if (key.Character == 'K' || key.Character == 'k') { // player move south if (smap[py + 1][px] == ' ') { sampleConsole.putChar(px, py, ' ', TCODBackgroundFlag.None); py++; sampleConsole.putChar(px, py, '@', TCODBackgroundFlag.None); recomputeFov = true; } } else if (key.Character == 'J' || key.Character == 'j') { // player move west if (smap[py][px - 1] == ' ') { sampleConsole.putChar(px, py, ' ', TCODBackgroundFlag.None); px--; sampleConsole.putChar(px, py, '@', TCODBackgroundFlag.None); recomputeFov = true; } } else if (key.Character == 'L' || key.Character == 'l') { // player move east if (smap[py][px + 1] == ' ') { sampleConsole.putChar(px, py, ' ', TCODBackgroundFlag.None); px++; sampleConsole.putChar(px, py, '@', TCODBackgroundFlag.None); recomputeFov = true; } } else if (key.Character == 'T' || key.Character == 't') { // enable/disable the torch fx torch = !torch; sampleConsole.setForegroundColor(TCODColor.white); string prompt = "IJKL : move around\nT : torch fx " + (torch ? "off" : "on ") + " : light walls " + (light_walls ? "off" : "on ") + "\n+-: algo " + algo_names[(int)algonum]; sampleConsole.print(1, 1, prompt); sampleConsole.setForegroundColor(TCODColor.black); } else if (key.Character == 'W' || key.Character == 'W') { light_walls = !light_walls; sampleConsole.setForegroundColor(TCODColor.white); string prompt = "IJKL : move around\nT : torch fx " + (torch ? "off" : "on ") + " : light walls " + (light_walls ? "off" : "on ") + "\n+-: algo " + algo_names[(int)algonum]; sampleConsole.print(1, 1, prompt); sampleConsole.setForegroundColor(TCODColor.black); recomputeFov = true; } else if (key.Character == '+' || key.Character == '-') { algonum += key.Character == '+' ? 1 : -1; if (algonum >= TCODFOVTypes.RestrictiveFov) algonum = TCODFOVTypes.RestrictiveFov; else if (algonum < 0) algonum = TCODFOVTypes.BasicFov; sampleConsole.setForegroundColor(TCODColor.white); string prompt = "IJKL : move around\nT : torch fx " + (torch ? "off" : "on ") + " : light walls " + (light_walls ? "off" : "on ") + "\n+-: algo " + algo_names[(int)algonum]; sampleConsole.print(1, 1, prompt); sampleConsole.setForegroundColor(TCODColor.black); recomputeFov = true; } }
public LibtcodMap( TCODMap map ) { TCODMap = map; }
public void LoadFromFile(string file) { Point pos = new Point(0, 0); Width = 0; using (StreamReader r = new StreamReader(file)) { string line; while ((line = r.ReadLine()) != null) { foreach (char c in line.ToCharArray().ToList<char>()) { switch (c) { case '#': Terrain.Add(new Terrain(pos, TerrainType.Wall)); break; case '.': Terrain.Add(new Terrain(pos, TerrainType.Floor)); break; } Width = Math.Max(Width, pos.X); pos.X++; } pos.X = 0; pos.Y++; } } Width++; Height = pos.Y; Map = new TCODMap(Width, Height); foreach (Terrain t in Terrain) { Map.setProperties(t.Position.X, t.Position.Y, t.Transparent, !t.Solid); } }
public bool IsTransparent(int x, int y) { return(TCODMap.isTransparent(x, y)); }
public bool IsWalkable(int x, int y) { return(TCODMap.isWalkable(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; }
public void SetCellProperties(int x, int y, bool isTransparent, bool isWalkable) { TCODMap.setProperties(x, y, isTransparent, isWalkable); }
public bool moveAI(int plaX, int plaY, TCODMap map) { counter = counter - speed; if (counter <= 0) { walk = true; counter = counter + 4; } if (walk) { walk = false; switch (ai) { case AIType.unmoveable: return checkAttack(plaX, plaY); case AIType.forgetful: path = new TCODPath(map); path.compute(x, y, plaX, plaY); if (path.size() < 5 && path.size() > 1) { path.walk(ref x, ref y, false); return false; } else { return checkAttack(plaX, plaY); } case AIType.guard: TCODPath tmpPath = new TCODPath(map); tmpPath.compute(x, y, origX, origY); path = new TCODPath(map); path.compute(x, y, plaX, plaY); if (path.size() < 5 && path.size() > 1 && tmpPath.size() < 3) { path.walk(ref x, ref y, false); return false; } else if (path.size() == 1) { return checkAttack(plaX, plaY); } else { tmpPath.walk(ref x, ref y, false); return false; } case AIType.warrior: path = new TCODPath(map); path.compute(x, y, plaX, plaY); if (path.size() < 8 && path.size() > 1) { path.walk(ref x, ref y, false); return false; } else { return checkAttack(plaX, plaY); } case AIType.psycho: path = new TCODPath(map); path.compute(x, y, plaX, plaY); if (path.size() > 1) { path.walk(ref x, ref y, false); return false; } else { return checkAttack(plaX, plaY); } } return false; } return false; }
public Map(int width, int height, Engine engine) { this.tiles = new Tile[width * height]; this.tmap = new TCODMap(width, height); this.gameState = engine.gameState; this.rooms = new List<Room>(); this.width = width; this.height = height; this.engine = engine; reGenMap(gameState.levellist[gameState.curLevel].theLayout, false, true); }
public void ComputeFov(int xOrigin, int yOrigin, int radius, bool lightWalls) { TCODMap.computeFov(xOrigin, yOrigin, radius, lightWalls); }
public SubscribedFoVMap(TCODMap fovMap) { _currentPath = null; _currentMap = new TCODMap(1000, 1000); OnUpdate(fovMap); }
public Cell GetCell(int x, int y) { return(new Cell(x, y, TCODMap.isTransparent(x, y), TCODMap.isWalkable(x, y), TCODMap.isInFov(x, y))); }
/// <summary> /// Initialize a new map object. /// </summary> public Map(Creature player, WorldMap wm, MessageHandler _out, FactionManager facman, SQLiteConnection dbconn, int vp_height, int vp_width) { this.Player = player; this.wm = wm; this._out = _out; this.dbconn = dbconn; this.vp_height = vp_height; this.vp_width = vp_width; sun_level_changed = true; CreatureList = new Inventory<Creature>(); ItemList = new Inventory<Item>(); //LightSources = new Dictionary<string, LightSource>(); this.facman = facman; tcod_map = new TCODMap(3 * wm.CELL_WIDTH, 3 * wm.CELL_HEIGHT); light_tint = new int[vp_width, vp_height]; cells = new Cell[3, 3, 3]; centerAndLoad(player); }
public LibtcodMap(TCODMap map) { TCODMap = map; }
public bool moveAI(int plaX, int plaY, TCODMap map) { counter = counter - speed; if (counter <= 0) { walk = true; counter = counter + 4; } if (walk) { walk = false; switch (ai) { case AIType.unmoveable: return(checkAttack(plaX, plaY)); case AIType.forgetful: path = new TCODPath(map); path.compute(x, y, plaX, plaY); if (path.size() < 5 && path.size() > 1) { path.walk(ref x, ref y, false); return(false); } else { return(checkAttack(plaX, plaY)); } case AIType.guard: TCODPath tmpPath = new TCODPath(map); tmpPath.compute(x, y, origX, origY); path = new TCODPath(map); path.compute(x, y, plaX, plaY); if (path.size() < 5 && path.size() > 1 && tmpPath.size() < 3) { path.walk(ref x, ref y, false); return(false); } else if (path.size() == 1) { return(checkAttack(plaX, plaY)); } else { tmpPath.walk(ref x, ref y, false); return(false); } case AIType.warrior: path = new TCODPath(map); path.compute(x, y, plaX, plaY); if (path.size() < 8 && path.size() > 1) { path.walk(ref x, ref y, false); return(false); } else { return(checkAttack(plaX, plaY)); } case AIType.psycho: path = new TCODPath(map); path.compute(x, y, plaX, plaY); if (path.size() > 1) { path.walk(ref x, ref y, false); return(false); } else { return(checkAttack(plaX, plaY)); } } return(false); } return(false); }
public void Initialize( int width, int height ) { TCODMap = new TCODMap( width, height ); }