Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- -- Setup collision filters
- local Floor_filter = { categoryBits = 1, maskBits = 0 }
- local InvisFloor_filter = { categoryBits = 2, maskBits = 0 }
- local Block_filter = { categoryBits = 4, maskBits = 0 }
- local Star_filter = { categoryBits = 8, maskBits = 2 }
- local Sprite_filter = { categoryBits = 16, maskBits = 8 }
- local Rock_filter = { categoryBits = 32, maskBits = 21 }
- ----
- -- Setup Invisible floor for Stars --
- local invisFloor = display.newRect(124.6, 300, 490, 2)
- groupOne:insert( invisFloor )
- invisFloor.itemName = "invisFloor"
- physics.addBody( invisFloor, "static")
- -- Setup player sprite --
- local Sprite = display.newImage ("Sprite.png")
- Sprite.x = 330
- Sprite.y = 290
- Sprite.itemName = "sprite"
- physics.addBody( Sprite, "static", { filter=Sprite_Filter } )
- groupOne:insert( Sprite )
- -- Setup Star and Points calling --
- local StarTime = 5000
- function newStar( ) -- Create new stars
- if ( gameState == "Play" ) then
- local Star = display.newImage ("Star.png")
- Star.x = math.random (140 , 470)
- Star.y = 303
- Star.itemName = "Star"
- physics.addBody( Star, "kinematic")
- groupOne:insert( Star )
- end
- end
- -- Register timers
- if ( gameState == "Play" ) then
- local StarSpawner = timer.performWithDelay( StarTime, newStar, 1 )
- end
- Sprite:addEventListener( "collision", Sprite )
- -- Check for Collisions
- function Sprite:collision (event) -- Game Over!
- if event.other.itemName == "rock" then
- gameState = "Pause"
- groupOne:remove( Sprite )
- physics.pause() -- Pause physics engine
- GameOver.gameEnd( Points )
- end
- if event.other.itemName == "Star" then -- Add points
- groupOne:remove( Star ) -- remove old star and reset star spawn timer
- Star = nil
- local StarSpawner = timer.performWithDelay( StarTime, newStar, 1 )
- updatePoints("add")
- end
- end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement