How do I create an endless level? But one that goes down, not accross?!

(I am new to Corona)

I am looking to create a game kind of like the game ‘Fall Down’ but with a different concept. I have my ball and my platforms. It is to get to grips on how to use Corona and its features for full games with my own ideas in the future.

display.setStatusBar(display.HiddenStatusBar) local physics = require( "physics" ) physics.start( ) local background = display.newImage( "background.png" ) background.x = display.contentCenterX background.y = display.contentCenterY local floor1L = display.newImage( "floorL.png", 70, 50 ) local floor2L = display.newImage( "floorL.png", 70, 150 ) local floor3L = display.newImage( "floorL.png", 70, 250 ) local floor4L = display.newImage( "floorL.png", 70, 350 ) local floor5L = display.newImage( "floorL.png", 70, 450 ) local floor1R = display.newImage( "floorR.png", 250, 50 ) local floor2R = display.newImage( "floorR.png", 250, 150 ) local floor3R = display.newImage( "floorR.png", 250, 250 ) local floor4R = display.newImage( "floorR.png", 250, 350 ) local floor5R = display.newImage( "floorR.png", 250, 450 ) physics.addBody( floor1L, "static", {density=1, friction=1, bounce=0} ) physics.addBody( floor2L, "static", {density=1, friction=1, bounce=0} ) physics.addBody( floor3L, "static", {density=1, friction=1, bounce=0} ) physics.addBody( floor4L, "static", {density=1, friction=1, bounce=0} ) physics.addBody( floor5L, "static", {density=1, friction=1, bounce=0} ) physics.addBody( floor1R, "static", {density=1, friction=1, bounce=0} ) physics.addBody( floor2R, "static", {density=1, friction=1, bounce=0} ) physics.addBody( floor3R, "static", {density=1, friction=1, bounce=0} ) physics.addBody( floor4R, "static", {density=1, friction=1, bounce=0} ) physics.addBody( floor5R, "static", {density=1, friction=1, bounce=0} ) local ball = display.newCircle(70, 20, 10) ball:setFillColor(192, 99, 55) physics.addBody(ball, {density=.2, friction=.3, bounce=.1, radius=10} )

What I have done it create a Left and a Right side with 5 platforms on each side . (This is what I have for my app so far)  http://gyazo.com/6dc16146eec55da8b61b32312ca60d84

So there is 5 on the left and 5 on the right.

However I need it so when the ball drops down, it will create more platforms and destroy the others at the top, as well as randomly placing them along the X-axis so the gap is in different places but always has a 30 pixel gap. ( I was thinking of something to do with ‘math.random()’ but I am not sure weather to use that to randomly place the Left or Right floors on the X-axis.)  Any suggestions/help? Thanks.

[EDIT] Also, will this be the part that I start to think about putting in a parallax background?

About the 30 pixel gap:

instead of using images, use display.newRect:

local function createNewFloors()      randomno = math.random (display.contentWidth/4, display.contentWidth\*3/4) -- random width of left floor, from 1/4 to 3/4 of the screen width      floorL = display.newRect(0, display.contentHeight+60, randomno, 30)      floorR = display.newRect(randomno+30, display.contentHeight+60, display.contentWidth-(randomno+30), 30) -- content height + 60 so they will be created off screen then go up the screen      physics.addBody(floorL, {density = 99999}) -- not static or they won't move      physics.addBody(floorR, {density = 99999}) -- high density or the ball will affect its movement      group:insert(floorL)      group:insert(floorR)      floorL:setLinearVelocity(0,-50)-- so the floors go up      floorR:setLinearVelocity(0,-50)      timer.performWithDelay (1500, createNewFloors) end

just call that at the beginning of the game and every 1.5s, new floors will be created below the screen and go up it 

Haven’t actually compiled the code, so there might be something wrong with it, but that’s the general idea.

Ahh, ok. I have added an ‘eventListner’. But now I get an error with:

 group:insert(floorL) group:insert(floorR)

Also, is there a way so the floors can have my own textures? THanks.

oops, forgot to define group.

before the inserts,  add

local group = scene.view

to add your own textures you have to use an image as far as I know.

make a image that’s longer than you actually need. the size of the screen maybe. then substitute the display.newRect parts for:

