// Reads CSV of tiles data private List <TileRow> ReadCSV(string filename) { List <TileRow> result = new List <TileRow>(); StreamReader strReader = new StreamReader(filename); bool endOfFile = false; while (!endOfFile) { string data_string = strReader.ReadLine(); if (data_string == null) { endOfFile = true; break; } // Storing to variable var data_values = data_string.Split(','); // Debug.Log(data_values[0].ToString() + " " + data_values[1].ToString() + " " + data_values[2].ToString() + " " + data_values[3].ToString()); TerrainType left_type = (TerrainType)System.Enum.Parse(typeof(TerrainType), data_values[0]); int left_crowns = int.Parse(data_values[1]); TerrainType right_type = (TerrainType)System.Enum.Parse(typeof(TerrainType), data_values[2]); int right_crowns = int.Parse(data_values[3]); TileRow row = new TileRow(left_type, left_crowns, right_type, right_crowns); result.Add(row); } return(result); }
/// <summary> /// Constructor /// </summary> private TileManager() { numTiles = 0; // Add the requested initial number tiles = new TileRow(); queue = new TileQueue(); addBatch(Options.Instance.Num_Tiles); }
private MapTiles ListToMapTiles(List <List <TileType> > rows) { TileRow[] tiles = new TileRow[rows.Count]; for (int i = 0; i < rows.Count; i++) { tiles[i] = new TileRow(rows[i].ToArray()); } TileRow[] rev = tiles.Reverse().ToArray(); return(new MapTiles(rev)); }
private TileRow GenerateRow(int y, float tileSize, Transform parent) { TileRow row = new TileRow(); Tile[] tiles = new Tile[(int)size.x]; for (int x = 0; x < size.x; x++) { tiles[x] = InstantiateTile(new Vector2(x, y), tileSize, parent); } row.tiles = tiles; return(row); }
private TileRow[] Generate() { TileRow[] rows = new TileRow[(int)size.y]; float tileSize = serializedObject.FindProperty("tileSize").floatValue; Transform parent = ((Tilemap)target).transform; for (int y = 0; y < size.y; y++) { rows[y] = GenerateRow(y, tileSize, parent); } return(rows); }
/// <summary> /// Gets the tile at tilePosition /// </summary> /// <param name="tilePosition">The point of the tile we are interested in</param> /// <returns>The tile at tilePosition if it exists, else null</returns> public Tile GetTile(Point tilePosition) { TileRow tr = Tiles[tilePosition.y]; try { return(tr[tilePosition.x]); } catch (System.Exception) { Debug.Log("X: " + tilePosition.x + "Y: " + tilePosition.y); } return(null); }
public Map() { int mapStringIndex = 0; string mapString = GameSetting.MapLayout.Level_01; for (int y = 0; y < GameSetting.MapSize.Y; y++) { TileRow thisRow = new TileRow(); for (int x = 0; x < GameSetting.MapSize.X; x++) { Tile mapCell = parseMapChar(mapString[mapStringIndex]); thisRow.Columns.Add(mapCell); mapStringIndex++; } Rows.Add(thisRow); } }
/// <summary> /// Checks to see if the tile at given co-ordinates is a valid tile /// </summary> /// <param name="x">The X location of the tile</param> /// <param name="y">The Y location of the tile</param> /// <returns>True if tile is valid. False if tile is invalid</returns> public bool ValidTile(int x, int y) { // Why not just check tilerow and column is not null? // Wouldn't that be more flexible? TileRow tr = Tiles[y]; if (tr == null) { return(false); } else if (tr[x] == null) { return(false); } else { return(true); } }
/// <summary> /// Private constructor, use TryLoad() to create a new instance /// </summary> private Rom206() { GameRom.TryCreate(out GameRom r); // load the ROM ROM.TryLoad("136029-206.bin", 0x4000, 0x174942, out ROM rom); System.Diagnostics.Debug.Assert(rom.Data.Length == 0x4000); Array.Copy(rom.Data, 0x2000, Data, 0, Data.Length); // read all tiles for (int n = 0; n < Tile.Length; n++) { Tile[n] = new Tile(this, (n - 8) * 2); } // read all the rows for (int n = 0; n < Row.Length; n++) { Row[n] = new TileRow(this, n + 1); } }
public TrapGrid(TileRow firstRow) { currentRow = firstRow; SafeTiles += firstRow.SafeCount; }
protected override void LoadState() { firstTileRow = TileRow.Parse(FileContents); }
private void AnalyzeRow() { currentRow = currentRow.GetNext(); SafeTiles += currentRow.SafeCount; }
/// <summary> /// Read an EMF file /// </summary> /// <param name="fileName">File to read the EMF data from</param> public void Read(string fileName) { int outersize; int innersize; using (EOFile file = new EOFile(File.Open(fileName, FileMode.Open, FileAccess.Read))) { if (file.GetFixedString(3) != "EMF") throw new Exception("Corrupt or not an EMF file"); revisionId = file.GetBytes(4); byte[] rawname = file.GetBytes(24); for (int i = 0; i < 24; ++i) { if (rawname[i] == 0xFF) { Array.Resize(ref rawname, i); break; } } name = DecodeString(rawname); type = (Type)file.GetChar(); effect = (Effect)file.GetChar(); music = file.GetChar(); musicExtra = file.GetChar(); ambientNoise = (ushort)file.GetShort(); width = file.GetChar(); height = file.GetChar(); fillTile = (ushort)file.GetShort(); mapAvailable = file.GetChar(); canScroll = file.GetChar(); relogX = file.GetChar(); relogY = file.GetChar(); unknown = file.GetChar(); outersize = file.GetChar(); for (int i = 0; i < outersize; ++i) { npcs.Add(new NPC() { x = file.GetChar(), y = file.GetChar(), id = (ushort)file.GetShort(), spawnType = file.GetChar(), spawnTime = (ushort)file.GetShort(), amount = file.GetChar() }); } outersize = file.GetChar(); for (int i = 0; i < outersize; ++i) { unknowns.Add(new Unknown() { data = file.GetBytes(5) }); } outersize = file.GetChar(); for (int i = 0; i < outersize; ++i) { chests.Add(new Chest() { x = file.GetChar(), y = file.GetChar(), key = (ushort)file.GetShort(), slot = file.GetChar(), item = (ushort)file.GetShort(), time = (ushort)file.GetShort(), amount = (uint)file.GetThree() }); } outersize = file.GetChar(); for (int i = 0; i < outersize; ++i) { byte y = file.GetChar(); innersize = file.GetChar(); TileRow row = new TileRow() { y = y, tiles = new List<Tile>(innersize) }; for (int ii = 0; ii < innersize; ++ii) { row.tiles.Add(new Tile() { x = file.GetChar(), spec = (TileSpec)file.GetChar() }); } tileRows.Add(row); } outersize = file.GetChar(); for (int i = 0; i < outersize; ++i) { byte y = file.GetChar(); innersize = file.GetChar(); WarpRow row = new WarpRow() { y = y, tiles = new List<Warp>(innersize) }; for (int ii = 0; ii < innersize; ++ii) { row.tiles.Add(new Warp() { x = file.GetChar(), warpMap = (ushort)file.GetShort(), warpX = file.GetChar(), warpY = file.GetChar(), levelRequirement = file.GetChar(), door = (ushort)file.GetShort() }); } warprows.Add(row); } for (int layer = 0; layer < GFXLayers; ++layer) { outersize = file.GetChar(); gfxRows[layer] = new List<GFXRow>(outersize); for (int i = 0; i < outersize; ++i) { byte y = file.GetChar(); innersize = file.GetChar(); GFXRow row = new GFXRow() { y = y, tiles = new List<GFX>(innersize) }; row.tiles = new List<GFX>(innersize); for (int ii = 0; ii < innersize; ++ii) { row.tiles.Add(new GFX() { x = file.GetChar(), tile = (ushort)file.GetShort() }); } gfxRows[layer].Add(row); } } outersize = file.GetChar(); for (int i = 0; i < outersize; ++i) { Sign sign = new Sign(); sign.x = file.GetChar(); sign.y = file.GetChar(); int msgLength = file.GetShort() - 1; string data = DecodeString(file.GetBytes(msgLength)); int titleLength = file.GetChar(); sign.title = data.Substring(0, titleLength); sign.message = data.Substring(titleLength); signs.Add(sign); } } }
private void GenerateMap() { int MapStringIndex = 0; for (int y = 0; y < Size.Y; y++) { TileRow thisRow = new TileRow(); for (int x = 0; x < Size.X; x++) { Tile mapCell = parseMapChar(MapString[MapStringIndex]); thisRow.Columns.Add(mapCell); MapStringIndex++; } Rows.Add(thisRow); } }
private static void ProcessFiles(string src, string dst, bool singleFile) { string[] inFiles = singleFile ? new[] { src } : Directory.GetFiles(src, "*.emf"); for (int map = 0; map < inFiles.Length; ++map) { MapFile EMF = new MapFile(inFiles[map]); bool changesMade = false; string lastPart = inFiles[map].Substring(inFiles[map].Contains('\\') ? inFiles[map].LastIndexOf('\\') + 1 : 0, inFiles[map].Length - inFiles[map].LastIndexOf('\\') - 1); for (int i = EMF.TileRows.Count - 1; i >= 0; --i) { TileRow tr = EMF.TileRows[i]; for (int j = tr.tiles.Count - 1; j >= 0; --j) { Tile tt = tr.tiles[j]; if (tt.x > EMF.Width || tr.y > EMF.Height) { Console.WriteLine("[MAP {3}] Tile {0}x{1} ({2}) is out of map bounds. Removing.", tt.x, tr.y, Enum.GetName(typeof(TileSpec), tt.spec), lastPart); tr.tiles.RemoveAt(j); changesMade = true; } } } for (int i = EMF.WarpRows.Count - 1; i >= 0; --i) { WarpRow tr = EMF.WarpRows[i]; for (int j = tr.tiles.Count - 1; j >= 0; --j) { Warp tt = tr.tiles[j]; if (tt.x > EMF.Width || tr.y > EMF.Height) { Console.WriteLine("[MAP {2}] Warp {0}x{1} is out of map bounds. Removing.", tt.x, tr.y, lastPart); tr.tiles.RemoveAt(j); changesMade = true; } } } for (int i = EMF.NPCSpawns.Count - 1; i >= 0; --i) { NPCSpawn npc = EMF.NPCSpawns[i]; NPCRecord npcRec = (NPCRecord)ENF.Data.Find(rec => ((NPCRecord)rec).ID == npc.id); if (npc.id > ENF.Data.Count || npcRec == null) { Console.WriteLine("[MAP {0}] NPC Spawn {1}x{2} uses non-existent NPC #{3}. Removing.", lastPart, npc.x, npc.y, npc.id); EMF.NPCSpawns.RemoveAt(i); changesMade = true; continue; } if (npc.x > EMF.Width || npc.y > EMF.Height) { Console.WriteLine("[MAP {0}] NPC Spawn {1}x{2} ({3}) is out of map bounds. Removing.", lastPart, npc.x, npc.y, npcRec.Name); EMF.NPCSpawns.RemoveAt(i); changesMade = true; continue; } if (!CheckTile(EMF, npc.x, npc.y)) { Console.WriteLine("[MAP {0}] NPC Spawn {1}x{2} ({3}) is invalid...", lastPart, npc.x, npc.y, npcRec.Name); bool found = false; for (int row = npc.y - 2; row < npc.y + 2; ++row) { if (found) { break; } for (int col = npc.x - 2; col < npc.x + 2; ++col) { if (found) { break; } if (CheckTile(EMF, col, row)) { Console.WriteLine("[MAP {0}] Found valid spawn point. Continuing.", lastPart); found = true; } } } if (!found) { Console.WriteLine("[MAP {0}] NPC couldn't spawn anywhere valid! Removing."); EMF.NPCSpawns.RemoveAt(i); changesMade = true; } } } for (int i = EMF.Chests.Count - 1; i >= 0; --i) { MapChest chest = EMF.Chests[i]; ItemRecord rec = EIF.GetItemRecordByID(chest.item); if (chest.item > EIF.Data.Count || rec == null) { Console.WriteLine("[MAP {0}] Chest Spawn {1}x{2} uses non-existent Item #{3}. Removing.", lastPart, chest.x, chest.y, chest.item); EMF.Chests.RemoveAt(i); changesMade = true; continue; } if (chest.x > EMF.Width || chest.y > EMF.Height || (EMF.TileLookup[chest.y, chest.x] ?? new Tile { spec = TileSpec.Wall }).spec != TileSpec.Chest) { Console.WriteLine("[MAP {0}] Chest Spawn {1}x{2} points to a non-chest. Removing.", lastPart, chest.x, chest.y); EMF.Chests.RemoveAt(i); changesMade = true; } } if (!changesMade) { Console.WriteLine("Map {0} processed without any errors. No changes made.", lastPart); continue; } if (map == 0 && singleFile && inFiles.Length == 1) { EMF.Save(dst); break; } EMF.Save(Path.Combine(dst, lastPart)); } }
//Loading textures and making tilemap public void LoadContent(ContentManager contentManager) { // Create a new SpriteBatch, which can be used to draw textures. SpriteBatch = new SpriteBatch(GraphicsDevice); //Loading textures var path = GameSettings.ContentDirectory + "\\Graphics"; var files = Utils.ListFilesRecursively(path); foreach (var file in files) { if (Path.GetExtension(GameSettings.ContentDirectory + file) != ".png") continue; var dir = new Uri(path).MakeRelativeUri(new Uri(file)).ToString(); var name = Path.GetFileNameWithoutExtension(file); if (name == null) throw new ArgumentNullException(); var relativeName = Path.GetDirectoryName(dir) + "\\" + name; var texture = contentManager.Load<Texture2D>(relativeName); _textures.Add(name, texture); } Font = contentManager.Load<SpriteFont>("HudFont"); var tileTexture = GetTexture("TileFloorGray"); var wallNW = GetTexture("TileWallBrownNW"); var wallNE = GetTexture("TileWallBrownNE"); GrayFloorTile = new Tile(0, 0, tileTexture); var width = GameSettings.WorldWidth; var height = GameSettings.WorldHeight; for (var x = -width/2; x < width/2; x++) { var row = new TileRow(); for (var y = -height/2; y < height/2; y++) row.Add(new Tile(x, y, tileTexture)); Tiles.Add(row); } foreach (var tile in Tiles[0]) tile.WallNW = wallNW; foreach (var row in Tiles) row.Last().WallNE = wallNE; }