private void loadBackgrounds(TmxMap map, Dictionary <int, TmxTilesetTile> tile_types, int first_gid, int tiles_in_row) { List <string> backgroundNames = new List <string>(); string pattern = @"\bbackground"; foreach (var layer in map.Layers) { if (Regex.IsMatch(layer.Name, pattern)) { backgroundNames.Add(layer.Name); } } foreach (string bgName in backgroundNames) { TmxLayerTile[] tmxTiles = map.Layers[bgName].Tiles.ToArray(); int tileID = 0; foreach (var tmxTile in tmxTiles) { int gid = tmxTile.Gid; int type; int typeID = gid - first_gid; cTile gameTile = null; try { if (typeID < 0) { gameTile = new cTile(tileID, TileType.EMPTY); // does not matter, because we just skip the drwaing of empty tiles... gameTile.PosOnTexture = new AABB(0, 0, Constants.TILE_SIZE, Constants.TILE_SIZE); } else if (int.TryParse(tile_types[typeID].Type, out type)) { gameTile = new cTile(tileID, TileType.EMPTY); gameTile.PosOnTexture = getTextureRect(typeID, tiles_in_row); } layers[TileLayerTypes.BACKGROUND_1].Add(gameTile); tileID++; } catch (Exception e) { } } } }
private void loadLayer(Dictionary <int, TmxTilesetTile> tile_types, string tmx_layer, int into_layer, int first_gid, int tiles_in_row) { TmxLayerTile[] tmxTiles = this.map.Layers[tmx_layer].Tiles.ToArray(); layers[into_layer] = new List <cTile>(); int tileID = 0; foreach (var tmxTile in tmxTiles) { int globalID = tmxTile.Gid; cTile gameTile = null; try { if (globalID <= 0) { // do nothing, it is an empty tile gameTile = new cTile(tileID, TileType.EMPTY); } else { int frameTile = globalID - 1; // substract one is very important! int type = Convert.ToInt32(tile_types[frameTile].Type); gameTile = new cTile(tileID, (TileType)type); gameTile.GlobalId = globalID; gameTile.PosOnTexture = getTextureRect(frameTile, tiles_in_row); /* #if DEBUG * System.Diagnostics.Debug.WriteLine( * string.Format("{0} : {1}", gameTile.PosOnTexture.topLeft.X, gameTile.PosOnTexture.topLeft.Y)); #endif */ } layers[into_layer].Add(gameTile); //simple tile id counting... tileID++; } catch (Exception e) { } } }
/// <summary> /// Filters the visible tiles and build the vertex arrays of each layer /// </summary> private void filterDrawableTiles() { int startTileX = (int)drawTileBounds.topLeft.X; int startTileY = (int)drawTileBounds.topLeft.Y; int endTileX = (int)drawTileBounds.rightBottom.X; int endTileY = (int)drawTileBounds.rightBottom.Y; // important to call !! this.ClearTileLayers(); Vector2f drawPos = new Vector2f(); const int spaceOffset = 0; for (int y = startTileY; y < endTileY; y++) { for (int x = startTileX; x < endTileX; x++) { for (int layer = 0; layer < drawTileLayers.Count; layer++) { cTile tempTile = world.CurrentLevel.GetTileAtXY(x, y, drawTileLayers[layer].TypeID); if (tempTile.Type != TileType.EMPTY) { // tilesToDraw.Add(new DrawTile(x, y, tempTile.PosOnTexture)); drawPos.X = (world.WorldBounds.topLeft.X + x * Constants.TILE_SIZE) + spaceOffset; drawPos.Y = (world.WorldBounds.topLeft.Y + y * Constants.TILE_SIZE) + spaceOffset; AABB tileBounds = world.getAABBFromWorldPos(drawPos); drawTileLayers[layer].AddTileVertices(tileBounds, tempTile.PosOnTexture); } } } } }
public cTile(cTile other) { this.IdCode = other.IdCode; this.Type = other.Type; }