Samples

Page contents

Full app samples

Compose 2D shooter game

compose-kstatemachine-sample — a complete Compose Multiplatform game that uses KStateMachine to drive game-object behaviour.

Android 2D shooter game (deprecated)

android-kstatemachine-sample — the original Android version. Note: KStateMachine itself has no Android dependency; this sample demonstrates how the library integrates with an Android project.

Code samples

All samples live under samples/src/commonMain/kotlin/ru/nsk/samples/ in the repository.

Getting started

Sample What it shows
MinimalSyntaxSample Simplest possible machine
MinimalSealedClassesSample Idiomatic sealed-class states
StdLibMinimalSealedClassesSample Usage without Kotlin Coroutines dependency
ComplexSyntaxSample Kitchen-sink demo of many syntax variants

Transitions

Sample What it shows
TypesafeTransitionSample Pass typed data from event to target state
GuardedTransitionSample Conditional / guarded transitions
CrossLevelTransitionSample Transitions across nested state levels
InheritTransitionsSample Share transitions by grouping states
UndoTransitionSample Navigate backwards (undo)
TargetlessTransitionSample Internal transitions without a state change
LocalVsExternalTransitionSample LOCAL vs EXTERNAL transition semantics

States

Sample What it shows
FinishedStateSample Final states and machine completion
FinishedEventSample Reacting to FinishedEvent
FinishedEventDataStateSample FinishedEvent combined with DataState
MutableDataStateSample Updating state data without a new event
HistoryStateSample Restore previously active sub-state on re-entry
ChoiceStateSample Route to a state dynamically via a pseudo-state
ComposedMachinesSample Nest a state machine as a child state
ParallelRegionListenersSample Listen for all-of / any-of parallel state combos

Persistence & export

Sample What it shows
SerializationEventRecordingSample Record events and restore state via serialization
PlantUmlExportSample Export machine structure to PlantUML
MermaidExportSample Export machine structure to Mermaid
PlantUmlExportWithUmlMetaInfoSample Export with UML metadata annotations
PlantUmlUnsafeExportWithExportMetaInfoSample Unsafe export with ExportMetaInfo

Coroutines & observation

Sample What it shows
FlowObservationSample Observe state changes via Kotlin Flow
AsyncEventProcessingSample Fire-and-forget / deferred event dispatch

This site uses Just the Docs, a documentation theme for Jekyll.