singe/testScripts/author/vocab.singe
2026-09-22 18:32:07 -05:00

47 lines
1.6 KiB
Text

-- A game's own vocabulary: a behaviour, a condition, and an action this game alone knows,
-- written as Author.singe writes its own manifest entries. The description names this file
-- (vocabulary = "vocab.singe"); nothing else in Forge has heard of a bob.
-- A bob: the entity rises and falls on a sine wave about where it was put.
AUTHOR.behaviours.bob = {
help = "Rises and falls about its place, height pixels either way, speed times a second.",
params = { height = "number", speed = "number" },
attach = function(instance, params)
local _, y = authorPosition(instance)
instance.bob = { height = params.height or 20, speed = params.speed or 2, base = y, at = 0 }
end,
step = function(instance, dt)
local bob = instance.bob
local x, _, z = authorPosition(instance)
bob.at = bob.at + dt * bob.speed
nodeSetPosition(instance.node, x, bob.base + math.sin(bob.at) * bob.height, z)
end
}
-- Whether an instance bobs: a condition of this game's own.
AUTHOR.conditions.bobbing = {
help = "An instance has a bob.",
params = { entity = "entity" },
emit = function(p) return "vocabBobbing(" .. p.entity .. ")" end
}
-- Sets how high an instance bobs: an action of this game's own.
AUTHOR.actions.setBob = {
help = "Changes how high an instance bobs.",
params = { entity = "entity", height = "number" },
emit = function(p) return "vocabSetBob(" .. p.entity .. ", " .. p.height .. ")" end
}
function vocabBobbing(instance)
return (instance ~= nil) and (instance.bob ~= nil)
end
function vocabSetBob(instance, height)
if instance and instance.bob then
instance.bob.height = height
end
end