THE CREATURE

This commit is contained in:
nelle 2023-11-04 02:56:42 -06:00
parent 3df26cd0c2
commit acf1ab4842
6 changed files with 55 additions and 10 deletions

View file

@ -4,6 +4,7 @@ import group.ouroboros.potrogue.entity.attributes.EntityActions
import group.ouroboros.potrogue.entity.attributes.EntityPosition import group.ouroboros.potrogue.entity.attributes.EntityPosition
import group.ouroboros.potrogue.entity.attributes.EntityTile import group.ouroboros.potrogue.entity.attributes.EntityTile
import group.ouroboros.potrogue.entity.attributes.flags.BlockOccupier import group.ouroboros.potrogue.entity.attributes.flags.BlockOccupier
import group.ouroboros.potrogue.entity.attributes.types.Creature
import group.ouroboros.potrogue.entity.attributes.types.Player import group.ouroboros.potrogue.entity.attributes.types.Player
import group.ouroboros.potrogue.entity.attributes.types.Wall import group.ouroboros.potrogue.entity.attributes.types.Wall
import group.ouroboros.potrogue.entity.messages.Dig import group.ouroboros.potrogue.entity.messages.Dig
@ -47,4 +48,12 @@ object EntityFactory {
behaviors(InputReceiver) behaviors(InputReceiver)
facets(Movable, CameraMover) facets(Movable, CameraMover)
} }
fun newCreature() = newGameEntityOfType(Creature) {
attributes(BlockOccupier,
EntityPosition(),
EntityTile(GameTileRepository.CREATURE))
facets()
behaviors()
}
} }

View file

@ -12,4 +12,7 @@ object GameColors {
// Player Color? // Player Color?
val accentColor = TileColor.fromString("#94e2d5") val accentColor = TileColor.fromString("#94e2d5")
//The Creature Color
val creatureColor = TileColor.fromString("#f9e2af")
} }

View file

@ -37,4 +37,10 @@ object GameTileRepository {
.withForegroundColor(accentColor) .withForegroundColor(accentColor)
.buildCharacterTile() .buildCharacterTile()
//The Creature Tile
val CREATURE = Tile.newBuilder()
.withCharacter('☻')
.withBackgroundColor(GameColors.floorBackgroundColor)
.withForegroundColor(GameColors.creatureColor)
.buildCharacterTile()
} }

View file

@ -34,6 +34,7 @@ class Config {
prop.setProperty("sidebarWidth", "18") prop.setProperty("sidebarWidth", "18")
prop.setProperty("logAreaHeight", "12") prop.setProperty("logAreaHeight", "12")
prop.setProperty("helpTipHeight", "3") prop.setProperty("helpTipHeight", "3")
prop.setProperty("creaturesPerLevel", "15")
} }
val out: OutputStream = FileOutputStream(file) val out: OutputStream = FileOutputStream(file)
prop.store(out, "PotRogue Configuration File, restart game if changed value. HERE BE DRAGONS.") prop.store(out, "PotRogue Configuration File, restart game if changed value. HERE BE DRAGONS.")
@ -52,4 +53,5 @@ class Config {
val logAreaHeight: Int = (prop.getProperty("logAreaHeight")).toInt() val logAreaHeight: Int = (prop.getProperty("logAreaHeight")).toInt()
val helpTipHeight: Int = (prop.getProperty("helpTipHeight")).toInt() val helpTipHeight: Int = (prop.getProperty("helpTipHeight")).toInt()
val creaturesPerLevel: Int = (prop.getProperty("creaturesPerLevel", "15")).toInt()
} }

View file

@ -9,3 +9,7 @@ object Player : BaseEntityType(
object Wall : BaseEntityType( object Wall : BaseEntityType(
name = "wall" name = "wall"
) )
object Creature : BaseEntityType(
name = "creature"
)

View file

@ -6,7 +6,9 @@ import group.ouroboros.potrogue.data.config.Config
import group.ouroboros.potrogue.data.config.GameConfig.WORLD_SIZE import group.ouroboros.potrogue.data.config.GameConfig.WORLD_SIZE
import group.ouroboros.potrogue.entity.attributes.types.Player import group.ouroboros.potrogue.entity.attributes.types.Player
import group.ouroboros.potrogue.extensions.GameEntity import group.ouroboros.potrogue.extensions.GameEntity
import org.hexworks.amethyst.api.entity.EntityType
import org.hexworks.zircon.api.data.Position3D import org.hexworks.zircon.api.data.Position3D
import org.hexworks.zircon.api.data.Size
import org.hexworks.zircon.api.data.Size3D import org.hexworks.zircon.api.data.Size3D
// Take the size of the World as a parameter // Take the size of the World as a parameter
@ -28,6 +30,7 @@ class GameBuilder(val worldSize: Size3D) {
prepareWorld() prepareWorld()
val player = addPlayer() val player = addPlayer()
addCreature()
return Game.create( return Game.create(
player = player, player = player,
@ -40,17 +43,35 @@ class GameBuilder(val worldSize: Size3D) {
world.scrollUpBy(world.actualSize.zLength) world.scrollUpBy(world.actualSize.zLength)
} }
// Add this extension method to any GameEntity and we use the T generic type parameter to preserve the type in the return value to out function
private fun <T : EntityType> GameEntity<T>.addToWorld(
// atLevel will be used to supply the level at which we want to add the Entity
atLevel: Int,
// atArea specifies the size of the area at which we want to add the Entity this defaults to the actual size of the world (the whole level).
// this function returns the GameEntity which we called this function on which allows us to perform Method Chaining
atArea: Size = world.actualSize.to2DSize()): GameEntity<T> {
world.addAtEmptyPosition(this,
// We call addAtEmptyPosition with the supplied level
offset = Position3D.defaultPosition().withZ(atLevel),
// and we set the size using the supplied Size
size = Size3D.from2DSize(atArea))
return this
}
// Create Player using addToWorld Function
private fun addPlayer(): GameEntity<Player> { private fun addPlayer(): GameEntity<Player> {
// We create the player entity here since were going to pass it as a parameter to other objects return EntityFactory.newPlayer().addToWorld(
val player = EntityFactory.newPlayer() atLevel = Config().dungeonLevels - 1,
world.addAtEmptyPosition( atArea = world.visibleSize.to2DSize())
// We immediately add the player to the World which takes an offset and a size as a parameter }
player,
// offset determines the position where the search for empty positions will start. Here we specify that the top level will be searched starting at (0, 0) private fun addCreature() = also {
offset = Position3D.create(0, 0, Config().dungeonLevels - 1), repeat(world.actualSize.zLength) { level ->
size = world.visibleSize.copy(zLength = 0) repeat(Config().creaturesPerLevel) {
) // And we also determine that we should search only the throughout the viewport. This ensures that the player will be visible on the screen when we start the game EntityFactory.newCreature().addToWorld(level)
return player }
}
} }
companion object { companion object {