init defold game
This commit is contained in:
parent
925d375313
commit
26e88c8f03
20 changed files with 381 additions and 9 deletions
30
defold_game/main/player.script
Normal file
30
defold_game/main/player.script
Normal 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
|
||||
Loading…
Add table
Add a link
Reference in a new issue