randomno = math.random (display.contentWidth/4, display.contentWidth\*3/4) floorR = display.newImage("yourimage", 0 , -60) floorL = display.newImage("yourimage", 0 , -60) floorR.anchorX = 0 --reference X at left of floorR floorL.anchorX = 1 --reference X at right of floorL floorL.x = randomno floorR.x = randomno+30

Also, you gotta create walls on the sides of the screen so the ball cant go out you can create them outside the scope of the display, so they wont appear.

Ok, thanks very much. But I have one problem I am not sure where to put the 

local group = scene.view

And also wherever I put it, it creates an error - http://gyazo.com/4bae727c7349a9f7e38419e0afc2edca

Line 23 is where ‘local group = scene.view’ is. (do I need to ‘require composer’?) Thanks

[EDIT] Also, I am having trouble with creating a parallax background. A lot of the places say to do:

self.y = self.y - 3

But that gives me an error?

Anyway, I have fiddled around a bit and looking all over the internet. Now it is just the

 group:insert(floorL) group:insert(floorR)

But without those it works ( to a certain point ). Because this happens…

http://gyazo.com/ddafcaf00a4c38cfa0fa35a4205723e5

and then in the end…

http://gyazo.com/830ba6c8b913febc34675ba419693131

This ends up lagging the game. I can see that there are floors but there is to many and they are not ‘static’ Could you please help?!

About the 30 pixel gap:

instead of using images, use display.newRect:

local function createNewFloors()      randomno = math.random (display.contentWidth/4, display.contentWidth\*3/4) -- random width of left floor, from 1/4 to 3/4 of the screen width      floorL = display.newRect(0, display.contentHeight+60, randomno, 30)      floorR = display.newRect(randomno+30, display.contentHeight+60, display.contentWidth-(randomno+30), 30) -- content height + 60 so they will be created off screen then go up the screen      physics.addBody(floorL, {density = 99999}) -- not static or they won't move      physics.addBody(floorR, {density = 99999}) -- high density or the ball will affect its movement      group:insert(floorL)      group:insert(floorR)      floorL:setLinearVelocity(0,-50)-- so the floors go up      floorR:setLinearVelocity(0,-50)      timer.performWithDelay (1500, createNewFloors) end

just call that at the beginning of the game and every 1.5s, new floors will be created below the screen and go up it 

Haven’t actually compiled the code, so there might be something wrong with it, but that’s the general idea.

Ahh, ok. I have added an ‘eventListner’. But now I get an error with:

 group:insert(floorL) group:insert(floorR)

Also, is there a way so the floors can have my own textures? THanks.

oops, forgot to define group.

before the inserts,  add

local group = scene.view

to add your own textures you have to use an image as far as I know.

make a image that’s longer than you actually need. the size of the screen maybe. then substitute the display.newRect parts for:

randomno = math.random (display.contentWidth/4, display.contentWidth\*3/4) floorR = display.newImage("yourimage", 0 , -60) floorL = display.newImage("yourimage", 0 , -60) floorR.anchorX = 0 --reference X at left of floorR floorL.anchorX = 1 --reference X at right of floorL floorL.x = randomno floorR.x = randomno+30

Also, you gotta create walls on the sides of the screen so the ball cant go out you can create them outside the scope of the display, so they wont appear.

Ok, thanks very much. But I have one problem I am not sure where to put the 

local group = scene.view

And also wherever I put it, it creates an error - http://gyazo.com/4bae727c7349a9f7e38419e0afc2edca

Line 23 is where ‘local group = scene.view’ is. (do I need to ‘require composer’?) Thanks

[EDIT] Also, I am having trouble with creating a parallax background. A lot of the places say to do:

self.y = self.y - 3

But that gives me an error?

Anyway, I have fiddled around a bit and looking all over the internet. Now it is just the

 group:insert(floorL) group:insert(floorR)

But without those it works ( to a certain point ). Because this happens…

http://gyazo.com/ddafcaf00a4c38cfa0fa35a4205723e5

and then in the end…

http://gyazo.com/830ba6c8b913febc34675ba419693131

This ends up lagging the game. I can see that there are floors but there is to many and they are not ‘static’ Could you please help?!