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

66 lines
3.7 KiB
Text

-- Genre one of milestone 4: racing. A car on the engine's vehicle physics driven by the keys,
-- a rival that drives a track of points on its own, checkpoints that are triggers, laps counted
-- by rules, and a camera that follows.
return {
title = "Author test: racing",
size = { w = 720, h = 480 },
layers = { { kind = "scene3d", ambient = { r = 90, g = 90, b = 110 }, fov = 60 }, { kind = "overlay" } },
vars = { score = 0, laps = 0, next = 1 },
types = {
ground = { look = { kind = "mesh", shape = "box", w = 120, h = 0.4, d = 200, r = 90, g = 100, b = 90 }, behaviours = { { kind = "solid" } } },
car = { look = { kind = "mesh", shape = "box", w = 1.6, h = 0.6, d = 3.2, r = 220, g = 60, b = 60 },
behaviours = { { kind = "keys", player = 1, left = "LEFT", right = "RIGHT", up = "UP", down = "DOWN" },
{ kind = "vehicle", type = "car", torque = 900, mass = 800 } } },
rival = { look = { kind = "mesh", shape = "box", w = 1.6, h = 0.6, d = 3.2, r = 60, g = 90, b = 220 },
behaviours = { { kind = "vehicle", type = "car", torque = 700, mass = 800 },
{ kind = "racer", track = "lap", throttle = 0.5, reach = 4 } } },
gate = { look = { kind = "none", w = 10, h = 3, d = 1 }, vars = { index = 1 }, behaviours = { { kind = "trigger" } } },
camera = { look = { kind = "none" }, behaviours = { { kind = "camera", mode = "follow", target = "car", x = 0, y = 4, z = 9, lookY = 0.5, lag = 0.3 } } },
bar = { look = { kind = "mesh", shape = "box", w = 4, h = 0.3, d = 0.3, r = 200, g = 200, b = 60 },
behaviours = { { kind = "body", mass = 20 }, { kind = "joint", type = "hinge", ax = -8, ay = 2, az = -20, dx = 0, dy = 0, dz = 1 } } },
hover = { look = { kind = "mesh", shape = "box", w = 1.2, h = 0.4, d = 2, r = 60, g = 220, b = 200 },
behaviours = { { kind = "body", mass = 100, friction = 0 }, { kind = "thrust", force = 900, turn = 0.5 } } },
readout = { look = { kind = "text", text = "", r = 235, g = 235, b = 245 } }
},
rooms = {
{ name = "track",
entities = {
{ type = "ground", id = "ground", x = 0, y = -0.2, z = -40 },
{ type = "car", id = "car", x = 0, y = 0.8, z = 10 },
{ type = "rival", id = "rival", x = 4, y = 0.8, z = 12 },
{ type = "gate", id = "gate1", x = 0, y = 1.5, z = -10, vars = { index = 1 } },
{ type = "gate", id = "gate2", x = 0, y = 1.5, z = -35, vars = { index = 2 } },
{ type = "camera", id = "camera", x = 0, y = 4, z = 19 },
{ type = "bar", id = "bar", x = -6, y = 2, z = -20 },
{ type = "hover", id = "hover", x = 8, y = 0.4, z = 10 },
{ type = "readout", id = "readout", x = 12, y = 12, z = 0 }
},
tracks = {
{ name = "lap", key = "time", points = { { at = 0, x = 4, y = 0, z = -10 }, { at = 1, x = 4, y = 0, z = -35 }, { at = 2, x = 4, y = 0, z = -70 } } }
} }
},
rules = {
{ note = "Through the next gate",
on = "enter", a = "gate", b = "car",
when = { { "test", expr = "self.index == next" } },
act = { { "addVar", name = "next", amount = 1 },
{ "addScore", amount = 10 } } },
{ note = "Both gates passed: a lap",
on = "frame",
when = { { "test", expr = "next > 2" } },
act = { { "addVar", name = "laps", amount = 1 },
{ "setVar", name = "next", value = 1 } } },
{ note = "The hovercraft pushes forward on its own",
on = "frame", each = "hover",
act = { { "setVar", entity = "self", name = "dy", value = -1 } } },
{ note = "The readout, every frame",
on = "frame",
act = { { "setText", entity = "readout", text = '"speed " .. floor(car.speed) .. " next gate " .. next .. " laps " .. laps' } } }
}
}