Flappy states
Terminal game169 lines of .st334 lines of generated Rust
You are dead!
(P) Play Again
(Q) Quit GameOn this page
The .st files#
intent.st
structop {
type_app {
exec = {
lang = "Rust"
}
}
lib_provider {
core = {
source = "StructOp/core"
version = "@latest"
}
Screen = {
source = "StructOp/game"
version = "@latest"
}
}
}main.st
ability "enum" "GameMode" {
values = [Menu, Playing, End]
}
ability "game" "Flappy" {
title = "Flappy Dragon"
key = ability.value.key
on_tick = [ability.switch.Tick]
}
ability "switch" "Tick" {
value = data.value.mode.current
cases = [
{ value = GameMode.Menu, run = [ability.call.MainMenu] },
{ value = GameMode.End, run = [ability.call.Dead] },
{ value = GameMode.Playing, run = [ability.call.Play] },
]
}
ability "call" "MainMenu" {
function = ability.function.main_menu
}
ability "call" "Dead" {
function = ability.function.dead
}
ability "call" "Play" {
function = ability.function.play
}
ability "function" "play" {
body = [ability.set.ToEnd]
}
# TODO: Fill in this stub later
ability "set" "ToEnd" {
target = ability.value.mode
value = GameMode.End
}
ability "function" "restart" {
body = [ability.set.ToPlaying]
}
ability "set" "ToPlaying" {
target = ability.value.mode
value = GameMode.Playing
}
ability "function" "main_menu" {
body = [
ability.clear.Menu,
ability.text.Welcome,
ability.text.Play,
ability.text.Quit,
ability.switch.MenuKey,
]
}
ability "clear" "Menu" {
}
ability "text" "Welcome" {
y = 5
message = "Welcome to Flappy Dragon"
}
ability "text" "Play" {
y = 8
message = "(P) Play Game"
}
ability "text" "Quit" {
y = 9
message = "(Q) Quit Game"
}
ability "switch" "MenuKey" {
value = data.value.key.current
cases = [
{ value = Key.p, run = [ability.call.Restart] },
{ value = Key.q, run = [ability.quit.MenuQuit] },
]
}
ability "call" "Restart" {
function = ability.function.restart
}
ability "quit" "MenuQuit" {
}
ability "function" "dead" {
body = [
ability.clear.Dead,
ability.text.Dead,
ability.text.Again,
ability.text.DeadQuit,
ability.switch.DeadKey,
]
}
ability "clear" "Dead" {
}
ability "text" "Dead" {
y = 5
message = "You are dead!"
}
ability "text" "Again" {
y = 8
message = "(P) Play Again"
}
ability "text" "DeadQuit" {
y = 9
message = "(Q) Quit Game"
}
ability "switch" "DeadKey" {
value = data.value.key.current
cases = [
{ value = Key.p, run = [ability.call.RestartAgain] },
{ value = Key.q, run = [ability.quit.DeadQuit] },
]
}
ability "call" "RestartAgain" {
function = ability.function.restart
}
ability "quit" "DeadQuit" {
}vars.st
ability "value" "mode" {
type = GameMode
initial = GameMode.Menu
}
data "value" "mode" {
of = ability.value.mode
}
ability "value" "key" {
type = Key
}
data "value" "key" {
of = ability.value.key
}Input, plan and generated Rust#
input.txt · key script, one line per frame (5 lines)
input.txt · key script, one line per frame (5 lines)
p
qstructop plan
structop plan
# program.app will be created
+ program.app (.structop/build/app)
+ ability.enum.GameMode
+ ability.game.Flappy
+ ability.switch.Tick
+ ability.call.MainMenu
+ ability.call.Dead
+ ability.call.Play
+ ability.function.play
+ ability.set.ToEnd
+ ability.function.restart
+ ability.set.ToPlaying
+ ability.function.main_menu
+ ability.clear.Menu
+ ability.text.Welcome
+ ability.text.Play
+ ability.text.Quit
+ ability.switch.MenuKey
+ ability.call.Restart
+ ability.quit.MenuQuit
+ ability.function.dead
+ ability.clear.Dead
+ ability.text.Dead
+ ability.text.Again
+ ability.text.DeadQuit
+ ability.switch.DeadKey
+ ability.call.RestartAgain
+ ability.quit.DeadQuit
+ ability.value.mode
+ ability.value.key
Plan: 1 to add, 0 to change, 0 to destroy.Generated main.rs
To inspect this generated file, select Rust in intent.st, initialize the project and export its source.
Export locally
structop init
structop apply -source -no-runTry it
cd rust-flappy-states # a folder holding the .st files above
structop init
structop plan
structop apply