i am making a minesweeper game and need a way to get a list of all connected tiles and then destroy all sprites of a certain type on those tiles.
well… i have an idea but it might not work super fast
so here is my idea, set the tile you want to start to a certain tile
then use a while loop with(tilesAdded != 0)
then in the loop put tilesAdded = 0
then add a for loop and check all four sides to see if the correct is there and set that tile to (your temporary tile) and run tilesAdded++
or in other words modify tilesAdded of one
then after the loop set all tiles (your temporary tile) to the correct tile
tiles.setTileAt((x,y), (your temporary tile))
while (tilesAdded != 0) {
let ilesAdded = 0
for (let valeur of tiles.getTilesByType(`myTile`)) {
if (tiles.tileAtLocationEquals(valeur.getNeighboringLocation(CollisionDirection.Left), (the tile you ar looking for))) {
tiles.setTileAt(valeur.getNeighboringLocation(CollisionDirection.Left), (your temporary tile))
tilesAdded += 1
}
if (tiles.tileAtLocationEquals(valeur.getNeighboringLocation(CollisionDirection.Right), (the tile you ar looking for))) {
tiles.setTileAt(valeur.getNeighboringLocation(CollisionDirection.Right), (your temporary tile))
tilesAdded += 1
}
if (tiles.tileAtLocationEquals(valeur.getNeighboringLocation(CollisionDirection.Top), (the tile you ar looking for))) {
tiles.setTileAt(valeur.getNeighboringLocation(CollisionDirection.Top), (your temporary tile))
tilesAdded += 1
}
if (tiles.tileAtLocationEquals(valeur.getNeighboringLocation(CollisionDirection.Bottom), (the tile you ar looking for))) {
tiles.setTileAt(valeur.getNeighboringLocation(CollisionDirection.Bottom), (your temporary tile))
tilesAdded += 1
}
}
}
for (let valeur of tiles.getTilesByType((your temporary tile))) {
tiles.setTileAt(valeur.getNeighboringLocation(CollisionDirection.Left), (the tile you want))
}