-
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
5 changed files
with
101 additions
and
17 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,5 +1,52 @@ | ||
# Keep Engine | ||
# Keep Engine - Characters | ||
|
||
## Characters | ||
## Simple characters | ||
|
||
## | ||
Simple characters are declared using the `npc` function with a `key` to identify them, a display `name`, and a `description`. Typically, a callback is registered using `onTalk`, it will be called when the `Talk` action is used on the character. | ||
|
||
The following example shows Bob, who can be talked to by the player and will answer back. | ||
|
||
```kotlin | ||
val bob = | ||
npc( | ||
"bob", | ||
"Bob", | ||
"Bob, an NPC." | ||
) onTalk { | ||
io.paragraph("${target.name}: Hello ${game.mainCharacter.name}!.") | ||
io.promptContinue() | ||
} | ||
``` | ||
|
||
## Stateful Characters | ||
|
||
Characters can also hold state, allowing them to react to the world and the player's actions. Use an overload of the `npc` function, and declare `key`, `initialState` and `states` parameters. | ||
|
||
Each state has its own `key`, also the state has `name` and `description` properties that replace the character's ones. Each state can have its own subscriptions to `onTalk` or any other actions, allowing the character to change its dialogues and behavior. Name and description are set on each state to make it easy to reflect changes on each character. | ||
|
||
The following example shows Alice, who greets the player by his name only once. | ||
|
||
```kotlin | ||
val alice = | ||
npc( | ||
"alice", | ||
"first-time", | ||
characterState( | ||
"first-time", | ||
"Alice", | ||
"Alice, another NPC.", | ||
) onTalk { | ||
io.paragraph("${target.name}: Oh, hi ${game.mainCharacter.name}!.") | ||
target.change("regular") | ||
io.promptContinue() | ||
}, | ||
characterState( | ||
"regular", | ||
"Alice", | ||
"Alice, another NPC.", | ||
) onTalk { | ||
io.paragraph("${target.name}: Hello.") | ||
io.promptContinue() | ||
} | ||
) | ||
``` |
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
26 changes: 20 additions & 6 deletions
26
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 |
---|---|---|
@@ -1,14 +1,28 @@ | ||
package tech.alephia.keep.samples.advanced.characters | ||
|
||
import tech.alephia.keep.core.entities.characters.characterState | ||
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() | ||
} | ||
"first-time", | ||
characterState( | ||
"first-time", | ||
"Alice", | ||
"Alice, another NPC.", | ||
) onTalk { | ||
io.paragraph("${target.name}: Oh, hi ${game.mainCharacter.name}!.") | ||
target.change("regular") | ||
io.promptContinue() | ||
}, | ||
characterState( | ||
"regular", | ||
"Alice", | ||
"Alice, another NPC.", | ||
) onTalk { | ||
io.paragraph("${target.name}: Hello.") | ||
io.promptContinue() | ||
} | ||
) |
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