This commit is contained in:
nelle 2023-10-28 17:54:26 -06:00
parent 5f0a2b06c2
commit b5e0527986
3 changed files with 59 additions and 0 deletions

View file

@ -0,0 +1,21 @@
package group.ouroboros.potrogue.blocks
import group.ouroboros.potrogue.builders.GameTileRepository.EMPTY
import group.ouroboros.potrogue.builders.GameTileRepository.FLOOR
import group.ouroboros.potrogue.builders.GameTileRepository.WALL
import kotlinx.collections.immutable.persistentMapOf
import org.hexworks.zircon.api.data.BlockTileType
import org.hexworks.zircon.api.data.Tile
import org.hexworks.zircon.api.data.base.BaseBlock
class GameBlock (content: Tile = FLOOR) : BaseBlock<Tile>(
emptyTile = EMPTY,
tiles = persistentMapOf(BlockTileType.CONTENT to content)
) {
val isFloor: Boolean
get() = content == FLOOR
val isWall: Boolean
get() = content == WALL
}

View file

@ -0,0 +1,9 @@
package group.ouroboros.potrogue.builders
import group.ouroboros.potrogue.blocks.GameBlock
object GameBlockFactory {
fun floor() = GameBlock(GameTileRepository.FLOOR)
fun wall() = GameBlock(GameTileRepository.WALL)
}

View file

@ -0,0 +1,29 @@
package group.ouroboros.potrogue.world
import group.ouroboros.potrogue.blocks.GameBlock
import org.hexworks.zircon.api.builder.game.GameAreaBuilder
import org.hexworks.zircon.api.data.Position3D
import org.hexworks.zircon.api.data.Size3D
import org.hexworks.zircon.api.data.Tile
import org.hexworks.zircon.api.game.GameArea
class World (
// A World object is about holding the world data in memory, but it is not about generating it, so we take the initial state of the world as a parameter.
startingBlocks: Map<Position3D, GameBlock>,
visibleSize: Size3D,
actualSize: Size3D
// We implement the GameArea which well use with the GameComponent
) : GameArea<Tile, GameBlock> by GameAreaBuilder.newBuilder<Tile, GameBlock>()
// We set its visibleSize. This is the size of the area which will be visible on our screen
.withVisibleSize(visibleSize)
// We set the actualSize. This is the size of the whole world which can be multiple times bigger than the visible part. GameArea supports scrolling so well be able to scroll through our caves soon
.withActualSize(actualSize)
.build() {
init {
startingBlocks.forEach { (pos, block) ->
// a World takes a Map of GameBlocks, so we need to add them to the GameArea. Where these blocks come from? Well see soon enough wen we implement the WorldBuilder!
setBlockAt(pos, block)
}
}
}