Problem with random falling objects.

Hi everyone.

I’m new to Corona and this is my first post so go easy. I hope someone can help.

I’m trying to make a simple program which generates a cirle just off the top of the screen, and at a random x coordinate, with a random radius.

The circle falls, and when it moves off the bottom of the screen it is killed, or it moves back to the top of the screen. Its x position and radius are again randomly generated and it falls again.

The goal is ultimately to have objects spawn on a timer, but never have more than x amount on screen at once.

Also, I need to know whether it’d be easier to simply make them physics objects with gravity?

My code at the moment looks like this:

____________________________________________________________________

_H = display.contentHeight;
_W = display.contentWidth;
mRand = math.random;

–create local variables
local cratercount = 5
local terrainspeed = 20
local craterx = mRand (0, _W)
local craterrad = mRand (30, 100)
local cratery = _H - _H - craterrad

–create the logic to spawn multiple craters, which is then called by the timer.
local crater = display.newCircle ( craterx,cratery - craterrad,craterrad )

–create the logic to move the crater, which is then called by the timer.
local function moveCrater()
crater.y = crater.y + terrainspeed

–kill the crater once it hits the bottom of the screen
if crater.y > _H + craterrad then
crater.x = mRand (0, _W)
crater.y = _H - _H - craterrad
craterrad = mRand (30, 100)
end
end

–creates a timer which calls the move crater function, so moves by an increment of terrainspeed
–every x milliseconds.
Mcrater = timer.performWithDelay(10, moveCrater, -1);

____________________________________________________________________

Can anyone help or point me in the right direction please?

Thanks

Dan [import]uid: 67933 topic_id: 12297 reply_id: 312297[/import]

what exactly is the program doing at the moment? [import]uid: 7116 topic_id: 12297 reply_id: 44762[/import]

The programs runs, but will not change the radius of the circle once it’s created.

It creates a random radius and x position circle. The circle falls off the screen and is then given a new x position, but the radius doesn’t change. Also, currently it only generates one circle.

What I really want to do is generate x number of circle with a delay between each. the circles fall at the same rate, and once they fall off the bottom of the screen, they are deleted. As one circle is deleted, another is created, keeping the amount on screen constant.

What is the best/most efficient/easiest way to do this?

Thanks [import]uid: 67933 topic_id: 12297 reply_id: 44766[/import]

Where you ever able to figure this out?

I am looking to do something similar and am looking for a starting point.

Thanks [import]uid: 73307 topic_id: 12297 reply_id: 48990[/import]

@dbooncha

[lua]local physics = require “physics”
physics.start()

local function generateRandomCircles()
local circle = display.newCircle(math.random(0,display.contentWidth),math.random(-300,-100),math.random(2,15))
circle:setFillColor(math.random(255),math.random(255),math.random(255),math.random(200,255))
physics.addBody(circle)
end
timer.performWithDelay(1000,generateRandomCircles,0)[/lua] [import]uid: 12482 topic_id: 12297 reply_id: 48993[/import]