I was once building publicly and it seemed to be popular. I axed that project, but I decided to build publicly again. I’m not sure what I’ll make yet and I don’t have as much time as I did before, but if and when I update the project, you’ll see the progression here:
https://github.com/RaymondDuke/tinkering-defold
The only thing I’ve done so far is create a simple 8-direction movement system for the player.
I’m tracking input like this:
function on_input(self, action_id, action)
if action_id == hash("right") then
self.input.x = 1
elseif action_id == hash("left") then
self.input.x = -1
end
if action_id == hash("up") then
self.input.y = 1
elseif action_id == hash("down") then
self.input.y = -1
end
end
I also added a dash mechanic to the input that has a cooldown attached. It looks like this:
if action_id == hash("spacebar") and action.released then
if self.total_dashes > 0 then
self.total_dashes = self.total_dashes - 1
self.dashing = true
msg.post("/guis", "show_dashes", { dashes = self.total_dashes } )
else
print("out of dashes")
end
end
The update function takes the inputs and updates the player accordingly.
function update(self, dt)
local pos = go.get_position()
if vmath.length(self.input) > 1 then
self.input = vmath.normalize(self.input)
end
if self.dashing then
go.animate(".", "position", go.PLAYBACK_ONCE_FORWARD, pos + self.input * 250, go.EASING_LINEAR, .2, 0, function()
timer.delay(self.dash_cooldown, false, function()
self.total_dashes = self.total_dashes + 1
msg.post("/guis", "show_dashes", { dashes = self.total_dashes } )
end)
end)
self.dashing = false
end
pos = pos + self.input * self.speed * dt
go.set_position(pos)
print(self.input)
self.input = vmath.vector3()
end
And finally, there’s an indicator on the UI that shows how many dashes are available. I am using messages instead of a module because it was faster to set up that way. This is just a project for tinkering around and building fast!
Some ideas of things to do next:
- Use a particle effect to add a trail when dashing
- Generate items for the player to pickup (coins, xp, powerups?)
- Add a camera and have it follow the player