Skip to content

Commit

Permalink
Add a wandering monster
Browse files Browse the repository at this point in the history
  • Loading branch information
adam-arold committed May 7, 2019
1 parent 890c370 commit 5fdac9f
Show file tree
Hide file tree
Showing 7 changed files with 62 additions and 1 deletion.
1 change: 1 addition & 0 deletions src/main/kotlin/org/hexworks/cavesofzircon/GameConfig.kt
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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")

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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

Expand Down Expand Up @@ -61,14 +63,15 @@ object EntityFactory {
attributes(
Vision(9),
EntityPosition(),
BlockOccupier,
CombatStats.create(
maxHp = 100,
attackValue = 10,
defenseValue = 5),
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) {
Expand All @@ -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)
}
}

Original file line number Diff line number Diff line change
Expand Up @@ -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")

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
24 changes: 24 additions & 0 deletions src/main/kotlin/org/hexworks/cavesofzircon/systems/Wanderer.kt
Original file line number Diff line number Diff line change
@@ -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<GameContext>() {

override fun update(entity: GameEntity<EntityType>, 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
}
}
10 changes: 10 additions & 0 deletions src/main/kotlin/org/hexworks/cavesofzircon/world/GameBuilder.kt
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -28,6 +29,7 @@ class GameBuilder(val worldSize: Size3D = WORLD_SIZE) {

val player = addPlayer()
addFungi()
addBats()

val game = Game.create(
player = player,
Expand Down Expand Up @@ -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 <T : EntityType> GameEntity<T>.addToWorld(
atLevel: Int,
atArea: Size = world.actualSize().to2DSize()): GameEntity<T> {
Expand Down

0 comments on commit 5fdac9f

Please sign in to comment.