2024-02-24 16:16:09 +00:00
|
|
|
function on_init()
|
|
|
|
local cube = world:request_res("assets/cube-texture-embedded.gltf")
|
|
|
|
print("Loaded textured cube")
|
2024-02-24 19:32:06 +00:00
|
|
|
|
|
|
|
local pos = Transform.from_translation(Vec3.new(0, 0, -8.0))
|
|
|
|
|
2024-02-24 20:27:01 +00:00
|
|
|
local e = world:spawn(pos, cube)
|
2024-02-24 19:32:06 +00:00
|
|
|
print("spawned entity " .. tostring(e))
|
2024-02-25 22:06:53 +00:00
|
|
|
|
2024-02-26 01:53:20 +00:00
|
|
|
local handler = ActionHandler.new {
|
2024-02-25 22:06:53 +00:00
|
|
|
layouts = { 0 },
|
|
|
|
actions = {
|
|
|
|
MoveForwardBackward = "Axis",
|
|
|
|
MoveLeftRight = "Axis",
|
|
|
|
MoveUpDown = "Axis",
|
|
|
|
LookLeftRight = "Axis",
|
|
|
|
LookUpDown = "Axis",
|
|
|
|
LookRoll = "Axis",
|
2024-02-26 01:53:20 +00:00
|
|
|
ObjectsMoveUpDown = "Axis"
|
2024-02-25 22:06:53 +00:00
|
|
|
},
|
|
|
|
mappings = {
|
|
|
|
{
|
|
|
|
layout = 0,
|
|
|
|
binds = {
|
|
|
|
MoveForwardBackward = {
|
|
|
|
"key:w=1.0", "key:s=-1.0"
|
|
|
|
},
|
|
|
|
MoveLeftRight = {
|
|
|
|
"key:a=-1.0", "key:d=1.0"
|
|
|
|
},
|
|
|
|
MoveUpDown = {
|
|
|
|
"key:c=1.0", "key:z=-1.0"
|
|
|
|
},
|
|
|
|
LookLeftRight = {
|
|
|
|
"key:left=-1.0", "key:right=1.0",
|
|
|
|
"mouse:axis:x"
|
|
|
|
},
|
|
|
|
LookUpDown = {
|
|
|
|
"key:up=-1.0", "key:down=1.0",
|
|
|
|
"mouse:axis:y",
|
|
|
|
},
|
|
|
|
LookRoll = {
|
|
|
|
"key:e=-1.0", "key:q=1.0",
|
2024-02-26 01:53:20 +00:00
|
|
|
},
|
|
|
|
ObjectsMoveUpDown = {
|
|
|
|
"key:u=1.0", "key:j=-1.0"
|
2024-02-25 22:06:53 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
world:add_resource(handler)
|
2024-01-07 05:57:19 +00:00
|
|
|
end
|
|
|
|
|
2024-02-24 16:16:09 +00:00
|
|
|
--[[ function on_first()
|
2024-01-07 05:57:19 +00:00
|
|
|
print("Lua's first function was called")
|
|
|
|
end
|
|
|
|
|
|
|
|
function on_pre_update()
|
|
|
|
print("Lua's pre-update function was called")
|
2024-01-13 16:52:20 +00:00
|
|
|
end ]]
|
2024-01-07 05:57:19 +00:00
|
|
|
|
|
|
|
function on_update()
|
2024-02-19 16:27:49 +00:00
|
|
|
---@type number
|
2024-02-18 00:08:11 +00:00
|
|
|
local dt = world:resource(DeltaTime)
|
2024-02-26 01:53:20 +00:00
|
|
|
local act = world:resource(ActionHandler)
|
|
|
|
---@type number
|
|
|
|
local move_objs = act:get_axis("ObjectsMoveUpDown")
|
2024-02-18 00:08:11 +00:00
|
|
|
|
|
|
|
world:view(function (t)
|
2024-02-26 01:53:20 +00:00
|
|
|
if move_objs ~= nil then
|
|
|
|
t:translate(0, move_objs * 0.35 * dt, 0)
|
|
|
|
return t
|
|
|
|
end
|
2024-02-18 00:08:11 +00:00
|
|
|
end, Transform)
|
2024-01-07 05:57:19 +00:00
|
|
|
end
|
|
|
|
|
2024-01-13 16:52:20 +00:00
|
|
|
--[[ function on_post_update()
|
2024-01-07 05:57:19 +00:00
|
|
|
print("Lua's post-update function was called")
|
|
|
|
end
|
|
|
|
|
|
|
|
function on_last()
|
|
|
|
print("Lua's last function was called")
|
2024-01-13 16:52:20 +00:00
|
|
|
end ]]
|