-- 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 }, kinds = { 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 } } }, rooms = { { name = "field", navFrom = { "floor" }, entities = { { kind = "floor", id = "floor", x = 0, y = -0.2, z = 0 }, { kind = "hero", id = "hero", x = 0, y = 0.2, z = 4 }, { kind = "camera", id = "camera", x = 0, y = 2, z = 10 }, { kind = "hive", id = "hive", x = 0, y = 0, z = -8 }, { kind = "readout", id = "readout", x = 12, y = 12, z = 0 } } } }, rules = { { note = "An enemy walks from the moment it is made", on = "spawn", kind = "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", kind = "enemy", act = { { "addScore", amount = 100 } } }, { note = "It reaches the hero and rears up", on = "arrived", kind = "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", kind = "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' } } } } }