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

81 lines
4.6 KiB
Text

-- A first-person shooter, from the catalogue: a character the keys move relative to a camera on
-- its eyes that the mouse turns, a gun that fires from the middle of the picture, and enemies
-- that walk the navigation mesh after the hero and bite when they reach it.
return {
title = "Author test: first person",
size = { w = 720, h = 480 },
layers = { { kind = "scene3d", ambient = { r = 60, g = 60, b = 80 }, fog = { r = 10, g = 10, b = 16, near = 20, far = 50 }, fov = 70 }, { kind = "overlay" } },
vars = { score = 0, health = 5, bites = 0 },
types = {
floor = { look = { kind = "mesh", shape = "box", w = 40, h = 0.4, d = 40, r = 70, g = 70, b = 80 }, behaviours = { { kind = "solid" } } },
wall = { look = { kind = "mesh", shape = "box", w = 1, h = 3, d = 40, r = 110, g = 60, b = 60 }, behaviours = { { kind = "solid" } } },
hero = { look = { kind = "none", w = 0.6, h = 1.7, 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 = 1.7 } } },
eyes = { look = { kind = "none" }, behaviours = { { kind = "camera", mode = "first", target = "hero", eye = 1.5 } } },
gun = { look = { kind = "none" }, vars = { ammo = 30 }, behaviours = { { kind = "gun", player = 1, ammo = 30, reload = "key", aim = "centre" } } },
zombie = { 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.5 },
{ kind = "walker", speed = 2.5, radius = 0.4, follow = "hero", every = 0.4, stopAt = 1.6 },
{ kind = "animator", idle = "Survey", walk = "Walk", attack = "Run", fade = 0.2 },
{ kind = "target", zones = { { name = "head", bone = "b_Head_05", w = 0.5, h = 0.5, d = 0.5 } } },
{ kind = "timer", name = "bite", after = 1.2, start = false } } },
hive = { look = { kind = "none" }, behaviours = { { kind = "spawner", spawns = "zombie", every = 2, max = 4, total = 6, points = { { x = -8, y = 0, z = -12 }, { x = 8, y = 0, z = -12 }, { x = 0, y = 0, z = -16 } } } } },
readout = { look = { kind = "text", text = "", r = 235, g = 235, b = 245 } }
},
rooms = {
{ name = "arena",
navFrom = { "floor" },
entities = {
{ type = "floor", id = "floor", x = 0, y = -0.2, z = 0 },
{ type = "wall", id = "wallL", x = -12, y = 1.5, z = 0 },
{ type = "wall", id = "wallR", x = 12, y = 1.5, z = 0 },
{ type = "hero", id = "hero", x = 0, y = 0.2, z = 8 },
{ type = "eyes", id = "eyes", x = 0, y = 1.7, z = 8 },
{ type = "gun", id = "gun1", x = 0, y = 0, z = 0 },
{ type = "hive", id = "hive", x = 0, y = 0, z = -14 },
{ type = "readout", id = "readout", x = 12, y = 12, z = 0 }
} }
},
rules = {
{ note = "A zombie walks from the moment it is made",
on = "spawn", type = "zombie",
act = { { "setState", entity = "self", state = "walk" } } },
{ note = "A shot lands",
on = "hit", type = "zombie",
act = { { "damage", entity = "self", amount = 1 }, { "addScore", amount = 50 } } },
{ note = "A headshot",
on = "hit", type = "zombie",
when = { { "hitPart", part = "head" } },
act = { { "damage", entity = "self", amount = 2 }, { "addScore", amount = 150 } } },
{ note = "It reaches the hero and rears up",
on = "arrived", type = "zombie",
act = { { "setState", entity = "self", state = "attack" }, { "timerStart", entity = "self", name = "bite", after = 1.2 } } },
{ note = "The bite lands unless it was killed",
on = "timer", name = "bite", type = "zombie",
when = { { "inState", entity = "self", state = "attack" } },
act = { { "addVar", name = "health", amount = -1 }, { "addVar", name = "bites", amount = 1 }, { "flash", r = 255, g = 40, b = 40, seconds = 0.2 },
{ "timerStart", entity = "self", name = "bite", after = 1.2 } } },
{ note = "Reload on R",
on = "pressed", key = "R",
act = { { "reload", entity = "gun1" } } },
{ note = "Out of health",
on = "frame",
when = { { "test", expr = "health <= 0" }, { "once", tag = "over", scope = "game" } },
act = { { "gameOver" } } },
{ note = "The readout, every frame",
on = "frame",
act = { { "setText", entity = "readout", text = '"score " .. score .. " health " .. health .. " ammo " .. gun1.ammo .. " zombies " .. count("zombie")' } } }
}
}