public void Refresh() { Ground.SetSprites(_groundSprites); Hazard.sprite = hazardSprite; EnemyTile.SetSprites(_groundSprites); EnemyTile.gameObject = enemyPrefab; }
/// <summary> /// 判断周围和自己相同类型瓦片的个数,四邻域 /// </summary> /// <param name="tilemap"></param> /// <param name="position"></param> private void JudgeSorroundings(ITilemap tilemap, Vector3Int position) { TileBase right = tilemap.GetTile(position + Vector3Int.right); TileBase left = tilemap.GetTile(position + Vector3Int.left); TileBase up = tilemap.GetTile(position + Vector3Int.up); TileBase down = tilemap.GetTile(position + Vector3Int.down); EnemyTile self = (EnemyTile)tilemap.GetTile(position); if (right is FloorTile && right.name.Contains(TileType.Floor.ToString())) { FloorTile temp = right as FloorTile; self.sprite = temp.sprite; } if (left is FloorTile && left.name.Contains(TileType.Floor.ToString())) { FloorTile temp = left as FloorTile; self.sprite = temp.sprite; } if (up is FloorTile && up.name.Contains(TileType.Floor.ToString())) { FloorTile temp = up as FloorTile; self.sprite = temp.sprite; } if (down is FloorTile && down.name.Contains(TileType.Floor.ToString())) { FloorTile temp = down as FloorTile; self.sprite = temp.sprite; } }
public void LoadMap(string mapFolder) { mapDict.Add(mapFolder, this); grpMap = new GroupBox(); grpBox.Controls.Add(grpMap); CurrentMap = this; mapFolder = @"Resources\" + mapFolder; // declare and initialize locals int top = TOP_PAD; int left = BOUNDARY_PAD; char startCharacter = ' '; List <string> mapLines = new List <string>(); List <string> mapTiles = new List <string>(); List <string> mapEnemies = new List <string>(); // read from tiles file using (FileStream fs = new FileStream(mapFolder + @"\Tiles.txt", FileMode.Open)) { using (StreamReader sr = new StreamReader(fs)) { string line = sr.ReadLine(); while (line != null) { mapTiles.Add(line); line = sr.ReadLine(); } } } tileDict = new Dictionary <char, Tile>(); // read character-tile relationships from file foreach (string mapTile in mapTiles) { // break line up string[] words = mapTile.Split(' '); char c = words[0][0]; // first character is the character described by the tile Tile t; // construct the tile by the tile type (the second word) switch (words[1]) { case "start": // start is a keyword defining the start character but is really just a path tile startCharacter = c; t = new PathTile(words[2]); break; case "path": t = new PathTile(words[2]); break; case "wall": t = new WallTile(words[2]); break; case "inportal": t = new InportalTile(words[2][0], words[3]); break; case "outportal": t = new OutportalTile(words[2][0], words[3], words[4]); break; case "enemy": t = new EnemyTile(words[2][0], Convert.ToInt32(words[3]), words[4]); break; case "boss": t = new BossTile(words[2][0], Convert.ToInt32(words[3]), words[4]); break; default: t = new WallTile("blank"); break; } // add the char, tile pair to tileDict tileDict.Add(c, t); } // read from map file using (FileStream fs = new FileStream(mapFolder + @"\Map.txt", FileMode.Open)) { using (StreamReader sr = new StreamReader(fs)) { string line = sr.ReadLine(); while (line != null) { mapLines.Add(line); line = sr.ReadLine(); } } } // load map file into layout and create PictureBox objects layout = new char[mapLines.Count, mapLines[0].Length]; int i = 0; foreach (string mapLine in mapLines) { int j = 0; foreach (char c in mapLine) { layout[i, j] = c; PictureBox pb = tileDict[c].MakePictureBox(loadImg); if (pb != null) { pb.Top = top; pb.Left = left; grpMap.Controls.Add(pb); } if (c == startCharacter) { CharacterStartRow = i; CharacterStartCol = j; } left += BLOCK_SIZE; j++; } left = BOUNDARY_PAD; top += BLOCK_SIZE; i++; } // resize Group grpMap.Width = NumCols * BLOCK_SIZE + BOUNDARY_PAD * 2; grpMap.Height = NumRows * BLOCK_SIZE + TOP_PAD + BOUNDARY_PAD; using (FileStream fs = new FileStream(mapFolder + @"\Enemies.txt", FileMode.Open)) { using (StreamReader sr = new StreamReader(fs)) { string line = sr.ReadLine(); while (line != null) { mapEnemies.Add(line); line = sr.ReadLine(); } } } enemies = new Bitmap[mapEnemies.Count]; for (int k = 0; k < mapEnemies.Count; ++k) { enemies[k] = loadImg(mapEnemies[k]); } }
public void SetCurrentEnemy(EnemyTile enemy) { anim.SetBool("isMoving", false); _currentEnemy = enemy; }