init defold game

This commit is contained in:
Travis Shears 2026-05-10 17:03:18 +02:00
parent 925d375313
commit 26e88c8f03
Signed by: travisshears
GPG key ID: CB9BF1910F3F7469
20 changed files with 381 additions and 9 deletions

View file

@ -0,0 +1,30 @@
function init(self)
msg.post(".", "acquire_input_focus") -- <1>
self.vel = vmath.vector3() -- <2>
end
function update(self, dt)
local pos = go.get_position() -- <3>
pos = pos + self.vel * dt -- <4>
go.set_position(pos) -- <5>
self.vel.x = 0 -- <6>
self.vel.y = 0
-- sprite.play_flipbook("#body", "s")
rot = go.get_rotation()
print(rot)
end
function on_input(self, action_id, action)
if action_id == hash("up") then
self.vel.y = 150 -- <7>
elseif action_id == hash("down") then
self.vel.y = -150
elseif action_id == hash("left") then
self.vel.x = -150 -- <8>
elseif action_id == hash("right") then
self.vel.x = 150
end
end