G2A Many GEOs
SHARE
TWEET

Scenes

a guest Apr 8th, 2020 127 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. -- Scene 1 --
  2. local composer = require( "composer" )
  3. local scene = composer.newScene()
  4.  
  5. ---------------------------------------------------------------------------------
  6. -- All code outside of the listener functions will only be executed ONCE
  7. -- unless "composer.removeScene()" is called.
  8. ---------------------------------------------------------------------------------
  9.  
  10. -- local forward references should go here
  11.  
  12. ---------------------------------------------------------------------------------
  13. display.setStatusBar(display.HiddenStatusBar)
  14.  
  15. local bg
  16. local title
  17. local button
  18.  
  19. local function gotoScene2()
  20.  
  21.   composer.gotoScene("scene2", {time=800, effect="slideRight"})
  22.  
  23. end
  24. -- "scene:create
  25. function scene:create( event )
  26.  
  27.    local sceneGroup = self.view
  28.  
  29.    bg = display.newRect(display.contentCenterX, display.contentCenterY, display.contentWidth, display.contentHeight)
  30.    bg:setFillColor(0,1,0)
  31.    sceneGroup:insert(bg)
  32.  
  33.    title = display.newText("Title Screen", display.contentCenterX, display.contentCenterY, "SFAutomaton", 40)
  34.    title:setFillColor(0,0,1)
  35.    sceneGroup:insert(title)
  36.  
  37.    button = display.newRoundedRect( display.contentCenterX, display.contentHeight*.8, display.contentHeight*.2, display.contentCenterY*.5, 20)
  38.    button:setFillColor(1,0,0)
  39.    sceneGroup:insert(button)
  40.  
  41.    button:addEventListener("tap", gotoScene2)
  42.  
  43.    -- Initialize the scene here.
  44.    -- Example: add display objects to "sceneGroup", add touch listeners, etc.
  45. end
  46.  
  47. -- "scene:show()"
  48. function scene:show( event )
  49.  
  50.    local sceneGroup = self.view
  51.    local phase = event.phase
  52.  
  53.    if ( phase == "will" ) then
  54.       -- Called when the scene is still off screen (but is about to come on screen).
  55.    elseif ( phase == "did" ) then
  56.       -- Called when the scene is now on screen.
  57.       -- Insert code here to make the scene come alive.
  58.       -- Example: start timers, begin animation, play audio, etc.
  59.    end
  60. end
  61.  
  62. -- "scene:hide()"
  63. function scene:hide( event )
  64.  
  65.    local sceneGroup = self.view
  66.    local phase = event.phase
  67.  
  68.    if ( phase == "will" ) then
  69.       -- Called when the scene is on screen (but is about to go off screen).
  70.       -- Insert code here to "pause" the scene.
  71.       -- Example: stop timers, stop animation, stop audio, etc.
  72.    elseif ( phase == "did" ) then
  73.       -- Called immediately after scene goes off screen.
  74.    end
  75. end
  76.  
  77. -- "scene:destroy()"
  78. function scene:destroy( event )
  79.  
  80.    local sceneGroup = self.view
  81.  
  82.    -- Called prior to the removal of scene's view ("sceneGroup").
  83.    -- Insert code here to clean up the scene.
  84.    -- Example: remove display objects, save state, etc.
  85. end
  86.  
  87. ---------------------------------------------------------------------------------
  88.  
  89. -- Listener setup
  90. scene:addEventListener( "create", scene )
  91. scene:addEventListener( "show", scene )
  92. scene:addEventListener( "hide", scene )
  93. scene:addEventListener( "destroy", scene )
  94.  
  95. ---------------------------------------------------------------------------------
  96.  
  97. return scene
  98.  
  99. -- Scene 2 --
  100. local composer = require( "composer" )
  101. local scene = composer.newScene()
  102.  
  103. ---------------------------------------------------------------------------------
  104. -- All code outside of the listener functions will only be executed ONCE
  105. -- unless "composer:removeScene()" is called.
  106. ---------------------------------------------------------------------------------
  107.  
  108. -- local forward references should go here
  109.  
  110. ---------------------------------------------------------------------------------
  111. display.setStatusBar(display.HiddenStatusBar)
  112.  
  113. local bg
  114. local title
  115. local button
  116.  
  117. local function gotoScene1()
  118.  
  119.   composer.gotoScene("scene1", {time=800, effect="slideLeft"})
  120.  
  121. end
  122. -- "scene:create()"
  123. function scene:create( event )
  124.  
  125.    local sceneGroup = self.view
  126.  
  127.  
  128.    -- Initialize the scene here.
  129.    -- Example: add display objects to "sceneGroup", add touch listeners, etc.
  130. end
  131.  
  132. -- "scene:show()"
  133. function scene:show( event )
  134.  
  135.    local sceneGroup = self.view
  136.    local phase = event.phase
  137.  
  138.    if ( phase == "will" ) then
  139.       -- Called when the scene is still off screen (but is about to come on screen).
  140.  
  141.    elseif ( phase == "did" ) then
  142.       -- Called when the scene is now on screen.
  143.       -- Insert code here to make the scene come alive.
  144.       -- Example: start timers, begin animation, play audio, etc.
  145.       --[[
  146.       bg = display.newRect(display.contentCenterX, display.contentCenterY, display.contentWidth, display.contentHeight)
  147.       bg:setFillColor(0,0,1)
  148.       sceneGroup:insert(bg)
  149.  
  150.       title = display.newText("Game", display.contentCenterX, display.contentCenterY, "SFAutomaton", 40)
  151.       title:setFillColor(0,1,0)
  152.       sceneGroup:insert(title)
  153.       --]]
  154.       local cX, cY = display.contentCenterX, display.contentCenterY
  155.  
  156.  
  157.  
  158.       -- Initialize Rows --
  159.       local row1 = display.newRect(cX*1.1, cY*.4, cX*2, 10)
  160.       local row2 = display.newRect(cX*1.1, cY*.7, cX*2, 10)
  161.       local row3 = display.newRect(cX*1.1, cY, cX*2, 10)
  162.       local row4 = display.newRect(cX*1.1, cY*1.3, cX*2, 10)
  163.       local row5 = display.newRect(cX*1.1, cY*1.6, cX*2, 10)
  164.  
  165.       sceneGroup:insert(row1)
  166.       sceneGroup:insert(row2)
  167.       sceneGroup:insert(row3)
  168.       sceneGroup:insert(row4)
  169.       sceneGroup:insert(row5)
  170.       -- Initialize Tower Positions --
  171.       local activeTowers = {}
  172.       local positions = {}
  173.         positions[1] = display.newRect(cX*.5, cY*.4, 10, 10)
  174.         positions[2] = display.newRect(cX*.8, cY*.4, 10, 10)
  175.         positions[3] = display.newRect(cX*1.1, cY*.4, 10, 10)
  176.         positions[4] = display.newRect(cX*1.4, cY*.4, 10, 10)
  177.         positions[5] = display.newRect(cX*1.7, cY*.4, 10, 10)
  178.         positions[6] = display.newRect(cX*.5, cY*.7, 10, 10)
  179.         positions[7] = display.newRect(cX*.8, cY*.7, 10, 10)
  180.         positions[8] = display.newRect(cX*1.1, cY*.7, 10, 10)
  181.         positions[9] = display.newRect(cX*1.4, cY*.7, 10, 10)
  182.         positions[10] = display.newRect(cX*1.7, cY*.7, 10, 10)
  183.         positions[11] = display.newRect(cX*.5, cY, 10, 10)
  184.         positions[12] = display.newRect(cX*.8, cY, 10, 10)
  185.         positions[13] = display.newRect(cX*1.1, cY, 10, 10)
  186.         positions[14] = display.newRect(cX*1.4, cY, 10, 10)
  187.         positions[15] = display.newRect(cX*1.7, cY, 10, 10)
  188.         positions[16] = display.newRect(cX*.5, cY*1.3, 10, 10)
  189.         positions[17] = display.newRect(cX*.8, cY*1.3, 10, 10)
  190.         positions[18] = display.newRect(cX*1.1, cY*1.3, 10, 10)
  191.         positions[19] = display.newRect(cX*1.4, cY*1.3, 10, 10)
  192.         positions[20] = display.newRect(cX*1.7, cY*1.3, 10, 10)
  193.         positions[21] = display.newRect(cX*.5, cY*1.6, 10, 10)
  194.         positions[22] = display.newRect(cX*.8, cY*1.6, 10, 10)
  195.         positions[23] = display.newRect(cX*1.1, cY*1.6, 10, 10)
  196.         positions[24] = display.newRect(cX*1.4, cY*1.6, 10, 10)
  197.         positions[25] = display.newRect(cX*1.7, cY*1.6, 10, 10)
  198.  
  199.  
  200.  
  201.       -- Tower Menu --
  202.       local tmBox = display.newRect(display.contentCenterX/8, display.contentCenterY, 70, display.contentCenterY*2)
  203.       local tower1 = display.newRect(display.contentCenterX/8, display.contentCenterX*.3, 30, 30)
  204.       tower1.towerNumber = 1
  205.       tower1:setFillColor(1,0,0)
  206.  
  207.       sceneGroup:insert(tmBox)
  208.       sceneGroup:insert(tower1)
  209.  
  210.       local function showPositions()
  211.  
  212.         for k,v in pairs(positions) do
  213.           v:setFillColor(1,0,0)
  214.         end
  215.  
  216.       end
  217.  
  218.       tower1:addEventListener("tap", showPositions)
  219.  
  220.       local function moveTower(pos)
  221.  
  222.         local newPosNum = tonumber(pos)
  223.  
  224.         for k,v in pairs(positions) do
  225.           v:setFillColor(1,1,1)
  226.         end
  227.  
  228.         if positions[newPosNum].isOccupied == false or positions[newPosNum].isOccupied == nil then
  229.           positions[newPosNum].isOccupied = true
  230.           local towerOneCopy = display.newRect(positions[tonumber(pos)].x, positions[tonumber(pos)].y, 30, 30)
  231.           towerOneCopy:setFillColor(1,0,0)
  232.           table.insert(activeTowers, towerOneCopy)
  233.         end
  234.  
  235.         for k,v in pairs(activeTowers) do
  236.           sceneGroup:insert(v)
  237.         end
  238.  
  239.  
  240.       end
  241.  
  242.       local function getPosTap(event)
  243.  
  244.         local pos = event.target.posNum
  245.  
  246.         if positions[tonumber(pos)].isOccupied == false or positions[tonumber(pos)].isOccupied == nil then
  247.           moveTower(pos)
  248.         else
  249.           return
  250.         end
  251.  
  252.       end
  253.  
  254.       for i = 1, #positions do
  255.         positions[i]:addEventListener("tap", getPosTap)
  256.         positions[i].posNum = i
  257.         sceneGroup:insert(positions[i])
  258.       end
  259.  
  260.  
  261.  
  262.       backButton = display.newRoundedRect( display.contentCenterX*1.8, display.contentHeight*0.1, 50, 50, 20)
  263.       backButton:setFillColor(1,0,0)
  264.       sceneGroup:insert(backButton)
  265.  
  266.       backButton:addEventListener("tap", gotoScene1)
  267.  
  268.    end
  269. end
  270.  
  271. -- "scene:hide()"
  272. function scene:hide( event )
  273.  
  274.    local sceneGroup = self.view
  275.    local phase = event.phase
  276.  
  277.    if ( phase == "will" ) then
  278.       -- Called when the scene is on screen (but is about to go off screen).
  279.       -- Insert code here to "pause" the scene.
  280.       -- Example: stop timers, stop animation, stop audio, etc.
  281.    elseif ( phase == "did" ) then
  282.       -- Called immediately after scene goes off screen.
  283.    end
  284. end
  285.  
  286. -- "scene:destroy()"
  287. function scene:destroy( event )
  288.  
  289.    local sceneGroup = self.view
  290.  
  291.    -- Called prior to the removal of scene's view ("sceneGroup").
  292.    -- Insert code here to clean up the scene.
  293.    -- Example: remove display objects, save state, etc.
  294.  
  295.  
  296. end
  297.  
  298. ---------------------------------------------------------------------------------
  299.  
  300. -- Listener setup
  301. scene:addEventListener( "create", scene )
  302. scene:addEventListener( "show", scene )
  303. scene:addEventListener( "hide", scene )
  304. scene:addEventListener( "destroy", scene )
  305.  
  306. ---------------------------------------------------------------------------------
  307.  
  308. return scene
RAW Paste Data
Ledger Nano X - The secure hardware wallet
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
Top