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

78 lines
4.1 KiB
Text

-- Third-person action, from the catalogue: a character the keys move relative to a camera that
-- orbits it under the mouse, enemies that walk the mesh after it and bite, and a swing of the
-- sword on a key at whatever is in reach.
return {
title = "Author test: third person",
size = { w = 720, h = 480 },
layers = { { kind = "scene3d", ambient = { r = 80, g = 80, b = 100 }, fov = 60 }, { kind = "overlay" } },
vars = { score = 0, health = 5, swings = 0 },
types = {
floor = { look = { kind = "mesh", shape = "box", w = 40, h = 0.4, d = 40, r = 80, g = 100, b = 80 }, behaviours = { { kind = "solid" } } },
hero = { look = { kind = "model", file = "testScripts/Models/Fox.glb", scale = 0.008, w = 0.6, h = 0.9, d = 0.6 },
behaviours = { { kind = "keys", player = 1, left = "A", right = "D", up = "W", down = "S" },
{ kind = "character", speed = 4, jump = 5, radius = 0.3, height = 0.9 },
{ kind = "animator", idle = "Survey", walk = "Walk" } } },
camera = { look = { kind = "none" }, behaviours = { { kind = "camera", mode = "orbit", target = "hero", y = 1.2, z = 6, lookY = 0.6 } } },
enemy = { look = { kind = "model", file = "testScripts/Models/Fox.glb", scale = 0.01, w = 0.8, h = 0.9, d = 1.4 },
vars = { health = 2 },
behaviours = { { kind = "health", max = 2, ragdoll = true, linger = 1 },
{ kind = "walker", speed = 2, radius = 0.4, follow = "hero", every = 0.4, stopAt = 1.6 },
{ kind = "animator", idle = "Survey", walk = "Walk", attack = "Run" },
{ kind = "timer", name = "bite", after = 1.5, start = false } } },
hive = { look = { kind = "none" }, behaviours = { { kind = "spawner", spawns = "enemy", every = 1.5, max = 3, total = 4, points = { { x = -8, y = 0, z = -8 }, { x = 8, y = 0, z = -8 } } } } },
readout = { look = { kind = "text", text = "", r = 235, g = 235, b = 245 } },
sign = { look = { kind = "text3d", text = "ARENA", height = 0.6 } }
},
rooms = {
{ name = "field",
navFrom = { "floor" },
entities = {
{ type = "floor", id = "floor", x = 0, y = -0.2, z = 0 },
{ type = "hero", id = "hero", x = 0, y = 0.2, z = 4 },
{ type = "camera", id = "camera", x = 0, y = 2, z = 10 },
{ type = "hive", id = "hive", x = 0, y = 0, z = -8 },
{ type = "sign", id = "sign", x = 0, y = 2, z = -8 },
{ type = "readout", id = "readout", x = 12, y = 12, z = 0 }
} }
},
rules = {
{ note = "An enemy walks from the moment it is made",
on = "spawn", type = "enemy",
act = { { "setState", entity = "self", state = "walk" } } },
{ note = "Moving means walking",
on = "frame", each = "hero",
when = { { "test", expr = "self.dx != 0 or self.dy != 0" } },
act = { { "setState", entity = "self", state = "walk" } } },
{ note = "Still means idle",
on = "frame", each = "hero",
when = { { "test", expr = "self.dx == 0 and self.dy == 0" } },
act = { { "setState", entity = "self", state = "idle" } } },
{ note = "A swing of the sword hits whatever is in reach",
on = "pressed", key = "SPACE", each = "enemy",
when = { { "test", expr = 'distance(self, "hero") < 2.2' } },
act = { { "damage", entity = "self", amount = 1 }, { "addVar", name = "swings", amount = 1 } } },
{ note = "A kill",
on = "death", type = "enemy",
act = { { "addScore", amount = 100 } } },
{ note = "It reaches the hero and rears up",
on = "arrived", type = "enemy",
act = { { "setState", entity = "self", state = "attack" }, { "timerStart", entity = "self", name = "bite", after = 1.5 } } },
{ note = "The bite lands unless it was killed",
on = "timer", name = "bite", type = "enemy",
when = { { "inState", entity = "self", state = "attack" } },
act = { { "addVar", name = "health", amount = -1 }, { "timerStart", entity = "self", name = "bite", after = 1.5 } } },
{ note = "The readout, every frame",
on = "frame",
act = { { "setText", entity = "readout", text = '"score " .. score .. " health " .. health' } } }
}
}