-- called every frame, with constant delta time local capture = false local Vector3 = require "vector3" local rot = 0 local rot_spd = 0.05 local spd = 0.07 local pos = Vector3() local function Vector2(x, y) if y == nil then return {x = x, y = x} end return {x = x, y = y} end local function wrap(value, min, max) local range = max - min if value == 0 then return min end local result = value - (range * math.floor((value - min) / range)) if result == max then return min end return result end local function b2n(value) return value and 1 or 0 end function game_tick() -- ctx.initialization_needed is true first frame and every time dynamic reload is performed if ctx.initialization_needed then -- ctx.udata persists on reload ctx.udata = {} print(Vector3(5, 0, 0)) end ctx.mouse_capture = capture input_action{name="quit", control="SPACE"} input_action{name = "left", control = "A"} input_action{name = "right", control = "D"} input_action{name = "forward", control = "W"} input_action{name = "back", control = "S"} if input_action_just_pressed{name = "quit"} then if not capture then capture = true else capture = false end end local dir = Vector3(draw_camera_from_principal_axes{position = pos, yaw = rot}.direction) dir.y = 0 dir = dir:normalized() local rot_d = b2n(input_action_pressed{name = "right"}) - b2n(input_action_pressed{name = "left"}) rot = rot + rot_d * rot_spd local mov_d = b2n(input_action_pressed{name = "forward"}) - b2n(input_action_pressed{name = "back"}) -- pos = trig.v3_add(pos, trig.v3_mult(dir, spd * mov_d)) pos = pos + dir * spd * mov_d draw_billboard{position = Vector3(5, 0, 0), size = Vector2(1, 1), texture = "images/duck.png"} end