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:
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
All you need to do is call runpowerup() and it will run a random powerup from the 'powerup' directory.
I am considering creating a powerup lib after the lovefest is over. what do other people think about that?
Very nice hack!
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?
spir wrote: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?
Exactly. Depending on the details, that might be enough to make the game run smoothly for someone with a bad computer who would have some occasional lag before.
spir wrote:Very nice hack!
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?
Thanks for pointing that out! I probably will, although I might not have much time to work on code during the week
Robin wrote:that might be enough to make the game run smoothly for someone with a bad computer who would have some occasional lag before.
Considering that I'm playtesting (And coding) this on an ~10 year old PC, I don't think that that will be to big of a problem, but I still will
OBEY!!! My Blog UE0gbWUgd2l0aCB0aGUgd29yZCAnSE1TRycgYXMgdGhlIHN1YmplY3Q=