singe/testScripts/author/bowling.game
2026-09-14 14:20:17 -05:00

55 lines
3 KiB
Text

-- Sports with a ball, from the catalogue: a ball on a body shoved down a lane by a charged
-- press, pins that are bodies, a gutter that is a trigger, and pins counted by how far they fell.
return {
title = "Author test: bowling",
size = { w = 720, h = 480 },
layers = { { kind = "scene3d", ambient = { r = 100, g = 100, b = 110 }, fov = 50 }, { kind = "overlay" } },
vars = { score = 0, down = 0, thrown = false },
kinds = {
lane = { look = { kind = "mesh", shape = "box", w = 3, h = 0.3, d = 24, r = 180, g = 150, b = 100 }, behaviours = { { kind = "solid" } } },
ball = { look = { kind = "mesh", shape = "sphere", w = 0.44, r = 40, g = 40, b = 60 }, behaviours = { { kind = "body", shape = "sphere", mass = 7, friction = 0.2, bounce = 0.1 } } },
pin = { look = { kind = "mesh", shape = "cylinder", w = 0.24, h = 0.8, r = 240, g = 240, b = 240 }, vars = { counted = false },
behaviours = { { kind = "body", mass = 1.5, friction = 0.5 } } },
gutter = { look = { kind = "none", w = 3, h = 1, d = 2 }, behaviours = { { kind = "trigger" } } },
camera = { look = { kind = "none" }, behaviours = { { kind = "camera", mode = "follow", target = "ball", x = 0, y = 2.5, z = 5, lookY = 0.2, lag = 0.3 } } },
readout = { look = { kind = "text", text = "", r = 235, g = 235, b = 245 } }
},
rooms = {
{ name = "alley",
entities = {
{ kind = "lane", id = "lane", x = 0, y = -0.15, z = -8 },
{ kind = "ball", id = "ball", x = 0, y = 0.3, z = 2 },
{ kind = "pin", id = "pin1", x = 0, y = 0.4, z = -16 },
{ kind = "pin", id = "pin2", x = -0.4, y = 0.4, z = -16.7 },
{ kind = "pin", id = "pin3", x = 0.4, y = 0.4, z = -16.7 },
{ kind = "pin", id = "pin4", x = -0.8, y = 0.4, z = -17.4 },
{ kind = "pin", id = "pin5", x = 0, y = 0.4, z = -17.4 },
{ kind = "pin", id = "pin6", x = 0.8, y = 0.4, z = -17.4 },
{ kind = "gutter", id = "gutter", x = 0, y = 0, z = -21 },
{ kind = "camera", id = "camera", x = 0, y = 2.5, z = 7 },
{ kind = "readout", id = "readout", x = 12, y = 12, z = 0 }
} }
},
rules = {
{ note = "The throw",
on = "pressed", key = "SPACE",
when = { { "test", expr = "not thrown" } },
act = { { "setVar", name = "thrown", value = true }, { "push", entity = "ball", x = 0, y = 0, z = -60 } } },
{ note = "A pin has fallen when it leans past the point of no return",
on = "frame", each = "pin",
when = { { "test", expr = "not self.counted and self.y < 0.25" } },
act = { { "setVar", entity = "self", name = "counted", value = true }, { "addVar", name = "down", amount = 1 }, { "addScore", amount = 10 } } },
{ note = "The ball reaches the end",
on = "enter", a = "gutter", b = "ball",
act = { { "setVar", name = "done", value = true } } },
{ note = "The readout, every frame",
on = "frame",
act = { { "setText", entity = "readout", text = '"pins down " .. down .. " score " .. score' } } }
}
}