Tile: Updated toward() method to use ULong coordinate system properly, moved some functions to appropriate objets outside of Tile

main
Bryson Zimmerman 11 months ago
parent 7cc820ee05
commit 9259a27ca0

@ -26,6 +26,10 @@ object World {
tiles.value[tile.x()][tile.y()] = to tiles.value[tile.x()][tile.y()] = to
} }
fun get(tile: Tile): TileProperties {
return tiles.value[tile.x()][tile.y()]
}
//Returns a coordinate pair //Returns a coordinate pair
fun getRandomLocation(): Tile { fun getRandomLocation(): Tile {
return Tile((0..<sizeX).random(), (0..<sizeY).random()) return Tile((0..<sizeX).random(), (0..<sizeY).random())

@ -2,7 +2,8 @@ package technology.zim.data
import technology.zim.World import technology.zim.World
//Tile is a ULong that represents the X,Y coordinates of a Tile
//Contains functions necessary for accessing and manipulating Tiles
@JvmInline @JvmInline
value class Tile(private val value: ULong) { value class Tile(private val value: ULong) {
@ -24,8 +25,6 @@ value class Tile(private val value: ULong) {
//Ensure that the tile is within bounds //Ensure that the tile is within bounds
if(candidateTile.isInBounds() && this.isInBounds()) if(candidateTile.isInBounds() && this.isInBounds())
{ {
if(this.y() == World.sizeY - 1 && dir == Directions.DOWN)
println("wat")
World.update(this, getProperties().add(dir)) World.update(this, getProperties().add(dir))
World.update(candidateTile, candidateTile.getProperties().add(candidateTile.toward(this))) World.update(candidateTile, candidateTile.getProperties().add(candidateTile.toward(this)))
} }
@ -40,8 +39,9 @@ value class Tile(private val value: ULong) {
} }
fun toward(otherTile: Tile): Directions { fun toward(otherTile: Tile): Directions {
return Directions.convertModifier(otherTile.value - this.value) return Directions.convertModifier(Tile(otherTile.x() - this.x(), otherTile.y() - this.y()).value)
} }
fun getAdjacentTiles(explored:Boolean): Set<Tile> { fun getAdjacentTiles(explored:Boolean): Set<Tile> {
val adj = mutableSetOf<Tile>() val adj = mutableSetOf<Tile>()
val dirs = Directions.ALL val dirs = Directions.ALL
@ -50,9 +50,9 @@ value class Tile(private val value: ULong) {
val candidateTile = this + dir val candidateTile = this + dir
//Ensure that the tile is within bounds //Ensure that the tile is within bounds
if(candidateTile.isInBounds() && candidateTile.getProperties().visited() == explored) if(candidateTile.isInBounds() && World.get(candidateTile).visited() == explored)
{ {
println("$this+$dir --> $candidateTile") //println("$this+$dir --> $candidateTile")
adj.add(candidateTile) adj.add(candidateTile)
} }
} }
@ -61,24 +61,17 @@ value class Tile(private val value: ULong) {
return adj return adj
} }
fun hasConnections(): Boolean {
return getProperties().connections != 0
}
//Arguments could be made for either World or Tile knowing whether a Tile is in bounds //Arguments could be made for either World or Tile knowing whether a Tile is in bounds
fun isInBounds(): Boolean { fun isInBounds(): Boolean {
return x() >= 0 && return x() >= 0 &&
y() >= 0 && y() >= 0 &&
x() < World.tiles.value.size && x() < World.sizeX &&
y() < World.tiles.value.get(0).size y() < World.sizeY
} }
//Get the properties of the tile at the given coordinates //Get the properties of the tile at the given coordinates
fun getProperties(): TileProperties { fun getProperties(): TileProperties {
return World.tiles.value.get(x()).get(y()) return World.get(this)
} }
//Get tile at given direction //Get tile at given direction
@ -91,6 +84,8 @@ value class Tile(private val value: ULong) {
} }
//Debug function to print the coordinates of this Tile
@SuppressWarnings
fun getCoordinates(): Pair<Int, Int> { fun getCoordinates(): Pair<Int, Int> {
return Pair(x(), y()) return Pair(x(), y())
} }

Loading…
Cancel
Save