-
Notifications
You must be signed in to change notification settings - Fork 10
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
d8e7f78
commit 3779a0e
Showing
12 changed files
with
193 additions
and
11 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
8 changes: 8 additions & 0 deletions
8
src/main/kotlin/org/hexworks/cavesofzircon/commands/CameraMoveDirection.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
package org.hexworks.cavesofzircon.commands | ||
|
||
enum class CameraMoveDirection { | ||
UP, | ||
DOWN, | ||
LEFT, | ||
RIGHT | ||
} |
11 changes: 11 additions & 0 deletions
11
src/main/kotlin/org/hexworks/cavesofzircon/commands/MoveCamera.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
package org.hexworks.cavesofzircon.commands | ||
|
||
import org.hexworks.amethyst.api.entity.EntityType | ||
import org.hexworks.cavesofzircon.extensions.GameCommand | ||
import org.hexworks.cavesofzircon.extensions.GameEntity | ||
import org.hexworks.cavesofzircon.world.GameContext | ||
import org.hexworks.zircon.api.data.impl.Position3D | ||
|
||
data class MoveCamera(override val context: GameContext, | ||
override val source: GameEntity<EntityType>, | ||
val previousPosition: Position3D) : GameCommand<EntityType> |
14 changes: 14 additions & 0 deletions
14
src/main/kotlin/org/hexworks/cavesofzircon/commands/MoveTo.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
package org.hexworks.cavesofzircon.commands | ||
|
||
import org.hexworks.amethyst.api.entity.EntityType | ||
import org.hexworks.cavesofzircon.extensions.GameCommand | ||
import org.hexworks.cavesofzircon.extensions.GameEntity | ||
import org.hexworks.cavesofzircon.world.GameContext | ||
import org.hexworks.zircon.api.data.impl.Position3D | ||
|
||
/** | ||
* A [GameCommand] representing moving [source] to [position]. | ||
*/ | ||
data class MoveTo(override val context: GameContext, | ||
override val source: GameEntity<EntityType>, | ||
val position: Position3D) : GameCommand<EntityType> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
36 changes: 36 additions & 0 deletions
36
src/main/kotlin/org/hexworks/cavesofzircon/systems/CameraMover.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
package org.hexworks.cavesofzircon.systems | ||
|
||
import org.hexworks.amethyst.api.Consumed | ||
import org.hexworks.amethyst.api.base.BaseFacet | ||
import org.hexworks.amethyst.api.entity.EntityType | ||
import org.hexworks.cavesofzircon.commands.MoveCamera | ||
import org.hexworks.cavesofzircon.extensions.GameCommand | ||
import org.hexworks.cavesofzircon.extensions.position | ||
import org.hexworks.cavesofzircon.world.GameContext | ||
|
||
object CameraMover : BaseFacet<GameContext>() { | ||
|
||
override fun executeCommand(command: GameCommand<out EntityType>) = command.responseWhenCommandIs(MoveCamera::class) { cmd -> | ||
val (context, source, previousPosition) = cmd | ||
val world = context.world | ||
val screenPos = source.position - world.visibleOffset() // 1 | ||
val halfHeight = world.visibleSize().yLength / 2 // 2 | ||
val halfWidth = world.visibleSize().xLength / 2 // 3 | ||
val currentPosition = source.position | ||
when { // 4 | ||
previousPosition.y > currentPosition.y && screenPos.y < halfHeight -> { | ||
world.scrollOneBackward() | ||
} | ||
previousPosition.y < currentPosition.y && screenPos.y > halfHeight -> { | ||
world.scrollOneForward() | ||
} | ||
previousPosition.x > currentPosition.x && screenPos.x < halfWidth -> { | ||
world.scrollOneLeft() | ||
} | ||
previousPosition.x < currentPosition.x && screenPos.x > halfWidth -> { | ||
world.scrollOneRight() | ||
} | ||
} | ||
Consumed | ||
} | ||
} |
31 changes: 31 additions & 0 deletions
31
src/main/kotlin/org/hexworks/cavesofzircon/systems/InputReceiver.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
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.world.GameContext | ||
import org.hexworks.zircon.api.uievent.KeyCode | ||
import org.hexworks.zircon.api.uievent.KeyboardEvent | ||
|
||
object InputReceiver : BaseBehavior<GameContext>() { | ||
|
||
override fun update(entity: GameEntity<out EntityType>, context: GameContext): Boolean { | ||
val (_, _, uiEvent, player) = context | ||
val currentPos = player.position | ||
if (uiEvent is KeyboardEvent) { | ||
val newPosition = when (uiEvent.code) { | ||
KeyCode.KEY_W -> currentPos.withRelativeY(-1) | ||
KeyCode.KEY_A -> currentPos.withRelativeX(-1) | ||
KeyCode.KEY_S -> currentPos.withRelativeY(1) | ||
KeyCode.KEY_D -> currentPos.withRelativeX(1) | ||
else -> { | ||
currentPos | ||
} | ||
} | ||
player.executeCommand(MoveTo(context, player, newPosition)) | ||
} | ||
return true | ||
} | ||
} |
32 changes: 32 additions & 0 deletions
32
src/main/kotlin/org/hexworks/cavesofzircon/systems/Movable.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
package org.hexworks.cavesofzircon.systems | ||
|
||
import org.hexworks.amethyst.api.CommandResponse | ||
import org.hexworks.amethyst.api.Consumed | ||
import org.hexworks.amethyst.api.Pass | ||
import org.hexworks.amethyst.api.Response | ||
import org.hexworks.amethyst.api.base.BaseFacet | ||
import org.hexworks.amethyst.api.entity.EntityType | ||
import org.hexworks.cavesofzircon.attributes.types.Player | ||
import org.hexworks.cavesofzircon.commands.MoveCamera | ||
import org.hexworks.cavesofzircon.commands.MoveTo | ||
import org.hexworks.cavesofzircon.extensions.GameCommand | ||
import org.hexworks.cavesofzircon.extensions.position | ||
import org.hexworks.cavesofzircon.world.GameContext | ||
|
||
object Movable : BaseFacet<GameContext>() { | ||
|
||
override fun executeCommand(command: GameCommand<out EntityType>) = command.responseWhenCommandIs(MoveTo::class) { (context, entity, position) -> | ||
val world = context.world | ||
val previousPosition = entity.position // 1 | ||
var result: Response = Pass | ||
if (world.moveEntity(entity, position)) { | ||
result = if (entity.type == Player) { // 2 | ||
CommandResponse(MoveCamera( // 3 | ||
context = context, | ||
source = entity, | ||
previousPosition = previousPosition)) | ||
} else Consumed | ||
} | ||
result | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
<configuration> | ||
<appender name="STDOUT" class="ch.qos.logback.core.ConsoleAppender"> | ||
<encoder> | ||
<pattern>%d{HH:mm:ss.SSS} [%thread] %-5level %logger{36} - %msg%n</pattern> | ||
</encoder> | ||
</appender> | ||
|
||
<root level="WARN"> | ||
<appender-ref ref="STDOUT" /> | ||
</root> | ||
|
||
<logger name="org.hexworks.cavesofzircon" level="INFO" /> | ||
|
||
</configuration> |