I worked hard on a game in Lua (Mega A**hole Portable) and now I'm starting a new one also in Lua. As I saw how easy it was for me to start again using parts of the code I already did, I decided it would be useful to distribute it as independant libraries. So here is the first, for inputs. With a few easy function calls this allows to see if a button is pressed, since how long, if it's released, if it's pressed since long, if it is repeating (like keyboards)... Timings are of course customizable.
It's really easy to use you basically just need to add the file to your project, execute it, call the update function every loop, and do your stuff:
I made a complete example, run index.lua in the zip file to see it, and read the readme.txt, I explained every function.Code:dofile("inputLib.lua") black = Color.new(0, 0, 0) white = Color.new(255, 255, 255) while true do screen:clear(black) INPUT.update(Controls.read()) --now do your stuff with the INPUT functions if INPUT.firstPress("cross") then --do smth, like: screen:print(250, 80, "you just pressed X!", white) end if INPUT.longPress("triangle") then --do smth, like: screen:print(250, 100, "triangle is pressed since long!", white) end screen.flip() screen.waitVblankStart() --I suggest you put a number here, to see the messages longer end
This should work in the luaplayer 0.16 (that's what Mega A**hole Portable used) although I haven't tested this exact version (I just polished it, made it readable etc), as I lent my PSP.
But this works perfectly with luaplayer windows (0.20), as it did before.
Here is the link:
Lua InputLib v0.1
If you test/use this, tell me if you like it or not, find it useful or think it's totally crap every comment you have will be welcomed (if it's no flaming/trolling of course).
Next to come, maybe, I just leave ideas there: a mod to grimfate's animLib (with image buffering, works good but need my PSP to test), a log in file library, I also have useful functions to deal with .properties files (see http://en.wikipedia.org/wiki/.properties) and many other utility functions.
Maybe people are interested in this?