collision detection

help please, so im trying new things with the samples given by corona sdk, so i have this code below,

the first part generates random boxes,

the second part display the ground, 

what i want to do is when one of the boxes hits the ground i want to end the game and stop generating boxes how would i do this?

—this code generates random boxes

local newCrate = function()



rand = math.random( 50 )

local crate



if (rand < 51) then

crate = display.newImage(“crate.png”);

crate.x = 50 + math.random( 160 )

crate.y = -100

physics.addBody( crate, dynamic,{ density = 3, friction= .5, bounce = .15} )

–crate.angularVelocity=math.random(800-400)

–crate.isSleepingAllowed=false

end

–This code is the ground

local ground = display.newImage( “ground.png” )

ground.x = 160; ground.y = 445


physics.addBody( ground, “static”, { friction=0.5, bounce = -50} )

http://developer.coronalabs.com/content/game-edition-collision-detection

Please update your bookmarks to this one, everybody. :slight_smile:

http://docs.coronalabs.com/guide/physics/collisionDetection/index.html

Thanks!

Brent

Thanks for posting but i dont get the articles, i am to new to be able to understand all the terms, i was hoping you guys would help me out in simpler words, i was able to do it for one single box, but when it randomly generates boxes i dont know how to do it,check this out

so below every time i generate my own image and it drops to the ground i can make it dissapear and then it says game over, but how do you do it for what i asked before?

–set floor

local ground = display.newImage( “ground.png” )

ground.x = 160; ground.y = 445

–set crate

local crate = display.newImage( “crate.png” )

crate.x = 180; crate.y = -100;

physics.addBody( crate, { bounce= .05, friction = 1.0} )

 

------trying the collision

local gameOver = “Game Over”

 

local function onCollision(event)

if (event.phase == “began”) then

done = display.newText(gameOver,30,30,TimesNewRoman,30)

crate:removeSelf()

crate=nil

end

end

------ending the collision

This is what i need help on below

—this code generates random boxes

local newCrate = function()

rand = math.random( 50 )


local crate

if (rand < 51) then


crate = display.newImage(“crate.png”);


crate.x = 50 + math.random( 160 )


crate.y = -100


physics.addBody( crate, dynamic,{ density = 3, friction= .5, bounce = .15} )


–crate.angularVelocity=math.random(800-400)


–crate.isSleepingAllowed=false


end

–This code is the ground

local ground = display.newImage( “ground.png” )


ground.x = 160; ground.y = 445

physics.addBody( ground, “static”, { friction=0.5, bounce = -50} )

Where are you calling newCrate()?

well im really not sure where its suppose to go, i have tried, create scence, enter scene, but nothing works

http://developer.coronalabs.com/content/game-edition-collision-detection

Please update your bookmarks to this one, everybody. :slight_smile:

http://docs.coronalabs.com/guide/physics/collisionDetection/index.html

Thanks!

Brent

Thanks for posting but i dont get the articles, i am to new to be able to understand all the terms, i was hoping you guys would help me out in simpler words, i was able to do it for one single box, but when it randomly generates boxes i dont know how to do it,check this out

so below every time i generate my own image and it drops to the ground i can make it dissapear and then it says game over, but how do you do it for what i asked before?

–set floor

local ground = display.newImage( “ground.png” )

ground.x = 160; ground.y = 445

–set crate

local crate = display.newImage( “crate.png” )

crate.x = 180; crate.y = -100;

physics.addBody( crate, { bounce= .05, friction = 1.0} )

 

------trying the collision

local gameOver = “Game Over”

 

local function onCollision(event)

if (event.phase == “began”) then

done = display.newText(gameOver,30,30,TimesNewRoman,30)

crate:removeSelf()

crate=nil

end

end

------ending the collision

This is what i need help on below

—this code generates random boxes

local newCrate = function()

rand = math.random( 50 )


local crate

if (rand < 51) then


crate = display.newImage(“crate.png”);


crate.x = 50 + math.random( 160 )


crate.y = -100


physics.addBody( crate, dynamic,{ density = 3, friction= .5, bounce = .15} )


–crate.angularVelocity=math.random(800-400)


–crate.isSleepingAllowed=false


end

–This code is the ground

local ground = display.newImage( “ground.png” )


ground.x = 160; ground.y = 445

physics.addBody( ground, “static”, { friction=0.5, bounce = -50} )

Where are you calling newCrate()?

well im really not sure where its suppose to go, i have tried, create scence, enter scene, but nothing works