Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!

Random Falling Items Help

edited January 2013 in Code Sharing Posts: 835

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!



  • Jmv38Jmv38 Mod
    edited January 2013 Posts: 3,297

    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 == 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 = {} = 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:

  • Posts: 835

    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.

Sign In or Register to comment.