THE CREATURE
This commit is contained in:
parent
3df26cd0c2
commit
acf1ab4842
6 changed files with 55 additions and 10 deletions
|
@ -4,6 +4,7 @@ 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.Creature
|
||||
import group.ouroboros.potrogue.entity.attributes.types.Player
|
||||
import group.ouroboros.potrogue.entity.attributes.types.Wall
|
||||
import group.ouroboros.potrogue.entity.messages.Dig
|
||||
|
@ -47,4 +48,12 @@ object EntityFactory {
|
|||
behaviors(InputReceiver)
|
||||
facets(Movable, CameraMover)
|
||||
}
|
||||
|
||||
fun newCreature() = newGameEntityOfType(Creature) {
|
||||
attributes(BlockOccupier,
|
||||
EntityPosition(),
|
||||
EntityTile(GameTileRepository.CREATURE))
|
||||
facets()
|
||||
behaviors()
|
||||
}
|
||||
}
|
|
@ -12,4 +12,7 @@ object GameColors {
|
|||
|
||||
// Player Color?
|
||||
val accentColor = TileColor.fromString("#94e2d5")
|
||||
|
||||
//The Creature Color
|
||||
val creatureColor = TileColor.fromString("#f9e2af")
|
||||
}
|
|
@ -37,4 +37,10 @@ object GameTileRepository {
|
|||
.withForegroundColor(accentColor)
|
||||
.buildCharacterTile()
|
||||
|
||||
//The Creature Tile
|
||||
val CREATURE = Tile.newBuilder()
|
||||
.withCharacter('☻')
|
||||
.withBackgroundColor(GameColors.floorBackgroundColor)
|
||||
.withForegroundColor(GameColors.creatureColor)
|
||||
.buildCharacterTile()
|
||||
}
|
|
@ -34,6 +34,7 @@ class Config {
|
|||
prop.setProperty("sidebarWidth", "18")
|
||||
prop.setProperty("logAreaHeight", "12")
|
||||
prop.setProperty("helpTipHeight", "3")
|
||||
prop.setProperty("creaturesPerLevel", "15")
|
||||
}
|
||||
val out: OutputStream = FileOutputStream(file)
|
||||
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 helpTipHeight: Int = (prop.getProperty("helpTipHeight")).toInt()
|
||||
val creaturesPerLevel: Int = (prop.getProperty("creaturesPerLevel", "15")).toInt()
|
||||
}
|
|
@ -9,3 +9,7 @@ object Player : BaseEntityType(
|
|||
object Wall : BaseEntityType(
|
||||
name = "wall"
|
||||
)
|
||||
|
||||
object Creature : BaseEntityType(
|
||||
name = "creature"
|
||||
)
|
|
@ -6,7 +6,9 @@ import group.ouroboros.potrogue.data.config.Config
|
|||
import group.ouroboros.potrogue.data.config.GameConfig.WORLD_SIZE
|
||||
import group.ouroboros.potrogue.entity.attributes.types.Player
|
||||
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.Size
|
||||
import org.hexworks.zircon.api.data.Size3D
|
||||
|
||||
// Take the size of the World as a parameter
|
||||
|
@ -28,6 +30,7 @@ class GameBuilder(val worldSize: Size3D) {
|
|||
prepareWorld()
|
||||
|
||||
val player = addPlayer()
|
||||
addCreature()
|
||||
|
||||
return Game.create(
|
||||
player = player,
|
||||
|
@ -40,17 +43,35 @@ class GameBuilder(val worldSize: Size3D) {
|
|||
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> {
|
||||
// We create the player entity here since we’re going to pass it as a parameter to other objects
|
||||
val player = EntityFactory.newPlayer()
|
||||
world.addAtEmptyPosition(
|
||||
// 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)
|
||||
offset = Position3D.create(0, 0, Config().dungeonLevels - 1),
|
||||
size = world.visibleSize.copy(zLength = 0)
|
||||
) // 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
|
||||
return player
|
||||
return EntityFactory.newPlayer().addToWorld(
|
||||
atLevel = Config().dungeonLevels - 1,
|
||||
atArea = world.visibleSize.to2DSize())
|
||||
}
|
||||
|
||||
private fun addCreature() = also {
|
||||
repeat(world.actualSize.zLength) { level ->
|
||||
repeat(Config().creaturesPerLevel) {
|
||||
EntityFactory.newCreature().addToWorld(level)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
companion object {
|
||||
|
|
Loading…
Reference in a new issue