-
Notifications
You must be signed in to change notification settings - Fork 0
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
Showing
16 changed files
with
183 additions
and
9 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,5 @@ | ||
# Keep Engine | ||
|
||
## 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 |
---|---|---|
@@ -1,3 +1,51 @@ | ||
# Keep Engine | ||
# Keep Engine - Items | ||
|
||
## Items | ||
## Simple items | ||
|
||
The most simple items are declared using the `item` function with a `key` to identify it, a display `name`, and a `description`. Typically, a callback is registered using `onUse`, it will be called when the `Use` action is used on the item. | ||
|
||
The following example shows a potion that can be used by the player. | ||
|
||
```kotlin | ||
val potion = | ||
item( | ||
"potion", | ||
"Potion", | ||
"A potion with magical powers.", | ||
canBeTaken = true | ||
) onUse { | ||
io.paragraph("You feel magical and refreshed.") | ||
} | ||
``` | ||
|
||
## Stateful items | ||
|
||
Items can hold state, allowing the world to react and be modified by the player's actions. Use an overload of the `item` function, and declare `key`, `initialState` and `states` parameters. | ||
|
||
Each state has its own `key`, also the state have `name` and `description` properties that replace the item ones. Each state can have its own subscriptions to `onUse` and other actions, allowing the item to change its behavior. | ||
|
||
The following example shows a switch that can be turned on or off by the player. | ||
|
||
```kotlin | ||
val switch = | ||
item( | ||
"switch", | ||
"off", | ||
itemState( | ||
"off", | ||
"switch (off)", | ||
"An example of an item with state in Keep. The switch is off." | ||
) onUse { | ||
target.change("on") | ||
io.paragraph("Turn the switch on...") | ||
}, | ||
itemState( | ||
"on", | ||
"switch (on)", | ||
"An example of an item with state in Keep. The switch is on." | ||
) onUse { | ||
target.change("off") | ||
io.paragraph("Turn the switch off...") | ||
} | ||
) | ||
``` |
14 changes: 14 additions & 0 deletions
14
samples/src/main/kotlin/tech/alephia/keep/samples/advanced/characters/alice.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 tech.alephia.keep.samples.advanced.characters | ||
|
||
import tech.alephia.keep.core.entities.characters.npc | ||
import tech.alephia.keep.core.events.onTalk | ||
|
||
val alice = | ||
npc( | ||
"alice", | ||
"Alice", | ||
"Alice, another NPC." | ||
) onTalk { | ||
io.paragraph("${target.name}: Hi, how have you been?") | ||
io.promptContinue() | ||
} |
14 changes: 14 additions & 0 deletions
14
samples/src/main/kotlin/tech/alephia/keep/samples/advanced/characters/bob.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 tech.alephia.keep.samples.advanced.characters | ||
|
||
import tech.alephia.keep.core.entities.characters.npc | ||
import tech.alephia.keep.core.events.onTalk | ||
|
||
val bob = | ||
npc( | ||
"bob", | ||
"Bob", | ||
"Bob, an NPC." | ||
) onTalk { | ||
io.paragraph("${target.name}: Hello ${game.mainCharacter.name}!.") | ||
io.promptContinue() | ||
} |
5 changes: 5 additions & 0 deletions
5
samples/src/main/kotlin/tech/alephia/keep/samples/advanced/characters/john.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,5 @@ | ||
package tech.alephia.keep.samples.advanced.characters | ||
|
||
import tech.alephia.keep.core.entities.characters.mainCharacter | ||
|
||
val john = mainCharacter("player", "John") |
14 changes: 14 additions & 0 deletions
14
samples/src/main/kotlin/tech/alephia/keep/samples/advanced/items/potion.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 tech.alephia.keep.samples.advanced.items | ||
|
||
import tech.alephia.keep.core.entities.items.item | ||
import tech.alephia.keep.core.events.onUse | ||
|
||
val potion = | ||
item( | ||
"potion", | ||
"Potion", | ||
"A potion with magical powers.", | ||
canBeTaken = true | ||
) onUse { | ||
io.paragraph("You feel magical and refreshed.") | ||
} |
27 changes: 27 additions & 0 deletions
27
samples/src/main/kotlin/tech/alephia/keep/samples/advanced/items/switch.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,27 @@ | ||
package tech.alephia.keep.samples.advanced.items | ||
|
||
import tech.alephia.keep.core.entities.items.item | ||
import tech.alephia.keep.core.entities.items.itemState | ||
import tech.alephia.keep.core.events.onUse | ||
|
||
val switch = | ||
item( | ||
"switch", | ||
"off", | ||
itemState( | ||
"off", | ||
"switch (off)", | ||
"An example of an item with state in Keep. The switch is off." | ||
) onUse { | ||
target.change("on") | ||
io.paragraph("Turn the switch on...") | ||
}, | ||
itemState( | ||
"on", | ||
"switch (on)", | ||
"An example of an item with state in Keep. The switch is on." | ||
) onUse { | ||
target.change("off") | ||
io.paragraph("Turn the switch off...") | ||
} | ||
) |
20 changes: 20 additions & 0 deletions
20
samples/src/main/kotlin/tech/alephia/keep/samples/advanced/main.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,20 @@ | ||
package tech.alephia.keep.samples.advanced | ||
|
||
import tech.alephia.keep.core.Game | ||
import tech.alephia.keep.delivery.InOut | ||
import tech.alephia.keep.samples.advanced.characters.john | ||
import tech.alephia.keep.samples.advanced.scenes.keepLobby | ||
import tech.alephia.keep.samples.advanced.scenes.room | ||
|
||
fun main() { | ||
val inOut = InOut() | ||
|
||
val scenes = listOf(keepLobby, room) | ||
val game = Game(inOut, john, scenes, "keep-lobby") | ||
|
||
game.start() | ||
|
||
while (true) { | ||
game.draw() | ||
} | ||
} |
20 changes: 20 additions & 0 deletions
20
samples/src/main/kotlin/tech/alephia/keep/samples/advanced/scenes/keepLobby.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,20 @@ | ||
package tech.alephia.keep.samples.advanced.scenes | ||
|
||
import tech.alephia.keep.core.actions.* | ||
import tech.alephia.keep.core.scenes.Scene | ||
import tech.alephia.keep.core.scenes.actions | ||
import tech.alephia.keep.core.scenes.characters | ||
import tech.alephia.keep.core.scenes.items | ||
import tech.alephia.keep.samples.advanced.characters.alice | ||
import tech.alephia.keep.samples.advanced.characters.bob | ||
import tech.alephia.keep.samples.advanced.items.potion | ||
import tech.alephia.keep.samples.advanced.items.switch | ||
|
||
val commonActions = actions(Take(), Leave(), Look(), Use(), Talk()) | ||
|
||
val keepLobby = Scene( | ||
"keep-lobby", "Keep", "Keep is a text game engine.", | ||
commonActions + Goto("room", "Go to the next room"), | ||
items(potion, switch), | ||
characters(alice, bob) | ||
) |
10 changes: 10 additions & 0 deletions
10
samples/src/main/kotlin/tech/alephia/keep/samples/advanced/scenes/room.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,10 @@ | ||
package tech.alephia.keep.samples.advanced.scenes | ||
|
||
import tech.alephia.keep.core.actions.Goto | ||
import tech.alephia.keep.core.scenes.Scene | ||
import tech.alephia.keep.core.scenes.actions | ||
|
||
val room = Scene( | ||
"room", "Room", "An empty room.", | ||
actions(Goto("keep.lobby", "Go back")) | ||
) |
2 changes: 1 addition & 1 deletion
2
.../alephia/keep/samples/addingitems/main.kt → ...ia/keep/samples/basic/addingitems/main.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
2 changes: 1 addition & 1 deletion
2
...h/alephia/keep/samples/addingnpcs/main.kt → ...hia/keep/samples/basic/addingnpcs/main.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
2 changes: 1 addition & 1 deletion
2
...ephia/keep/samples/changingscenes/main.kt → ...keep/samples/basic/changingscenes/main.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
File renamed without changes.
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