Talking about Mike Dangers game, Defold, Game development, HTML5 and Users contributions.
You surely know King, one of the leading companies when we talk about casual gaming. You may not know King owns a 2D cross platform game engine called Defold, it was used to create games like King’s Blossom Blast Saga and TouchArcade game of the week Hero Slide – you can find a tutorial series at this link – and it’s free to use. It may seem out of the ordinary, that a commercial game company releases its core technology for free, they think the more people who use Defold, the better the engine will be. By releasing Defold to the community, everyone can help making Defold better, by creating tutorials, by finding bugs, improving the documentation, and much more. I have to say, I agree with them. While at the moment I am leaving to you the task to explore Defold engine and its Lua language, I want to show you Björn Ritzl‘s port of Mike Dangers game using Defold, playable at this link. The source code is also intuitive and should help you to start with Defold engine:
go.property(“gravity”, vmath.vector3(0, -4500, 0))
go.property(“ground_speed”, 450)
go.property(“jump_speed”, 900)
— distance between the platforms
local PLATFORM_SPACING = 250
function init(self)
msg.post(“.”, “acquire_input_focus”)
self.velocity = vmath.vector3(self.ground_speed, 0, 0)
— the platforms each consist of a ground and ladder game object
— they are defined in game.collection
— the game object ids are sequentially named ground1, ladder1, …, ground6, ladder6
— the list will be kept ordered so that the first element will represent the platform
— at the bottom of the screen while the last element represents the platform at
— the top of the screen
self.platforms = { 1, 2, 3, 4, 5, 6 }
for i,id in ipairs(self.platforms) do
go.set_position(vmath.vector3(400, PLATFORM_SPACING * i, 0), “ground” .. id)
end
end
function update(self, dt)
msg.post(“@render:/”, “clear_color”, { color = vmath.vector4(0xaa / 0xff, 0xeea / 0xff, 1.0, 1.0) })
— ignore any movement logic while the player is climbing a ladder
if self.climbing then
return
end
— add gravity to the hero velocity
self.velocity = self.velocity + self.gravity * dt
— move the player
— if the player has moved outside the left or right edge of the
— the screen the horizontal component of the velocity is reversed
— also flip the hero sprite
local pos = go.get_position()
pos = pos + self.velocity * dt
if pos.x > 800 then
pos.x = 800
self.velocity.x = -self.velocity.x
sprite.set_hflip(“#sprite”, true)
elseif pos.x < 0 then
pos.x = 0
self.velocity.x = -self.velocity.x
sprite.set_hflip("#sprite", false)
end
go.set_position(pos)
-- reset volatile state
self.can_jump = false
end
function on_message(self, message_id, message, sender)
if message_id == hash("contact_point_response") then
if message.group == hash("ground") and not self.climbing then
-- resolve the collision by moving the hero out of the collision object
-- also reset the vertical component of the velocity
go.set_position(go.get_position() + message.normal * message.distance)
self.velocity.y = 0
self.can_jump = true
elseif message.group == hash("ladder") and not self.climbing then
self.velocity.y = 0
self.climbing = true
for i,id in ipairs(self.platforms) do
-- fade out the bottom most ground and ladder
if i == 1 then
go.animate("ground" .. id .. "#sprite", "tint.w", go.PLAYBACK_ONCE_FORWARD, 0, go.EASING_OUTCUBIC, 0.3)
go.animate("ladder" .. id .. "#sprite", "tint.w", go.PLAYBACK_ONCE_FORWARD, 0, go.EASING_OUTCUBIC, 0.3)
end
-- animate the platform downwards
-- if the platform was animated outside of the view it will
-- be moved to the top
go.animate("ground" .. id, "position.y", go.PLAYBACK_ONCE_FORWARD, go.get_position("ground" .. id).y - PLATFORM_SPACING, go.EASING_LINEAR, 0.3, 0, function()
self.climbing = false
-- if this was the first (ie bottom-most platform) we need to
-- move it to the top of the platforms
-- we also move it to the end of the list of platforms to
-- keep the order intact
-- and finally we also reset the alpha value (we faded it)
if i == 1 then
go.set("ground" .. id .. "#sprite", "tint.w", 1.0)
go.set("ladder" .. id .. "#sprite", "tint.w", 1.0)
table.insert(self.platforms, table.remove(self.platforms, i))
local pos = go.get_position("ground" .. id)
pos.y = pos.y + #self.platforms * PLATFORM_SPACING
go.set_position(pos, "ground" .. id)
end
end)
end
end
end
end
function on_input(self, action_id, action)
if action_id == hash("touch") or action_id == hash("jump") then
if action.pressed and self.can_jump then
self.velocity.y = self.jump_speed
end
end
end
The full source code is also available at this link. I suggest to have a look at Björn’s GitHub page as it’s full of interesting examples.
I will also try to publish some tutorials about Defold. Never miss an update! Subscribe, and I will bother you by email only when a new game or full source code comes out.