I am making a game on codea, and I want to add random falling items from the top of the screen, Please, any help is appreciated!
Someone posted this some time ago (sorry pal, i didnt write your name in, just claim youself as the author)
--Main
supportedOrientations(PORTRAIT_ANY)
function setup()
displayMode(FULLSCREEN)
objectTable = {}
lastGenerated = ElapsedTime
interval = 1
num = 1
table.insert(objectTable,Objects(math.random(1,WIDTH-1),math.random(1,4),num))
end
function draw()
spriteMode(CENTER)
sprite("Cargo Bot:Opening Background",WIDTH/2,HEIGHT/2,WIDTH,HEIGHT)
pushStyle()
spriteMode(CENTER)
randomObjectGenerate()
popStyle()
end
function randomObjectGenerate()
for k,v in pairs(objectTable) do
v:draw()
end
if ElapsedTime - lastGenerated > interval then
lastGenerated = ElapsedTime
num = num + 1
table.insert(objectTable,Objects(math.random(1,WIDTH-1),math.random(1,4),num))
end
for k,v in pairs(objectTable) do
if v.a.y < 0 or (v.a.x > WIDTH or v.a.x< 0) or v.a.info.id == 0 then
table.remove(objectTable,k)
v.a:destroy()
v.a = nil
v=nil
end
end
end
--Objects
Objects = class()
function Objects:init(x,cat,id)
-- you can accept and set parameters here
self.a = physics.body(CIRCLE,20)
self.a.x = x
self.a.y = HEIGHT
self.a.gravityScale = 1
self.a.restitution = 0.0
self.a.interpolate = true
self.asleepingAllowed = true
self.flag = true
self.category = cat
self.a.info = {}
self.a.info.id = id
end
function Objects:draw()
pushMatrix()
translate(self.a.x, self.a.y)
if self.category == 1 then
sprite("Cargo Bot:Condition Blue",0,0,50,50)
elseif self.category == 2 then
sprite("Cargo Bot:Condition Green",0,0,50,50)
elseif self.category == 3 then
sprite("Cargo Bot:Condition Red",0,0,50,50)
elseif self.category == 4 then
sprite("Cargo Bot:Condition Yellow",0,0,50,50)
end
popMatrix()
end
function Objects:touched(touch)
-- Codea does not automatically call this method
end
And there is this excellent program from space monkey:
http://www.twolivesleft.com/Codea/Talk/discussion/2014/bouncing-balls/p1
Thanks, but is it possible to add sprites to this and gravity to move the sprite to pick up the items? Anyone who helps will be credited.