singe/testScripts/author/tail.game
2026-09-14 22:32:53 -05:00

73 lines
3.4 KiB
Text

-- The long tail, in 2D: a sprite sheet stepped by state, a map of tiles, and MIDI notes as an
-- event -- the pieces a rhythm game or a maze game needs.
return {
title = "Author test: the long tail",
size = { w = 720, h = 480 },
layers = { { kind = "overlay" } },
vars = { score = 0, notes = 0 },
types = {
runner = { look = { kind = "sprite", file = "testScripts/strip.png", frames = 5, anchor = "feet" },
behaviours = { { kind = "frames", fps = 10, states = "idle=1-1, walk=3-5, walkLeft=1-2" },
{ kind = "keys", player = 1, left = "LEFT", right = "RIGHT" },
{ kind = "mover", speed = 120, clamp = true } } },
-- The same sheet, drawn facing right only: facing left mirrors it, and rz turns a frame.
mirrored = { look = { kind = "sprite", file = "testScripts/strip.png", frames = 5, anchor = "feet" },
behaviours = { { kind = "frames", fps = 10, states = "idle=1-1, walk=3-5" },
{ kind = "keys", player = 1, left = "LEFT", right = "RIGHT" },
{ kind = "mover", speed = 120, clamp = true },
{ kind = "sound", hit = "testScripts/crackle.wav", volume = 30 } } },
floor = { look = { kind = "grid", file = "testScripts/checker.png", tile = 32, columns = 2, map = "1 2 1 2 1; 2 1 2 1 2; 3 4 3 4 3" } },
spinner = { look = { kind = "sprite", file = "testScripts/checker.png" }, behaviours = { { kind = "spin", rate = 90 } } },
fire = { look = { kind = "particles", r = 255, g = 140, b = 40, rate = 60, size = 10, speed = 80, life = 0.8 } },
readout = { look = { kind = "text", text = "", r = 235, g = 235, b = 245 } }
},
rooms = {
{ name = "stage",
entities = {
{ type = "floor", id = "floor", x = 200, y = 300 },
{ type = "runner", id = "runner", x = 360, y = 300 },
{ type = "mirrored", id = "mirror", x = 360, y = 420 },
{ type = "mirrored", id = "tilted", x = 120, y = 200, rz = 30 },
{ type = "spinner", id = "spinner", x = 560, y = 200, rz = 45 },
{ type = "fire", id = "fire", x = 640, y = 400 },
{ type = "readout", id = "readout", x = 12, y = 12 }
} }
},
rules = {
{ note = "Moving means walking",
on = "frame", each = "runner",
when = { { "test", expr = "self.dx != 0" } },
act = { { "setState", entity = "self", state = "walk" } } },
{ note = "Still means idle",
on = "frame", each = "runner",
when = { { "test", expr = "self.dx == 0" } },
act = { { "setState", entity = "self", state = "idle" } } },
{ note = "The mirrored one walks the same",
on = "frame", each = "mirrored",
when = { { "test", expr = "self.dx != 0" } },
act = { { "setState", entity = "self", state = "walk" } } },
{ note = "Middle C is a quiet click as well",
on = "midi", pitch = 60,
act = { { "playSound", file = "testScripts/crackle.wav", volume = 40 } } },
{ note = "Middle C scores",
on = "midi", pitch = 60,
act = { { "addScore", amount = 10 },
{ "addVar", name = "notes", amount = 1 } } },
{ note = "Any other note is counted",
on = "midi",
when = { { "test", expr = "event.pitch != 60" } },
act = { { "addVar", name = "notes", amount = 1 } } },
{ note = "The readout, every frame",
on = "frame",
act = { { "setText", entity = "readout", text = '"frame " .. runner.frame .. " " .. runner.state .. " score " .. score .. " notes " .. notes' } } }
}
}