From 5fdac9f4573f121ee815865824960472c711a9f4 Mon Sep 17 00:00:00 2001 From: adam-arold Date: Tue, 7 May 2019 22:13:27 +0200 Subject: [PATCH] Add a wandering monster --- .../org/hexworks/cavesofzircon/GameConfig.kt | 1 + .../attributes/types/EntityTypes.kt | 3 +++ .../cavesofzircon/builders/EntityFactory.kt | 18 +++++++++++++- .../cavesofzircon/builders/GameColors.kt | 1 + .../builders/GameTileRepository.kt | 6 +++++ .../cavesofzircon/systems/Wanderer.kt | 24 +++++++++++++++++++ .../cavesofzircon/world/GameBuilder.kt | 10 ++++++++ 7 files changed, 62 insertions(+), 1 deletion(-) create mode 100644 src/main/kotlin/org/hexworks/cavesofzircon/systems/Wanderer.kt diff --git a/src/main/kotlin/org/hexworks/cavesofzircon/GameConfig.kt b/src/main/kotlin/org/hexworks/cavesofzircon/GameConfig.kt index 1545148..be43394 100644 --- a/src/main/kotlin/org/hexworks/cavesofzircon/GameConfig.kt +++ b/src/main/kotlin/org/hexworks/cavesofzircon/GameConfig.kt @@ -24,6 +24,7 @@ object GameConfig { // entities const val FUNGI_PER_LEVEL = 15 + const val BATS_PER_LEVEL = 10 const val MAXIMUM_FUNGUS_SPREAD = 20 fun buildAppConfig() = AppConfigs.newConfig() diff --git a/src/main/kotlin/org/hexworks/cavesofzircon/attributes/types/EntityTypes.kt b/src/main/kotlin/org/hexworks/cavesofzircon/attributes/types/EntityTypes.kt index ed573cb..2c01dee 100644 --- a/src/main/kotlin/org/hexworks/cavesofzircon/attributes/types/EntityTypes.kt +++ b/src/main/kotlin/org/hexworks/cavesofzircon/attributes/types/EntityTypes.kt @@ -11,6 +11,9 @@ object Wall : BaseEntityType( object Fungus : BaseEntityType( name = "fungus"), Combatant +object Bat : BaseEntityType( + name = "bat"), Combatant + object StairsDown : BaseEntityType( name = "stairs down") diff --git a/src/main/kotlin/org/hexworks/cavesofzircon/builders/EntityFactory.kt b/src/main/kotlin/org/hexworks/cavesofzircon/builders/EntityFactory.kt index 3e3a519..83d773c 100644 --- a/src/main/kotlin/org/hexworks/cavesofzircon/builders/EntityFactory.kt +++ b/src/main/kotlin/org/hexworks/cavesofzircon/builders/EntityFactory.kt @@ -11,6 +11,7 @@ import org.hexworks.cavesofzircon.attributes.FungusSpread import org.hexworks.cavesofzircon.attributes.Vision import org.hexworks.cavesofzircon.attributes.flags.BlockOccupier import org.hexworks.cavesofzircon.attributes.flags.VisionBlocker +import org.hexworks.cavesofzircon.attributes.types.Bat import org.hexworks.cavesofzircon.attributes.types.Fungus import org.hexworks.cavesofzircon.attributes.types.Player import org.hexworks.cavesofzircon.attributes.types.StairsDown @@ -28,6 +29,7 @@ import org.hexworks.cavesofzircon.systems.InputReceiver import org.hexworks.cavesofzircon.systems.Movable import org.hexworks.cavesofzircon.systems.StairClimber import org.hexworks.cavesofzircon.systems.StairDescender +import org.hexworks.cavesofzircon.systems.Wanderer import org.hexworks.cavesofzircon.world.Game import org.hexworks.cavesofzircon.world.GameContext @@ -61,6 +63,7 @@ object EntityFactory { attributes( Vision(9), EntityPosition(), + BlockOccupier, CombatStats.create( maxHp = 100, attackValue = 10, @@ -68,7 +71,7 @@ object EntityFactory { EntityTile(GameTileRepository.PLAYER), EntityActions(Dig::class, Attack::class)) behaviors(InputReceiver) - facets(Movable, CameraMover, StairClimber, StairDescender) + facets(Movable, CameraMover, StairClimber, StairDescender, Attackable, Destructible) } fun newFungus(fungusSpread: FungusSpread = FungusSpread()) = newGameEntityOfType(Fungus) { @@ -83,5 +86,18 @@ object EntityFactory { facets(Attackable, Destructible) behaviors(FungusGrowth) } + + fun newBat() = newGameEntityOfType(Bat) { + attributes(BlockOccupier, + EntityPosition(), + EntityTile(GameTileRepository.BAT), + CombatStats.create( + maxHp = 5, + attackValue = 2, + defenseValue = 1), + EntityActions(Attack::class)) + facets(Movable, Attackable, Destructible) + behaviors(Wanderer) + } } diff --git a/src/main/kotlin/org/hexworks/cavesofzircon/builders/GameColors.kt b/src/main/kotlin/org/hexworks/cavesofzircon/builders/GameColors.kt index a6baf2f..9ebe6d3 100644 --- a/src/main/kotlin/org/hexworks/cavesofzircon/builders/GameColors.kt +++ b/src/main/kotlin/org/hexworks/cavesofzircon/builders/GameColors.kt @@ -10,6 +10,7 @@ object GameColors { val FLOOR_BACKGROUND = TileColors.fromString("#1e2320") val FUNGUS_COLOR = TileColors.fromString("#85DD1B") + val BAT_COLOR = TileColors.fromString("#2348b2") val ACCENT_COLOR = TileColors.fromString("#FFCD22") diff --git a/src/main/kotlin/org/hexworks/cavesofzircon/builders/GameTileRepository.kt b/src/main/kotlin/org/hexworks/cavesofzircon/builders/GameTileRepository.kt index d570540..ef1fb9b 100644 --- a/src/main/kotlin/org/hexworks/cavesofzircon/builders/GameTileRepository.kt +++ b/src/main/kotlin/org/hexworks/cavesofzircon/builders/GameTileRepository.kt @@ -44,6 +44,12 @@ object GameTileRepository { .withForegroundColor(GameColors.FUNGUS_COLOR) .buildCharacterTile() + val BAT = Tiles.newBuilder() + .withCharacter('b') + .withBackgroundColor(GameColors.FLOOR_BACKGROUND) + .withForegroundColor(GameColors.BAT_COLOR) + .buildCharacterTile() + val UNREVEALED = Tiles.newBuilder() .withCharacter(' ') .withBackgroundColor(GameColors.UNREVEALED_COLOR) diff --git a/src/main/kotlin/org/hexworks/cavesofzircon/systems/Wanderer.kt b/src/main/kotlin/org/hexworks/cavesofzircon/systems/Wanderer.kt new file mode 100644 index 0000000..fd886ca --- /dev/null +++ b/src/main/kotlin/org/hexworks/cavesofzircon/systems/Wanderer.kt @@ -0,0 +1,24 @@ +package org.hexworks.cavesofzircon.systems + +import org.hexworks.amethyst.api.base.BaseBehavior +import org.hexworks.amethyst.api.entity.EntityType +import org.hexworks.cavesofzircon.commands.MoveTo +import org.hexworks.cavesofzircon.extensions.GameEntity +import org.hexworks.cavesofzircon.extensions.position +import org.hexworks.cavesofzircon.extensions.sameLevelNeighborsShuffled +import org.hexworks.cavesofzircon.world.GameContext + +object Wanderer : BaseBehavior() { + + override fun update(entity: GameEntity, context: GameContext): Boolean { + val pos = entity.position + if (pos.isUnknown().not()) { + entity.executeCommand(MoveTo( + context = context, + source = entity, + position = pos.sameLevelNeighborsShuffled().first())) + return true + } + return false + } +} diff --git a/src/main/kotlin/org/hexworks/cavesofzircon/world/GameBuilder.kt b/src/main/kotlin/org/hexworks/cavesofzircon/world/GameBuilder.kt index 4b34de3..8470c18 100644 --- a/src/main/kotlin/org/hexworks/cavesofzircon/world/GameBuilder.kt +++ b/src/main/kotlin/org/hexworks/cavesofzircon/world/GameBuilder.kt @@ -2,6 +2,7 @@ package org.hexworks.cavesofzircon.world import org.hexworks.amethyst.api.entity.EntityType import org.hexworks.cavesofzircon.GameConfig +import org.hexworks.cavesofzircon.GameConfig.BATS_PER_LEVEL import org.hexworks.cavesofzircon.GameConfig.WORLD_SIZE import org.hexworks.cavesofzircon.attributes.types.Player import org.hexworks.cavesofzircon.builders.EntityFactory @@ -28,6 +29,7 @@ class GameBuilder(val worldSize: Size3D = WORLD_SIZE) { val player = addPlayer() addFungi() + addBats() val game = Game.create( player = player, @@ -56,6 +58,14 @@ class GameBuilder(val worldSize: Size3D = WORLD_SIZE) { } } + private fun addBats() = also { + repeat(world.actualSize().zLength) { level -> + repeat(BATS_PER_LEVEL) { + EntityFactory.newBat().addToWorld(level) + } + } + } + private fun GameEntity.addToWorld( atLevel: Int, atArea: Size = world.actualSize().to2DSize()): GameEntity {