public Tilemap(TextureAtlas atlas, int width, int height, float tileTextureDimension, float tileWorldDimension, Tile[,] tiles) { _atlas = atlas; _width = width; _height = height; _tileSize = tileTextureDimension; _cellSize = tileWorldDimension; Tiles = tiles; _vertexArray = new VertexArray(PrimitiveType.Quads, (uint)(width * height * 4)); for (int x = 0; x < width; x++) { for (int y = 0; y < height; y++) { AddTileVertices(tiles[x, y], new Vector2f(x, y)); } } }
public static Level Generate(GameWorld world, int width, int height, TextureAtlas atlas, int cellSize) { DungeonGenerator.Instance.GenerateHauberkDungeon(width, height, 195000, 5, 5, 50, false, true); var tileData = DungeonGenerator._dungeon; var map = new Map(width, height); var tiles = new Tile[width, height]; for (var x = 0; x < width; x++) { for (var y = 0; y < height; y++) { Color color = Color.White; switch (tileData[x, y]) { case TileType.Floor: map.SetCellProperties(x, y, true, true); color = new Color(194, 194, 194); break; case TileType.RoomFloor: map.SetCellProperties(x, y, true, true); color = new Color(35, 255, 255); break; case TileType.Wall: map.SetCellProperties(x, y, false, false); color = new Color(163, 163, 163); break; case TileType.Door: map.SetCellProperties(x, y, false, true); color = new Color(132, 81, 0); break; } tiles[x, y] = new Tile(tileData[x, y], color); tiles[x, y].Cell = map.GetCell(x, y); } } var tilemap = new Tilemap(atlas, width, height, atlas.SpriteSize, cellSize, tiles); return new Level(world, map, tilemap); }
private bool InRange(uint entity, Vector2f AIpos, Vector2f entityPos) { var tiles = new Tile[4] { World.CurrentLevel.GetTile(AIpos + new Vector2f(1, 0)), World.CurrentLevel.GetTile(AIpos + new Vector2f(-1, 0)), World.CurrentLevel.GetTile(AIpos + new Vector2f(0, 1)), World.CurrentLevel.GetTile(AIpos + new Vector2f(0, -1)) }; for (var i = 0; i < tiles.Length; i++) { if (tiles[i].Entity != null && tiles[i].Entity.Value == entity) return true; } return false; }
public void AddTileVertices(Tile tile, Vector2f position) { //TODO: store the indices of these 4 verticies on the tile so that they can be //accessed and have the color modifired for FOV var src = _atlas.GetCoords(tile.Type).Value; if (!tile.Cell.IsExplored) { _vertexArray.Append(new Vertex((new Vector2f(0.0f, 0.0f) + position) * _cellSize, Color.Black, new Vector2f(_tileSize * src.X, _tileSize * src.Y))); _vertexArray.Append(new Vertex((new Vector2f(1.0f, 0.0f) + position) * _cellSize, Color.Black, new Vector2f(_tileSize * src.X + _tileSize, _tileSize * src.Y))); _vertexArray.Append(new Vertex((new Vector2f(1.0f, 1.0f) + position) * _cellSize, Color.Black, new Vector2f(_tileSize * src.X + _tileSize, _tileSize * src.Y + _tileSize))); _vertexArray.Append(new Vertex((new Vector2f(0.0f, 1.0f) + position) * _cellSize, Color.Black, new Vector2f(_tileSize * src.X, _tileSize * src.Y + _tileSize))); } else { if (!tile.Cell.IsInFov) { var colorOffset = new Color(133, 133, 133); _vertexArray.Append(new Vertex((new Vector2f(0.0f, 0.0f) + position) * _cellSize, tile.Tint * colorOffset, new Vector2f(_tileSize * src.X, _tileSize * src.Y))); _vertexArray.Append(new Vertex((new Vector2f(1.0f, 0.0f) + position) * _cellSize, tile.Tint * colorOffset, new Vector2f(_tileSize * src.X + _tileSize, _tileSize * src.Y))); _vertexArray.Append(new Vertex((new Vector2f(1.0f, 1.0f) + position) * _cellSize, tile.Tint * colorOffset, new Vector2f(_tileSize * src.X + _tileSize, _tileSize * src.Y + _tileSize))); _vertexArray.Append(new Vertex((new Vector2f(0.0f, 1.0f) + position) * _cellSize, tile.Tint * colorOffset, new Vector2f(_tileSize * src.X, _tileSize * src.Y + _tileSize))); } else { _vertexArray.Append(new Vertex((new Vector2f(0.0f, 0.0f) + position) * _cellSize, tile.Tint, new Vector2f(_tileSize * src.X, _tileSize * src.Y))); _vertexArray.Append(new Vertex((new Vector2f(1.0f, 0.0f) + position) * _cellSize, tile.Tint, new Vector2f(_tileSize * src.X + _tileSize, _tileSize * src.Y))); _vertexArray.Append(new Vertex((new Vector2f(1.0f, 1.0f) + position) * _cellSize, tile.Tint, new Vector2f(_tileSize * src.X + _tileSize, _tileSize * src.Y + _tileSize))); _vertexArray.Append(new Vertex((new Vector2f(0.0f, 1.0f) + position) * _cellSize, tile.Tint, new Vector2f(_tileSize * src.X, _tileSize * src.Y + _tileSize))); } } }
public Tile SetTileProperties(Tile tile, bool isWalkable, bool isTransparent, bool isExplored) { _map.SetCellProperties(tile.Cell.X, tile.Cell.Y, isTransparent, isWalkable, isExplored); return GetTile(tile.Cell.X, tile.Cell.Y); }
public Tile[] GetBorderingTilesInArea(Vector2f position, int distance = 1) { var cells = _map.GetBorderCellsInArea((int)position.X, (int)position.Y, distance).ToArray(); var tiles = new Tile[cells.Length]; for (var i = 0; i < cells.Length; i++) tiles[i] = GetTile(cells[i].X, cells[i].Y); return tiles; }