LOVEFEST III: Chance. Big Red Button

Show off your games, demos and other (playable) creations.
spir
Citizen
Posts: 76
Joined: Wed Oct 17, 2012 1:12 pm

Re: LOVEFEST III: Chance. Space shooter dev log

Post by spir »

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:

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
All you need to do is call runpowerup() and it will run a random powerup from the 'powerup' directory.

Here is an example powerup:

Code: Select all

player.speed = 200
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?

Denis
... la vita e estrany ...
User avatar
Robin
The Omniscient
Posts: 6506
Joined: Fri Feb 20, 2009 4:29 pm
Location: The Netherlands
Contact:

Re: LOVEFEST III: Chance. Space shooter dev log

Post by Robin »

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.
Help us help you: attach a .love.
User avatar
Nsmurf
Party member
Posts: 191
Joined: Fri Jul 27, 2012 1:58 am
Location: West coast.

Re: LOVEFEST III: Chance. Big Red Button

Post by Nsmurf »

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=
Post Reply

Who is online

Users browsing this forum: No registered users and 0 guests