How to end game after objects reach a certain y position

Hey! So I am trying to have my game end when a certain number of objects go past a certain why position. so if brick.y > 520 then game is over. 

Here is my code. I don’t know how to carry this action out. Please help if you can. Thanks!


– level1.lua


system.activate(“multitouch”)

local storyboard = require( “storyboard” )

local scene = storyboard.newScene()

local widget = require( “widget” )

– include Corona’s “physics” library

local physics = require “physics”

physics.start(); physics.pause()

physics.setGravity( 0, 6 )


– forward declarations and other locals

local screenW, screenH, halfW = display.contentWidth, display.contentHeight, display.contentWidth*0.5

MainMenuRelease = function( event )

storyboard.gotoScene( “menu”, “fade”, 500 )

return true – indicates successful touch

end

function scene:createScene( event )

local group = self.view

– create a grey rectangle as the backdrop

local background = display.newRect( 0, 0, screenW, screenH )

background.anchorX = 0

background.anchorY = 0

MainMenu = widget.newButton

{

defaultFile = “button.png”,

overFile = “button-over.png”,

label = “Main Menu”,

emboss = true,

onPress = MainMenuPress,

onRelease = MainMenuRelease,

}

MainMenu.x = 100; MainMenu.y = 500

group:insert( background )

group:insert( MainMenu )

end

local function throwBrick()

bricks = display.newImage( “smallcrate.png”, 100 + math.random(200), -100 )

physics.addBody( bricks, { density=3.0, friction=0.5, bounce=0.05 } )

bricks.rotation = math.random(360)

scene.view:insert(bricks)

end

timer.performWithDelay( 750, throwBrick, 90000000000000000000)

– Called immediately after scene has moved onscreen:

function scene:enterScene( event )

local group = self.view

physics.start()

end

– Called when scene is about to move offscreen:

function scene:exitScene( event )

local group = self.view

physics.stop()

end

– If scene’s view is removed, scene:destroyScene() will be called just prior to:

function scene:destroyScene( event )

local group = self.view

package.loaded[physics] = nil

physics = nil

if MainMenu then

MainMenu:removeSelf() – widgets must be manually removed

MainMenu = nil

end

if bricks then

bricks:removeSelf() – widgets must be manually removed

bricks = nil

end

end


– END OF YOUR IMPLEMENTATION


– “createScene” event is dispatched if scene’s view does not exist

scene:addEventListener( “createScene”, scene )

– “enterScene” event is dispatched whenever scene transition has finished

scene:addEventListener( “enterScene”, scene )

– “exitScene” event is dispatched whenever before next scene’s transition begins

scene:addEventListener( “exitScene”, scene )

– “destroyScene” event is dispatched before view is unloaded, which can be

– automatically unloaded in low memory situations, or explicitly via a call to

– storyboard.purgeScene() or storyboard.removeScene().

scene:addEventListener( “destroyScene”, scene )


return scene