Is this the kind of thing you were looking for?
[code]
–hides iphone status bar
–display.setStatusBar(display.HiddenStatusBar)
physics = require(“physics”)
physics.start()
physics.setGravity(0,9.8)
physics.setDrawMode( “hybrid” ) – uncomment to see physics interactions.
–physics.setDrawMode( “hybrid” ) – uncomment to see physics interactions.
–cache content dimensions and math.random for better performance
_H = display.contentHeight;
_W = display.contentWidth;
mRand = math.random;
terrainspeed = 5
maxCrater = 5
tsmod = 0
craterRate = 1000
craterMod = 0
local centerX = display.contentWidth/2;
local hitdet = display.newRect(0, 0, _W, 5)
hitdet.x = _W / 2
hitdet.y = _H - 5
hitdet:setFillColor(0, 0, 255)
physics.addBody(hitdet, “static”, {density = 1.0, friction = 0, bounce = 0, isSensor =true})
hitdet.myName = “hitDet”
local buggy = display.newRect(0, 0, 30, 30)
buggy.x = _W / 2
buggy.y = _H / 3 + _H / 3
buggy.strokeWidth = 3
buggy:setFillColor(140, 140, 140)
buggy:setStrokeColor(180, 180, 180)
function tsmodifier() --picks a random value by which to modify terrainspeed
tsmod = mRand(0, 10)
–print (tsmod)
end
function spawnCrater() – spawns a crater, checks its y position and moves it if necessary.
local crater = display.newCircle (mRand(0, _W), _H / _H, mRand(30, 100))
physics.addBody( crater, { friction=0, bounce=0, radius = crater.radius} )
crater.isSensor = true
crater.myName = “Crater”
local function moveCrater() – moves the crater
if crater then
if crater.y < _H + crater.contentHeight then
crater.y = crater.y + terrainspeed + tsmod
end
end
end
–Timer2 = timer.performWithDelay(10,moveCrater, 0)
end
local function onLocalCollision( self, event )
if ( event.phase == “began” ) then
print( self.myName … ": collision began with " … event.other.myName )
local function removecrater()
event.other:removeSelf()
end
Timer4 = timer.performWithDelay(1,removecrater, 1)
elseif ( event.phase == “ended” ) then
print( self.myName … ": collision ended with " … event.other.myName )
end
end
–crater.collision = onLocalCollision
–crater:addEventListener( “collision”, hitdet )
hitdet.collision = onLocalCollision
hitdet:addEventListener( “collision”, hitdet )
–]]
Timer1 = timer.performWithDelay(craterRate, spawnCrater, 0)
Timer3 = timer.performWithDelay(5000,tsmodifier, 0)
[/code] [import]uid: 67933 topic_id: 13471 reply_id: 49640[/import]