storyboard.removeAll() -- local forward references should go here -- --------------------------------------------------------------------------------- -- BEGINNING OF YOUR IMPLEMENTATION --------------------------------------------------------------------------------- -- Called when the scene's view does not exist: function scene:createScene( event ) local group = self.view local loadButton = display.newText( "Play", 0, 0, native.systemFont, 120 ) loadButton.x = display.contentCenterX loadButton.y = display.contentCenterY local backbutton = display.newText( "Go Back", 0, 0, native.systemFont, 120) backbutton.x = display.contentCenterX backbutton. y = display.viewableContentHeight \* 0.7 local function onTap( event ) storyboard.gotoScene( "scene\_game" ) end loadButton:addEventListener( "tap", onTap ) --local function goback( event) --storyboard.gotoScene( "scene\_splash" ) -- end --backbutton:addEventListener( "tap", goback ) group:insert( loadButton ) end -- Called BEFORE scene has moved onscreen: function scene:willEnterScene( event ) local group = self.view end -- Called immediately after scene has moved onscreen: function scene:enterScene( event ) local group = self.view end -- Called when scene is about to move offscreen: function scene:exitScene( event ) local group = self.view end -- Called AFTER scene has finished moving offscreen: function scene:didExitScene( event ) local group = self.view end -- Called prior to the removal of scene's "view" (display view) function scene:destroyScene( event ) local group = self.view end -- Called if/when overlay scene is displayed via storyboard.showOverlay() function scene:overlayBegan( event ) local group = self.view local overlay\_name = event.sceneName -- name of the overlay scene end -- Called if/when overlay scene is hidden/removed via storyboard.hideOverlay() function scene:overlayEnded( event ) local group = self.view local overlay\_name = event.sceneName -- name of the overlay scene end --------------------------------------------------------------------------------- -- END OF YOUR IMPLEMENTATION --------------------------------------------------------------------------------- -- "createScene" event is dispatched if scene's view does not exist scene:addEventListener( "createScene", scene ) -- "willEnterScene" event is dispatched before scene transition begins scene:addEventListener( "willEnterScene", scene ) -- "enterScene" event is dispatched whenever scene transition has finished scene:addEventListener( "enterScene", scene ) -- "exitScene" event is dispatched before next scene's transition begins scene:addEventListener( "exitScene", scene ) -- "didExitScene" event is dispatched after scene has finished transitioning out scene:addEventListener( "didExitScene", 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 ) -- "overlayBegan" event is dispatched when an overlay scene is shown scene:addEventListener( "overlayBegan", scene ) -- "overlayEnded" event is dispatched when an overlay scene is hidden/removed scene:addEventListener( "overlayEnded", scene ) --------------------------------------------------------------------------------- return scene
Above is scene_menu.lua
Below is scene_game.lua
--------------------------------------------------------------------------------- -- game -- Scene notes go here --------------------------------------------------------------------------------- local storyboard = require( "storyboard" ) local scene = storyboard.newScene() storyboard.purgeOnSceneChange = true local physics = require( "physics" ) physics.start() physics.setGravity( 0, T ) -- Clear previous scene storyboard.removeAll() W = display.viewableContentWidth H = display.viewableContentHeight GStart = 0 Score = 0 -- local forward references should go here -- -------------------------------------- --HIGH SCORE STUFF-- -------------------------------------- path = system.pathForFile( "Score.txt" ) local scorepath = io.open( path, "r" ) local highest = scorepath:read( "\*a" ) local highscore = tonumber(highest) --------------------------------------------------------------------------------- -- BEGINNING OF YOUR IMPLEMENTATION --------------------------------------------------------------------------------- function gamecreate() local foo = display.newImageRect("foo.png", 150, 150); foo.x = display.contentCenterX foo.y = display.contentCenterY local ground = display.newImageRect("ground.png", display.viewableContentWidth, display.viewableContentHeight \* 0.2); ground.x = display.contentCenterX ground.y = display.viewableContentHeight physics.addBody( foo, "static", {density=0, friction=0.5, bounce=0.5, filter = {maskBits = 4, categoryBits = 2}}) physics.addBody( ground, "static", {density=2, friction=0.5, bounce = 0.6, filter = {maskBits = 4, categoryBits = 2}}) local function drag( event ) if event.phase == "began" then foo.markX = foo.x --Storing X location foo.markY = foo.y --Storing Y location elseif event.phase == "moved" then local x = (event.x - event.xStart) + foo.markX local y = (event.y - event.yStart) + foo.markY foo.x, foo.y = x, y end return true end foo:addEventListener("touch",drag); GStart = GStart + 1 foo.collision = onLocalCollision foo:addEventListener( "collision", j ) end function snowing() meh = math.random( 0, 100 ) if (meh \< 33) then j = display.newImage("bsnow.png"); j.x = math.random( 1, display.viewableContentWidth ) j.y = -50 --j.rotation = math.random( -270, 270 ) physics.addBody( j, { density=0, friction=0.3, bounce=0.4, filter = {maskBits = 2, categoryBits = 4}} ) --, filter = {maskBits = 2, categoryBits = 4} elseif (meh \> 66) then j = display.newImage("gsnow.png"); j.x = math.random( 1, display.viewableContentWidth ) j.y = -50 --j.rotation = math.random( -270, 270 ) physics.addBody( j, { density=0, friction=0.3, bounce=0.2, filter = {maskBits = 2, categoryBits = 4}} ) --, filter = {maskBits = 2, categoryBits = 4} else j = display.newImage("snow.png"); j.x = math.random( 1, display.viewableContentWidth ) j.y = -50 --j.rotation = math.random( -270, 270 ) physics.addBody( j, { density=0, friction=0.2, bounce=0.5, filter = {maskBits = 2, categoryBits = 4}} ) end return lol end function addition() Score = Score + 1 end function onLocalCollision() timer.cancel( snownow ) timer.cancel( count ) local gameover = display.newText("You Lost!", W \* 0.5, H \* 0.5, "Helvetica", 100); gameover.x = W \* 0.5 gameover.y = H \* 0.2 local showmyhigh = display.newText( "Your high score is:", W \* 0.5, H \* 0.7, "Helvetica", 100); showmyhigh.x = W \* 0.5 showmyhigh.y = H \* 0.8 local showmyhigh2 = display.newText( highscore, W \* 0.5, H \* 0.7, "Helvetica", 100); showmyhigh2.x = W \* 0.5 showmyhigh2.y = showmyhigh.y + 20 local showscore = display.newText( Score , W \* 0.5, H \* 0.7, "Helvetica", 100); showscore.x = W \* 0.5 showscore.y = H \* 0.6 local replay = display.newImage( "replay.png" ) replay.x = W \* 0.2 replay.Y = H \* 0.5 local function tapped( event ) storyboard.gotoScene( "scene\_splash" ) end replay:addEventListener( "tap", tapped ) if highscore \< Score then local wow = display.newText( "High Score!", W \* 0.5, H \* 0.7, "Helvetica", 100) wow.x = W \* 0.5 wow.y = H \* 0.4 local path = system.pathForFile( "Score.txt") local file = io.open( path, "w+" ) file:write( Score ) end end -- Called when the scene's view does not exist: function scene:createScene( event ) local group = self.view gamecreate() count = timer.performWithDelay( 1000, addition, - 1) if GStart == 1 then snownow = timer.performWithDelay( 300, snowing, -1) end end -- Called BEFORE scene has moved onscreen: function scene:willEnterScene( event ) local group = self.view end -- Called immediately after scene has moved onscreen: function scene:enterScene( event ) local group = self.view end -- Called when scene is about to move offscreen: function scene:exitScene( event ) local group = self.view end -- Called AFTER scene has finished moving offscreen: function scene:didExitScene( event ) local group = self.view end -- Called prior to the removal of scene's "view" (display view) function scene:destroyScene( event ) local group = self.view end -- Called if/when overlay scene is displayed via storyboard.showOverlay() function scene:overlayBegan( event ) local group = self.view local overlay\_name = event.sceneName -- name of the overlay scene end -- Called if/when overlay scene is hidden/removed via storyboard.hideOverlay() function scene:overlayEnded( event ) local group = self.view local overlay\_name = event.sceneName -- name of the overlay scene end --------------------------------------------------------------------------------- -- END OF YOUR IMPLEMENTATION --------------------------------------------------------------------------------- -- "createScene" event is dispatched if scene's view does not exist scene:addEventListener( "createScene", scene ) -- "willEnterScene" event is dispatched before scene transition begins scene:addEventListener( "willEnterScene", scene ) -- "enterScene" event is dispatched whenever scene transition has finished scene:addEventListener( "enterScene", scene ) -- "exitScene" event is dispatched before next scene's transition begins scene:addEventListener( "exitScene", scene ) -- "didExitScene" event is dispatched after scene has finished transitioning out scene:addEventListener( "didExitScene", 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 ) -- "overlayBegan" event is dispatched when an overlay scene is shown scene:addEventListener( "overlayBegan", scene ) -- "overlayEnded" event is dispatched when an overlay scene is hidden/removed scene:addEventListener( "overlayEnded", scene ) --------------------------------------------------------------------------------- return scene