diff --git a/src/main/kotlin/group/ouroboros/potrogue/blocks/GameBlock.kt b/src/main/kotlin/group/ouroboros/potrogue/blocks/GameBlock.kt index 3e8bb93..8451719 100644 --- a/src/main/kotlin/group/ouroboros/potrogue/blocks/GameBlock.kt +++ b/src/main/kotlin/group/ouroboros/potrogue/blocks/GameBlock.kt @@ -14,26 +14,24 @@ import org.hexworks.zircon.api.data.Tile import org.hexworks.zircon.api.data.base.BaseBlock class GameBlock( - private var defaultTile: Tile = WALL, + private var defaultTile: Tile = FLOOR, // We added currentEntities, which is just a mutable list of Entity objects, which is empty by default private val currentEntities: MutableList> = mutableListOf(), ) : BaseBlock( emptyTile = Tile.empty(), tiles = persistentMapOf(BlockTileType.CONTENT to defaultTile) ) { - - companion object { - - fun createWith(entity: GameEntity) = GameBlock( - currentEntities = mutableListOf(entity) - ) + init { + updateContent() } + val isWall: Boolean + get() = defaultTile == WALL + val isFloor: Boolean get() = defaultTile == FLOOR - val isWall: Boolean - get() = defaultTile == WALL + // We add a property which tells whether this block is just a floor (similar to isWall) val isEmptyFloor: Boolean @@ -71,10 +69,18 @@ class GameBlock( content = when { // Checking if the player is at this block. If yes, it is displayed on top entityTiles.contains(PLAYER) -> PLAYER + entityTiles.contains(WALL) -> WALL // Otherwise, the first Entity is displayed if present entityTiles.isNotEmpty() -> entityTiles.first() // Or the default tile if not else -> defaultTile } } + + companion object { + + fun createWith(entity: GameEntity) = GameBlock( + currentEntities = mutableListOf(entity) + ) + } } diff --git a/src/main/kotlin/group/ouroboros/potrogue/builders/EntityFactory.kt b/src/main/kotlin/group/ouroboros/potrogue/builders/EntityFactory.kt index 680656f..3431c28 100644 --- a/src/main/kotlin/group/ouroboros/potrogue/builders/EntityFactory.kt +++ b/src/main/kotlin/group/ouroboros/potrogue/builders/EntityFactory.kt @@ -1,11 +1,14 @@ package group.ouroboros.potrogue.builders +import group.ouroboros.potrogue.entity.attributes.EntityActions import group.ouroboros.potrogue.entity.attributes.EntityPosition import group.ouroboros.potrogue.entity.attributes.EntityTile import group.ouroboros.potrogue.entity.attributes.flags.BlockOccupier import group.ouroboros.potrogue.entity.attributes.types.Player import group.ouroboros.potrogue.entity.attributes.types.Wall +import group.ouroboros.potrogue.entity.messages.Dig import group.ouroboros.potrogue.entity.systems.CameraMover +import group.ouroboros.potrogue.entity.systems.Diggable import group.ouroboros.potrogue.entity.systems.InputReceiver import group.ouroboros.potrogue.entity.systems.Movable import group.ouroboros.potrogue.world.GameContext @@ -30,7 +33,7 @@ object EntityFactory { BlockOccupier, EntityTile(GameTileRepository.WALL) ) - //facets(Diggable) + facets(Diggable) } // We add a function for creating a newPlayer and call newGameEntityOfType with our previously created Player type. @@ -39,7 +42,7 @@ object EntityFactory { attributes( EntityPosition(), EntityTile(GameTileRepository.PLAYER), - //EntityActions(Dig::class) + EntityActions(Dig::class) ) behaviors(InputReceiver) facets(Movable, CameraMover) diff --git a/src/main/kotlin/group/ouroboros/potrogue/builders/WorldBuilder.kt b/src/main/kotlin/group/ouroboros/potrogue/builders/WorldBuilder.kt index 6c7c497..20d56ec 100644 --- a/src/main/kotlin/group/ouroboros/potrogue/builders/WorldBuilder.kt +++ b/src/main/kotlin/group/ouroboros/potrogue/builders/WorldBuilder.kt @@ -46,7 +46,7 @@ class WorldBuilder (private val worldSize: Size3D) { pos.sameLevelNeighborsShuffled().plus(pos).forEach { neighbor -> // And we only care about the positions which have a corresponding block (when they are not outside the game world) blocks.whenPresent(neighbor) { block -> - if (block.isFloor) { + if (block.isEmptyFloor) { floors++ } else rocks++ } diff --git a/src/main/kotlin/group/ouroboros/potrogue/data/config/Config.kt b/src/main/kotlin/group/ouroboros/potrogue/data/config/Config.kt index f67a427..9b0126d 100644 --- a/src/main/kotlin/group/ouroboros/potrogue/data/config/Config.kt +++ b/src/main/kotlin/group/ouroboros/potrogue/data/config/Config.kt @@ -11,7 +11,6 @@ import java.util.* val prop = Properties() - class Config { private val file = File("./run/potrogue.conf") private val prop = Properties() @@ -34,12 +33,14 @@ class Config { prop.setProperty("dungeonLevels", "2") prop.setProperty("sidebarWidth", "18") prop.setProperty("logAreaHeight", "12") + prop.setProperty("helpTipHeight", "3") } val out: OutputStream = FileOutputStream(file) prop.store(out, "PotRogue Configuration File, restart game if changed value.") } } - //Convert values from the config file to in-code variables, so we can use them later, also make them public. + //Convert values from the config file to in-code variables, + // so we can use them later, also make them public because I said so. val windowWidth: Int = (prop.getProperty("windowWidth")).toInt() val windowHeight: Int = (prop.getProperty("windowHeight")).toInt() @@ -49,4 +50,5 @@ class Config { val sidebarWidth: Int = (prop.getProperty("sidebarWidth")).toInt() val logAreaHeight: Int = (prop.getProperty("logAreaHeight")).toInt() + val helpTipHeight: Int = (prop.getProperty("helpTipHeight")).toInt() } \ No newline at end of file diff --git a/src/main/kotlin/group/ouroboros/potrogue/entity/messages/Dig.kt b/src/main/kotlin/group/ouroboros/potrogue/entity/messages/Dig.kt new file mode 100644 index 0000000..a5caeb2 --- /dev/null +++ b/src/main/kotlin/group/ouroboros/potrogue/entity/messages/Dig.kt @@ -0,0 +1,11 @@ +package group.ouroboros.potrogue.entity.messages + +import group.ouroboros.potrogue.extensions.GameEntity +import group.ouroboros.potrogue.world.GameContext +import org.hexworks.amethyst.api.entity.EntityType + +data class Dig( + override val context: GameContext, + override val source: GameEntity, + override val target: GameEntity +) : EntityAction diff --git a/src/main/kotlin/group/ouroboros/potrogue/entity/systems/Diggable.kt b/src/main/kotlin/group/ouroboros/potrogue/entity/systems/Diggable.kt index fa606ba..9cd4c46 100644 --- a/src/main/kotlin/group/ouroboros/potrogue/entity/systems/Diggable.kt +++ b/src/main/kotlin/group/ouroboros/potrogue/entity/systems/Diggable.kt @@ -1,9 +1,15 @@ package group.ouroboros.potrogue.entity.systems -object Diggable /*: BaseFacet(Dig::class)*/ { - /*override suspend fun receive(message: Dig): Response { +import group.ouroboros.potrogue.entity.messages.Dig +import group.ouroboros.potrogue.world.GameContext +import org.hexworks.amethyst.api.Consumed +import org.hexworks.amethyst.api.Response +import org.hexworks.amethyst.api.base.BaseFacet + +object Diggable : BaseFacet(Dig::class) { + override suspend fun receive(message: Dig): Response { val (context, _, target) = message context.world.removeEntity(target) return Consumed - }*/ + } } \ No newline at end of file diff --git a/src/main/kotlin/group/ouroboros/potrogue/extensions/EntityExtensions.kt b/src/main/kotlin/group/ouroboros/potrogue/extensions/EntityExtensions.kt index d69742f..821f2f2 100644 --- a/src/main/kotlin/group/ouroboros/potrogue/extensions/EntityExtensions.kt +++ b/src/main/kotlin/group/ouroboros/potrogue/extensions/EntityExtensions.kt @@ -7,9 +7,6 @@ import org.hexworks.amethyst.api.Consumed import org.hexworks.amethyst.api.Pass import org.hexworks.amethyst.api.Response -val AnyGameEntity.occupiesBlock: Boolean - get() = findAttribute(BlockOccupier::class).isPresent - // We define this function as an extension function on AnyGameEntity. // This means that from now on we can call tryActionsOn on any of our entities! // It is also suspending fun because the receiveMessage function we call later is also a suspending function. @@ -32,3 +29,6 @@ suspend fun AnyGameEntity.tryActionsOn(context: GameContext, target: AnyGameEnti } return result } + +val AnyGameEntity.occupiesBlock: Boolean + get() = findAttribute(BlockOccupier::class).isPresent diff --git a/src/main/kotlin/group/ouroboros/potrogue/view/PlayView.kt b/src/main/kotlin/group/ouroboros/potrogue/view/PlayView.kt index f5bcd58..797b8e5 100644 --- a/src/main/kotlin/group/ouroboros/potrogue/view/PlayView.kt +++ b/src/main/kotlin/group/ouroboros/potrogue/view/PlayView.kt @@ -32,6 +32,13 @@ class PlayView (private val grid: TileGrid, private val game: Game = GameBuilder .withAlignmentWithin(screen, ComponentAlignment.BOTTOM_RIGHT) .build() + //Create help tooltip + val helpTip = Components.panel() + .withPreferredSize(Config().windowWidth - Config().sidebarWidth, Config().helpTipHeight) + .withPosition(Config().sidebarWidth, 38 - Config().helpTipHeight) + .withDecorations(box(title = "Help")) + .build() + //Create Game view val gameComponent = Components.panel() .withPreferredSize(game.world.visibleSize.to2DSize()) @@ -45,7 +52,7 @@ class PlayView (private val grid: TileGrid, private val game: Game = GameBuilder .withAlignmentWithin(screen, ComponentAlignment.TOP_RIGHT) .build() - screen.addComponents(sidebar, logArea, gameComponent) + screen.addComponents(sidebar, logArea, helpTip, gameComponent) // modify our PlayView to update our world whenever the user presses a key screen.handleKeyboardEvents(KeyboardEventType.KEY_PRESSED) { event, _ -> diff --git a/src/main/kotlin/group/ouroboros/potrogue/world/GameBuilder.kt b/src/main/kotlin/group/ouroboros/potrogue/world/GameBuilder.kt index 307c703..b900408 100644 --- a/src/main/kotlin/group/ouroboros/potrogue/world/GameBuilder.kt +++ b/src/main/kotlin/group/ouroboros/potrogue/world/GameBuilder.kt @@ -15,7 +15,7 @@ class GameBuilder(val worldSize: Size3D) { // We define the visible size which is our viewport of the world private val visibleSize = Size3D.create( xLength = Config().windowWidth - Config().sidebarWidth, - yLength = Config().windowHeight - Config().logAreaHeight, + yLength = Config().windowHeight - Config().logAreaHeight - Config().helpTipHeight, zLength = 1 )