public Tileset(Tile[][] tiles, Texture tex) { this.tiles = tiles; this.tex = tex; Reload(); }
private void GenerateTiles(int x, int y) { Tile[][] tiles = new Tile[x][]; for (int i = 0; i < tiles.Length; i++) tiles[i] = new Tile[y]; for (int i = 0; i < x; i++) { for (int j = 0; j < y; j++) { if (j == 0 || j == y - 1 || i == 0 || i == x - 1) { tiles[i][j] = new Tile(new Point(i, j), 4, 4, TileType.Wall); } else tiles[i][j] = new Tile(new Point(i, j), 4, 4, TileType.Floor); } } level.Tileset = new Tileset(tiles, Resources.Textures["tilesetworld.png"]); }
public static void setInitialTileOffset(Tile tile, Point p, int length, int width) { tile.Position = new Vector2(-(float)width / 2 * Tile.SIZE_F + p.X * Tile.SIZE_F + Tile.SIZE_F / 2, (float)length / 2 * Tile.SIZE_F - p.Y * Tile.SIZE_F - Tile.SIZE_F / 2); }
/** * Calculates the bordering tile bitfield. * A tile is considered a "bordering tile" of a given tile if it meets the following criteria: * <ul> * <li> The bordering tile shares an edge or vertex with the given tile.</li> * <li> The bordering tile is not of the same type as the given tile.</li> * </ul> * The result of this method is stored as a byte. Each potential bordering tile is represented as a flag in a bitfield. * The flags are defined as follows: * \verbatim * +------+------+------+ * | | | | * | 0x01 | 0x02 | 0x04 | * | | | | * +------+------+------+ * | | | | * | 0x08 | | 0x10 | * | | | | * +------+------+------+ * | | | | * | 0x20 | 0x40 | 0x80 | * | | | | * +------+------+------+ * \endverbatim * @param tileset The tileset that contains this tile. */ public void calculateBorders(Tile[][] tileset) { int x = tilesetPos.X; int y = tilesetPos.Y; //store all the bordering tile indices in top left to bottom right order. List<Point> points = new List<Point>(); points.Add(new Point(x - 1, y - 1)); points.Add(new Point(x, y - 1)); points.Add(new Point(x + 1, y - 1)); points.Add(new Point(x - 1, y)); points.Add(new Point(x + 1, y)); points.Add(new Point(x - 1, y + 1)); points.Add(new Point(x, y + 1)); points.Add(new Point(x + 1, y + 1)); //check each of the bordering tiles, set it's corresponding bit to 1 if it's not the same type of tile. for (int i = 0; i < points.Count; i++) { Point p = points[i]; //make sure tileset index is within tileset bounds if (p.X >= 0 && p.X < tileset[0].Length && p.Y >= 0 && p.Y < tileset.Length) { Tile t = tileset[p.Y][p.X]; //if the tile type is not the same, it's considered a bordering tile. if (t != null && t.getTileType() != type) borders |= (byte)(0x01 << i); } } }