The part I am having trouble in is when a ball hits an object, I want that object to be eliminated and that game is over.
– Example
local physics = require “physics”
physics.start()
physics.setGravity(0, 2)
–Status Bar
display.setStatusBar(display.HiddenStatusBar)
local sky = display.newImage( “sky.png” )
local grass = display.newImage( “grass.png” )
grass.y = 480
physics.addBody( grass, “static”, { friction=0.3 } )
local orb = display.newImage( “orb.png” )
orb.x, orb.y = 200, 100
orb.rotation = 50
physics.addBody( orb, { bounce=0.3, radius=15 } )
local function spawnOrb()
local orb = display.newImage( “orb.png” )
orb.x = math.random( 320 )
orb.y = -100
orb.rotation = 10
physics.addBody( orb, { density=2.0, friction=0.5, bounce=0.3, radius=15 } )
end
timer.performWithDelay( 9000, spawnOrb, 20 )
local bomb = display.newImage( “bomb.png” )
bomb.x, bomb.y = 200, 100
bomb.rotation = 50
physics.addBody( bomb, {bounce=0.3, radius=15 } )
local function spawnBomb()
local bomb = display.newImage( “bomb.png” )
bomb.x = math.random( 320 )
bomb.y = -100
bomb.rotation = 10
physics.addBody( bomb, { density=2.0, friction=0.5, bounce=0.3, radius=15 } )
end
display.setStatusBar (display.HiddenStatusBar)
– Hides the status bar
–Penguin
local penguin = display.newImage(“penguin.png”)
penguin.x=240
penguin.y=225
physics.addBody(penguin,“static”,{radius=45})
timer.performWithDelay( 1500, spawnBomb, 5 )
–Define wall graphics (rectangles)
local leftWall = display.newRect( 0, 0, 1, display.contentHeight )
local rightWall = display.newRect( display.contentWidth, 0, 1, display.contentHeight )
–Turn wall graphics into physical bodies
physics.addBody(leftWall, “static”, { bounce = 0.1} )
physics.addBody(rightWall, “static”, { bounce = 0.1} )
[import]uid: 132369 topic_id: 23947 reply_id: 323947[/import]
[import]uid: 52491 topic_id: 23947 reply_id: 96508[/import]