ysravankumar

Corona Physics problem

Feb 10th, 2012
207
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 2.02 KB | None | 0 0
  1. local physics = require("physics")
  2. physics.setDrawMode("hybrid")
  3. physics.start(true)
  4. physics.setGravity(0,9.8)
  5.  
  6. display.setStatusBar( display.HiddenStatusBar )
  7.  
  8. local bkg = display.newImage( "bkg_cor.png" )
  9.  
  10. local grass = display.newImage("grass.png")
  11. grass.x = 160; grass.y = 430
  12.  
  13. local grass2 = display.newImage("grass2.png") -- non-physical decorative overlay
  14. grass2.x = 160; grass2.y = 440
  15.  
  16. physics.addBody( grass, "static", { friction=0.5, bounce=0.3 } )
  17.  
  18.  
  19. local crates = {}
  20. local stopit = false --make it true to stop instead of pause, you wont see problem
  21. local displace = 0
  22.  
  23. --local dropCrates = timer.performWithDelay( 500, newCrate, 100 )
  24. function startagain()
  25.     physics.start(true)
  26.     if stopit then
  27.         local grass = display.newImage("grass.png")
  28.         grass.x = 160; grass.y = 430
  29.         physics.addBody( grass, "static", { friction=0.5, bounce=0.3 } )
  30.     end
  31.     if displace == 0 then
  32.         displace = 10    --change this to > 30(since crate dimension is 30), won;t see the problem
  33.     else
  34.         displace = 0
  35.     end
  36.  
  37.     SetCretes()
  38. end
  39.  
  40.  
  41.  
  42. function CreatePhysicsProblem()
  43.    for i=1,#crates do
  44.        crates[i]:removeSelf()
  45.        crates[i] = nil
  46.    end
  47.    crates = nil
  48.    crates= {}
  49.    if stopit then
  50.     physics.stop()
  51.    else
  52.     physics.pause()
  53.    end
  54.    timer.performWithDelay( 1000, startagain )
  55.  
  56. end
  57.  
  58. function SetCretes()
  59.     local j = display.newImageRect("crate.png",30,30);
  60.     crates[#crates+1] = j
  61.     j.x = 60+displace
  62.     j.y = 405--335
  63.     physics.addBody( j, { density=3, friction=.500, bounce=0} )
  64.  
  65.     local j = display.newImageRect("crate.png",30,30);
  66.     crates[#crates+1] = j
  67.     j.x = 60+displace
  68.     j.y = 368
  69.     physics.addBody( j, { density=3, friction=.500, bounce=0} )
  70.  
  71.     local j = display.newImageRect("crate.png",30,30);
  72.     crates[#crates+1] = j
  73.     j.x = 60+displace
  74.     j.y = 330--402
  75.     physics.addBody( j, { density=3, friction=.500, bounce=0} )
  76.  
  77.     timer.performWithDelay( 2000, CreatePhysicsProblem)
  78. end
  79.  
  80. SetCretes()
Advertisement
Add Comment
Please, Sign In to add comment