Advertisement
Guest User

Untitled

a guest
Feb 13th, 2012
106
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 3.82 KB | None | 0 0
  1. ---------------------------------------------------------------------------------
  2. --
  3. -- testscreen1.lua
  4. --
  5. ---------------------------------------------------------------------------------
  6.  
  7. local storyboard = require( "storyboard" )
  8. local scene = storyboard.newScene()
  9.  
  10. ---------------------------------------------------------------------------------
  11. -- BEGINNING OF YOUR IMPLEMENTATION
  12. ---------------------------------------------------------------------------------
  13.  
  14. require("physics")
  15. physics.start()
  16. physics.pause()
  17. --physics.setDrawMode("hybrid")
  18.  
  19. gameOn = false
  20.  
  21.  
  22. local module = require "module"
  23.  
  24.  
  25. --local lines = module.lines
  26. --local line_number = module.line_number
  27. --local line_width = module.line_width
  28. --local prev_x, prev_y = module.prev_x, module.prev_y
  29. --local maxLines = 5
  30. --local maxDist = 400
  31. --local dist = module.dist
  32. --local mathSqrt = module.mathSqrt
  33.  
  34. local dist = 0
  35. local maxDist = 400
  36.  
  37.  
  38.  
  39.  
  40. local drawLine = module.drawLine
  41.  
  42. local gameWin = module.gameWin
  43.  
  44. local gameState = module.gameState
  45.  
  46.  
  47.  
  48.  
  49. -- Called when the scene's view does not exist:
  50. function scene:createScene( event )
  51.     local screenGroup = self.view
  52.    
  53.  
  54.  
  55.     local ball = module.spawnBall(30, 50)
  56.    
  57.     local goal = module.createGoal(100, 300)
  58.    
  59.  
  60.  
  61.     local wall = module.createWall( 0, 150, 450, 14, 1)
  62.    
  63.     local wall2 = module.createWall( 200, 300, 400, 10)
  64.    
  65.     local arrow = module.createArrow()
  66.  
  67.     screenGroup:insert( arrow )
  68.     screenGroup:insert( ball )
  69.     screenGroup:insert( goal )
  70.     screenGroup:insert( wall )
  71.     screenGroup:insert( wall2 )
  72.    
  73.     local changeGravity = module.changeGravity
  74.  
  75.    
  76.     screenGroup[3]:addEventListener("tap", gameState)
  77.     arrow:addEventListener("tap", changeGravity)
  78.  
  79.  
  80.    
  81.    
  82. end
  83.  
  84.  
  85. -- Called immediately after scene has moved onscreen:
  86. function scene:enterScene( event )
  87.  
  88.     local drawLineWrapper = function(e)
  89.         --if gameOn == false then
  90.             if e.phase == "began" then
  91.                 prev_x = e.x
  92.                 prev_y = e.y
  93.             elseif e.phase == "moved" then
  94.                 if dist < maxDist then
  95.                
  96.                     dist_x = e.x - prev_x
  97.                     dist_y = e.y - prev_y
  98.                    
  99.                     dist = dist + mathSqrt(dist_x*dist_x + dist_y*dist_y)
  100.                     print(dist)
  101.                    
  102.                     drawLine(prev_x, prev_y, dist_x, dist_y)
  103.                    
  104.                     prev_x = e.x
  105.                     prev_y = e.y
  106.                        
  107.                        
  108.                 end
  109.             elseif e.phase == "ended" then
  110.             end
  111.         --end
  112.    
  113.     end
  114.        
  115.     Runtime:addEventListener("touch", drawLineWrapper)
  116.  
  117.     Runtime:addEventListener("collision", gameWin)
  118.  
  119.    
  120.     -- remove previous scene's view
  121.     --storyboard.purgeScene( "storyboard.lastScene" )
  122.     --storyboard.lastScene =
  123.    
  124.  
  125.  
  126. end
  127.  
  128.  
  129. -- Called when scene is about to move offscreen:
  130. function scene:exitScene( event )
  131.  
  132.     lines = {}
  133.    
  134.    
  135.    
  136.     -- remove touch listener for image
  137.     -- image:removeEventListener( "touch", image )
  138.    
  139.  
  140. end
  141.  
  142.  
  143. -- Called prior to the removal of scene's "view" (display group)
  144. function scene:destroyScene( event )
  145.    
  146.     print( "((destroying scene 1's view))" )
  147. end
  148.  
  149. ---------------------------------------------------------------------------------
  150. -- END OF YOUR IMPLEMENTATION
  151. ---------------------------------------------------------------------------------
  152.  
  153. -- "createScene" event is dispatched if scene's view does not exist
  154. scene:addEventListener( "createScene", scene )
  155.  
  156. -- "enterScene" event is dispatched whenever scene transition has finished
  157. scene:addEventListener( "enterScene", scene )
  158.  
  159. -- "exitScene" event is dispatched before next scene's transition begins
  160. scene:addEventListener( "exitScene", scene )
  161.  
  162. -- "destroyScene" event is dispatched before view is unloaded, which can be
  163. -- automatically unloaded in low memory situations, or explicitly via a call to
  164. -- storyboard.purgeScene() or storyboard.removeScene().
  165. scene:addEventListener( "destroyScene", scene )
  166.  
  167. ---------------------------------------------------------------------------------
  168.  
  169. return scene
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement