Re: LOVEFEST III: Chance. Space shooter dev log
Posted: Sun Nov 04, 2012 11:03 pm
Very nice hack!Nsmurf wrote:No screenshot, but I'm willing to post some code on my powerup system.
Basically it enumerates the 'powerup' directory, and stores all the files inside it in a table. It gets a random value from that table, and then runs it with love.filesystem.load().
This allows me to create as many powerups as I want, and have them automatically added to the game without any unnecessary code!
This is actually salvaged code from an old project, but still very useful!
Here is the code currently located in powerup.lua:
All you need to do is call runpowerup() and it will run a random powerup from the 'powerup' directory.Code: Select all
function getpowerups(dir) powerups = love.filesystem.enumerate(dir) return powerups[math.random(#powerups)] end function runpowerup() powerupc = love.filesystem.load('powerup/'..getpowerups('powerup')) powerupc() end
Here is an example powerup:
I am considering creating a powerup lib after the lovefest is over. what do other people think about that?Code: Select all
player.speed = 200
Why don't you "enumerate" the powerup files once only at load? Actually, you could even load (compile) them all into Lua funcs, using love.filesystem.load, keep them into an array of funcs, and on power-up run one of them by chance, couldn't you?
Denis