This should help you move along
[code]
local physics = require(“physics”)
physics.start()
Random = math.random
local screenW = display.contentWidth
local screenH = display.contentHeight
local screenHW = screenW *.5
local screenHH = screenH *.5
local function MySimulation()
local maxObjects = 200
–physics.setDrawMode(“hybrid”)
local gameStage = display.newGroup()
local gameBounds = display.newGroup()
gameStage:insert(gameBounds)
local gameObjCol = display.newGroup()
gameStage:insert(gameObjCol)
local function MakeCollisionBounds()
local tRectTop = display.newRect(gameBounds, 0, 0, screenW, 10)
physics.addBody(tRectTop, “static”, {density = 1.0, friction = 1.0})
local tRectBottom = display.newRect(gameBounds, 0, screenH - 10, screenW, 10)
physics.addBody(tRectBottom, “static”, {density = 1.0, friction = 1.0})
local tRectLeft = display.newRect(gameBounds, 0, 0, 10, screenH)
physics.addBody(tRectLeft, “static”, {density = 1.0, friction = 1.0})
local tRectRight = display.newRect(gameBounds, screenW - 10, 0, 10, screenH)
physics.addBody(tRectRight, “static”, {density = 1.0, friction = 1.0})
end
MakeCollisionBounds()
local function ObjCollision(self, event)
if(event.phase == “began”)then
if(self.isAlive)then
self.isAlive = false
self:setFillColor(255,0,0,255)
–The 1000 ms delay is just for showing the Red(collided) color for awhile, but you do need
–a delay of 1 ms or 2 if removing within an Objects collision
timer.performWithDelay(1000, function() self:removeEventListener(“collision”, self) self:removeSelf() self = nil end)
end
end
end
local function FrameLoop()
if(gameObjCol.numChildren < maxObjects)then
–local Obj = display.newRect(gameObjCol, Random(20, 700), Random(20, 1000), 15, 15)
–or
local Obj = display.newRect(gameObjCol, screenHW, screenHH, 15, 15)
Obj.isAlive = true
Obj:setFillColor(0,0,255,255)
physics.addBody(Obj, “dynamic”, {density = 1.0, friction = 1.0, bounce = 0.5})
Obj.collision = ObjCollision
Obj:addEventListener(“collision”, Obj)
Obj:applyLinearImpulse(Random(-20,20), Random(-20,20), Obj.x, Obj.y)
end
end
Runtime:addEventListener(“enterFrame”, FrameLoop)
end
MySimulation()
[/code] [import]uid: 21331 topic_id: 23542 reply_id: 94497[/import]