Dungeon map
Terminal game131 lines of .st358 lines of generated Rust
................................................................................ ................................................................................ ................................................................................ ................................................................................ ................................................................................ ................................................................................ ................................................................................ ................................................................................ ................................................................................ ................................................................................ ................................................................................ ................................................................................ ................................................................................ ................................................................................ ................................................................................ ................................................................................ ................................................................................ ................................................................................ ................................................................................ ................................................................................ ................................................................................ ................................................................................ ................................................................................ ................................................................................ ................................................................................ ................................................................................ ................................................................................ ................................................................................ ................................................................................ ................................................................................ ................................................................................ ................................................................................ ................................................................................ ................................................................................ ................................................................................ ................................................................................ ................................................................................ ................................................................................ ................................................................................ ................................................................................ ................................................................................ ................................................................................ ................................................................................ ................................................................................ ................................................................................ ................................................................................ ................................................................................ ................................................................................ ................................................................................ ................................................................................
On 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 "call" "NewMap" {
function = ability.function.new_map
}
ability "game" "Dungeon" {
title = "Dungeon Crawler"
fps = 30
on_tick = [ability.clear.Screen, ability.call.Render]
depends_on = [ability.call.NewMap]
}
ability "clear" "Screen" {
}
ability "call" "Render" {
function = ability.function.render_map
}vars.st
constant "SCREEN_WIDTH" {
type = Int
default = 80
}
constant "SCREEN_HEIGHT" {
type = Int
default = 50
}
# SCREEN_WIDTH * SCREEN_HEIGHT
constant "NUM_TILES" {
type = Int
default = 4000
}
ability "value" "tiles" {
type = Array
of = TileType
size = 4000
}
data "value" "tiles" {
of = ability.value.tiles
}map.st
ability "enum" "TileType" {
values = [Wall, Floor]
}
ability "function" "map_idx" {
params = [{ name = "x", type = Int }, { name = "y", type = Int }]
returns = Int
return = y * const.SCREEN_WIDTH + x
}
# Map::new(): every tile a floor
ability "function" "new_map" {
locals = [{ name = "i", type = Int }]
body = [ability.for.Fill]
}
ability "for" "Fill" {
counter = i
from = 0
while = i < const.NUM_TILES
next = i + 1
body = [ability.set.Floor]
}
ability "set" "Floor" {
target = ability.value.tiles[i]
value = TileType.Floor
}
ability "function" "render_map" {
locals = [{ name = "x", type = Int }, { name = "y", type = Int }]
body = [ability.for.Rows]
}
ability "for" "Rows" {
counter = y
from = 0
while = y < const.SCREEN_HEIGHT
next = y + 1
body = [ability.for.Columns]
}
ability "for" "Columns" {
counter = x
from = 0
while = x < const.SCREEN_WIDTH
next = x + 1
body = [ability.switch.Tile]
}
ability "switch" "Tile" {
value = data.value.tiles.current[map_idx(x, y)]
cases = [
{ value = TileType.Floor, run = [ability.draw.FloorTile] },
{ value = TileType.Wall, run = [ability.draw.WallTile] },
]
}
ability "draw" "FloorTile" {
x = x
y = y
glyph = "."
color = Color.yellow
}
ability "draw" "WallTile" {
x = x
y = y
glyph = "#"
color = Color.green
}Input, plan and generated Rust#
input.txt · key script, one line per frame (1 lines)
input.txt · key script, one line per frame (1 lines)
structop plan
structop plan
# program.app will be created
+ program.app (.structop/build/app)
+ ability.call.NewMap
+ ability.game.Dungeon
+ ability.clear.Screen
+ ability.call.Render
+ ability.enum.TileType
+ ability.function.map_idx
+ ability.function.new_map
+ ability.for.Fill
+ ability.set.Floor
+ ability.function.render_map
+ ability.for.Rows
+ ability.for.Columns
+ ability.switch.Tile
+ ability.draw.FloorTile
+ ability.draw.WallTile
+ ability.value.tiles
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-dungeon-map # a folder holding the .st files above
structop init
structop plan
structop apply