by Ivan on Thu Jul 30, 2009 9:56 am
Hey. There is a 'math' module which has 'math.floor' and 'math.rand'. Check out the official Lua documentation (not the AGen manual but the official Lua language documentation) to find out more.
Secondly, your code has a huge memory leak. You are drawing on the canvas once every 16 ms but you never 'clear' it. Therefore the canvas keeps on growing in size. I would recommend calling "meter:clear ( )" before you redraw the scene.
Next, I would suggest you have a separate table object for each bomb. You can store all bombs in a table like so:
bomblist = {} -- create a list of bombs
table.insert ( bomblist, bombobject ) -- add a bomb to the list
You can get the size of the list like so:
numberofbombs = #bomblist
Then, you can access your bombs via an index:
bomblist[4] -- returns the fourth bomb
table.remove ( bomblist, 4 ) -- removes the fourth bomb from the list
Just be careful because removing an object from the table like so, changes the indexes of all other objects in the table.
Study up on how tables work and you should get some interesting ideas.