Digging and help box

This commit is contained in:
nelle 2023-10-31 01:27:14 -06:00
parent f80aa94bfa
commit 79054cbbba
9 changed files with 57 additions and 22 deletions

View file

@ -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<GameEntity<EntityType>> = mutableListOf(),
) : BaseBlock<Tile>(
emptyTile = Tile.empty(),
tiles = persistentMapOf(BlockTileType.CONTENT to defaultTile)
) {
companion object {
fun createWith(entity: GameEntity<EntityType>) = 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<EntityType>) = GameBlock(
currentEntities = mutableListOf(entity)
)
}
}

View file

@ -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)

View file

@ -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++
}

View file

@ -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()
}

View file

@ -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<EntityType>,
override val target: GameEntity<EntityType>
) : EntityAction<EntityType, EntityType>

View file

@ -1,9 +1,15 @@
package group.ouroboros.potrogue.entity.systems
object Diggable /*: BaseFacet<GameContext, Dig>(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<GameContext, Dig>(Dig::class) {
override suspend fun receive(message: Dig): Response {
val (context, _, target) = message
context.world.removeEntity(target)
return Consumed
}*/
}
}

View file

@ -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

View file

@ -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, _ ->

View file

@ -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
)