Advertisement
Guest User

Untitled

a guest
Sep 21st, 2017
72
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 1.83 KB | None | 0 0
  1. -- Setup collision filters
  2. local Floor_filter = { categoryBits = 1, maskBits = 0 }
  3. local InvisFloor_filter = { categoryBits = 2, maskBits = 0 }
  4. local Block_filter = { categoryBits = 4, maskBits = 0 }
  5. local Star_filter = { categoryBits = 8, maskBits = 2 }
  6. local Sprite_filter = { categoryBits = 16, maskBits = 8 }
  7. local Rock_filter = { categoryBits = 32, maskBits = 21 }
  8. ----
  9.  
  10.     -- Setup Invisible floor for Stars --
  11. local invisFloor = display.newRect(124.6, 300, 490, 2)
  12.     groupOne:insert( invisFloor )
  13.         invisFloor.itemName = "invisFloor"
  14.             physics.addBody( invisFloor, "static")
  15.            
  16.     -- Setup player sprite --
  17. local Sprite = display.newImage ("Sprite.png")
  18.     Sprite.x = 330
  19.         Sprite.y = 290
  20.             Sprite.itemName = "sprite"
  21.         physics.addBody( Sprite, "static", { filter=Sprite_Filter } )
  22.     groupOne:insert( Sprite )
  23.  
  24.     -- Setup Star and Points calling --
  25.         local StarTime = 5000
  26.  
  27. function newStar( ) -- Create new stars
  28.     if ( gameState == "Play" ) then
  29.         local Star = display.newImage ("Star.png")
  30.             Star.x = math.random (140 , 470)
  31.                 Star.y = 303
  32.             Star.itemName = "Star"
  33.         physics.addBody( Star, "kinematic")
  34.         groupOne:insert( Star )
  35.     end
  36. end
  37.  
  38. -- Register timers
  39. if ( gameState == "Play" ) then
  40.     local StarSpawner = timer.performWithDelay( StarTime, newStar, 1 )
  41. end
  42.  
  43.     Sprite:addEventListener( "collision", Sprite ) 
  44.            
  45. -- Check for Collisions
  46. function Sprite:collision (event) -- Game Over!
  47.     if event.other.itemName == "rock" then 
  48.         gameState = "Pause"
  49.         groupOne:remove( Sprite )
  50.         physics.pause() -- Pause physics engine
  51.         GameOver.gameEnd( Points )
  52.     end    
  53. if event.other.itemName == "Star" then -- Add points
  54.     groupOne:remove( Star ) -- remove old star and reset star spawn timer
  55.         Star = nil
  56.             local StarSpawner = timer.performWithDelay( StarTime, newStar, 1 )
  57.         updatePoints("add")
  58.     end
  59. end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement