Hello I’m currently working on a small platformer game for some school coursework however I am stuck on how to develop a working powerups system as there dosen’t seem to be any tutorials that I can find. If you can help is welcome.
Can you give examples of two powerups you’d like to implement? Also how will the user obtain them (pick-up, level-up, other?) and activate them (always on, special key combination, other condition?).
The general idea if there’s only like 5 or 10 powerups is probably to track which ones the user has in a Lua table. Something like:
function init(self)
self.powerups = {
doublejump = false, -- player can double-jump
blaster = false, -- player can shoot laser beams
bomb = false, -- player can plant bombs
}
end
You change the state when the player picks up or otherwise acquires the powerup:
function on_message(self, message_id, message, sender)
if message_id == hash("collision_response") and message.other_group == hash("blaster_powerup") then
self.powerups.blaster = true
go.delete(sender) -- remove the powerup
end
end
And then check against this table when the player tries to perform an action:
function on_input(self, action_id, action)
if action_id == hash("shoot") and action.pressed and self.powerups.blaster then
print("Zap!")
end
end
3 Likes
I’m planning on including a powerup that gives the player a second dash. It’s only a small game for course work. However, the code that you have shared helps me a lot thank you.
1 Like