Advertisement
Guest User

Untitled

a guest
Apr 20th, 2014
73
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 10.92 KB | None | 0 0
  1. highScores = {
  2. 1,
  3. 2,
  4. 3,
  5. 4,
  6. 5,
  7. 6,
  8. 7
  9. }
  10.  
  11. highScores[1] = score
  12.  
  13. local composer = require( "composer" )
  14. local scene = composer.newScene()
  15. local myData = require( "myData" )
  16. local physics = require("physics")
  17. physics.setDrawMode( "hybrid" )
  18. -- forward references
  19. local w = display.actualContentWidth
  20. local h = display.actualContentHeight
  21. local dropCount = 0
  22. local spawnShit = 0
  23. local allowDrop = 1
  24. local spawnTime = 17
  25. local countdownTimer
  26. local score
  27. local gX = 0
  28. local gY = 0
  29. score = 0
  30. local countDownNumber = 10
  31. local gameOver
  32.  
  33. local scoreT = display.newText( {text="Score: "..score, font=system.nativeSystemFont, fontSize=14,} )
  34. scoreT.x = w * 0.5
  35. scoreT.y = h * 0.1
  36.  
  37. local countDownText = display.newText( {text="", font=system.nativeSystemFont, fontSize=14} )
  38. countDownText.x = w * 0.5
  39. countDownText.y = h * 0.2
  40.  
  41. local drop01 = display.newImage("drop01.png")
  42. drop01.x = -100
  43.  
  44. local drop02 = display.newImage("drop02.png")
  45. drop02.x = -100
  46.  
  47. local drop03 = display.newImage("drop03.png")
  48. drop03.x = -100
  49.  
  50. local drop04 = display.newImage("drop04.png")
  51. drop04.x = -100
  52.  
  53. local timerSpawn
  54. local timer2
  55.  
  56. -- Display objects
  57. local background = display.newImage( "bluebg.png" )
  58. background.x = w*0.5
  59. background.y = h*0.5
  60. background.width = w
  61. background.height = h
  62.  
  63. local bckBtn = display.newText({text="<--BACK", font=system.nativeSystemFont, fontSize=14})
  64. bckBtn.x = 50
  65. bckBtn.y = 20
  66.  
  67.  
  68. local egon = display.newImage( "Egon.png" )
  69. egon.x = w*0.5
  70. egon.y = h*0.85
  71. egon.width = 100
  72. egon.height = 97
  73.  
  74. local destroyAll = display.newRect( 0, h, w, 10 )
  75. destroyAll.width = w*2
  76. destroyAll.alpha = 0
  77.  
  78. local overlayBg = display.newRect( -500, -500, w, h )
  79. overlayBg:setFillColor( 0, 0, 0 )
  80. overlayBg.alpha = 0.4
  81.  
  82. --functions
  83.  
  84. function gameOver ()
  85. if timerSpawn == nil then
  86. else
  87. timer.cancel(timerSpawn)
  88. timerSpawn = nil
  89. spawnShit = 0
  90. end
  91. if countdownTimer == nil then
  92. else
  93. timer.cancel(countdownTimer)
  94. countdownTimer = nil
  95. end
  96. highScores[1] = score
  97. transition.to( overlayBg, {x=w/2, y=h/2, time=500 } )
  98. end
  99.  
  100. function goBack (event)
  101. if "began" == event.phase then
  102. gameOver()
  103. if timerSpawn == nil then
  104. else
  105. timer.cancel(timerSpawn)
  106. end
  107. if countdownTimer == nil then
  108. else
  109. timer.cancel(countdownTimer)
  110. end
  111.  
  112. elseif event.phase == "ended" then
  113.  
  114. timer2 = timer.performWithDelay(1000, function()
  115. composer.gotoScene("select", "fade", 500)
  116. end)
  117.  
  118. if overlayBg == nil then
  119. else
  120. overlayBg:removeSelf( )
  121. end
  122.  
  123. return true
  124. end
  125.  
  126. return true
  127. end
  128.  
  129. function moveEgon (event)
  130. if "moved" == event.phase then
  131. egon.x = event.x
  132. end
  133.  
  134. end
  135.  
  136. ------------------------------------------------vvv---------------------------------------------------
  137. ------------------------------------------------vvv---------------------------------------------------
  138. ------------------------------------------------vvv---------------------------------------------------
  139. function spawnObjects (event)
  140.  
  141. dropCount = math.random(1,4)
  142.  
  143. --if stopTimer == 1 then
  144. -- timerSpawn = nil
  145. --spawnShit = nil
  146. --end
  147. if spawnShit == 1 then
  148. print( 'spawnShit' )
  149. if dropCount == 1 then
  150. -- Drop01 function and settings
  151. drop01 = display.newImage( "drop01.png" )
  152. drop01.x = math.random(10, 470)
  153. drop01.y = -40
  154. drop01.width = 50
  155. drop01.height = 50
  156. drop01.myName = "01"
  157. physics.addBody( drop01, "dynamic", {density=0.9, friction=0.1, bounce=0.8 } )
  158.  
  159. elseif dropCount == 2 then
  160. --Do shit for drop02
  161. drop02 = display.newImage( "drop02.png" )
  162. drop02.x = math.random(10, 470)
  163. drop02.y = -40
  164. drop02.width = 50
  165. drop02.height = 50
  166. drop02.myName = "02"
  167. physics.addBody( drop02, "dynamic", {density=0.9, friction=0.1, bounce=0.8 } )
  168.  
  169. elseif dropCount == 3 then
  170. drop03 = display.newImage( "drop03.png" )
  171. drop03.x = math.random(10, 470)
  172. drop03.y = -40
  173. drop03.width = 50
  174. drop03.height = 50
  175. drop03.myName = "03"
  176. physics.addBody( drop03, "dynamic", {density=0.9, friction=0.1, bounce=0.8 } )
  177.  
  178. elseif dropCount == 4 then
  179. drop04 = display.newImage( "drop04.png" )
  180. drop04.x = math.random(10, 470)
  181. drop04.y = -40
  182. drop04.width = 50
  183. drop04.height = 50
  184. drop04.myName = "04"
  185. physics.addBody( drop04, "dynamic", {density=0.9, friction=0.1, bounce=0.8 } )
  186. end
  187. end
  188.  
  189. return true
  190. end
  191.  
  192. ---------------------------------------------------------------------------------------------------
  193. ---------------------------------------------------------------------------------------------------
  194. ---------------------------------------------------------------------------------------------------
  195.  
  196. function onCollision (event)
  197.  
  198. if "began" == event.phase then
  199. --v--do shit when touching surface
  200.  
  201. if event.other.myName == "01" then
  202. -- Do shit for drop01 --
  203. -- Change score, powersups etc
  204. event.other:removeSelf( )
  205. score = score+1
  206. countDownNumber = countDownNumber + 10
  207. scoreT.text = "Score: "..score
  208. end
  209.  
  210. if event.other.myName == "02" then
  211. -- Do shit for drop02 --
  212. -- Change score, powersups etc
  213. event.other:removeSelf( )
  214. score = score+1
  215. scoreT.text = "Score: "..score
  216. end
  217.  
  218. if event.other.myName == "03" then
  219. -- Do shit for drop03 --
  220. -- Change score, powersups etc
  221. event.other:removeSelf( )
  222. score = score-1
  223. scoreT.text = "Score: "..score
  224. end
  225.  
  226. if event.other.myName == "04" then
  227. -- Do shit for drop04 --
  228. -- Change score, powersups etc
  229. event.other:removeSelf( )
  230. score = score-1
  231. scoreT.text = "Score: "..score
  232. end
  233.  
  234. elseif "ended" == event.phase then
  235. -- Do shit when leaving surfaces
  236. end
  237.  
  238. return true
  239.  
  240. end
  241.  
  242. ------------------------------------------------vvv---------------------------------------------------
  243. ------------------------------------------------vvv---------------------------------------------------
  244. ------------------------------------------------vvv---------------------------------------------------
  245. function showCountDown (event)
  246. -- Condition to show and hide countdown
  247. if countDownNumber <= 1 or score == -1 then
  248. spawnShit = 0
  249. countDownNumber = 0
  250. timer.cancel(timerSpawn)
  251. timer.cancel(countdownTimer)
  252. countdownTimer = nil
  253. highScores[1] = score
  254. print( 'NO MORE SPAAAAAAAAAAAAAAAWWNS' )
  255. end
  256.  
  257. if countDownNumber >= 1 then
  258. countDownNumber = countDownNumber -1
  259. countDownText.text = countDownNumber
  260. spawnShit = 1
  261. end
  262.  
  263. return true
  264. end
  265.  
  266. ---------------------------------------------------------------------------------------------------
  267. ---------------------------------------------------------------------------------------------------
  268. ---------------------------------------------------------------------------------------------------
  269.  
  270.  
  271. function destroy (event)
  272.  
  273. if "began" == event.phase then
  274. event.other:removeSelf( )
  275. else if "ended" == event.phase then
  276. end
  277. return true
  278. end
  279. end
  280.  
  281.  
  282. --function scene:create( event )
  283. function scene:create( event )
  284. local sceneGroup = self.view
  285.  
  286. -- Initialize the scene here.
  287. -- Example: add display objects to "sceneGroup", add touch listeners, etc
  288.  
  289. --Listeners
  290.  
  291. background:addEventListener( "touch", moveEgon )
  292. bckBtn:addEventListener( "touch", goBack )
  293. egon:addEventListener( "collision", onCollision )
  294. destroyAll:addEventListener( "collision", destroy )
  295.  
  296. --SceneGroup insert
  297. sceneGroup:insert( background )
  298. sceneGroup:insert(egon)
  299. sceneGroup:insert(bckBtn)
  300. sceneGroup:insert(drop01)
  301. sceneGroup:insert(drop02)
  302. sceneGroup:insert(drop03)
  303. sceneGroup:insert(drop04)
  304. sceneGroup:insert(scoreT)
  305. sceneGroup:insert(countDownText)
  306. sceneGroup:insert(overlayBg)
  307. sceneGroup:insert(destroyAll)
  308.  
  309. end
  310.  
  311.  
  312. -- "scene:show()"
  313. function scene:show( event )
  314. local sceneGroup = self.view
  315. local phase = event.phase
  316.  
  317. if ( phase == "will" ) then
  318. -- Called when the scene is still off screen (but is about to come on screen).
  319.  
  320. elseif ( phase == "did" ) then
  321. -- Called when the scene is now on screen.
  322. -- Insert code here to make the scene come alive.
  323. -- Example: start timers, begin animation, play audio, etc.
  324. physics.start( )
  325. gX = 0
  326. gY = 10
  327. physics.setGravity( gX, gY )
  328. timercount = 10
  329. spawnShit = 1
  330. score = 0
  331. scoreT.text = "Score: "..score
  332.  
  333. -- ADD physic bodies ----
  334. physics.addBody( egon, "static", {density=0.1, friction=0.1, bounce=0.8 } )
  335. physics.addBody( destroyAll, "static", {density=0.1, friction=0.1, bounce=0.1 } )
  336. countDownNumber = 10
  337. if countdownTimer == nil then
  338. countdownTimer = timer.performWithDelay( 1000, showCountDown, 0 )
  339. else
  340. end
  341.  
  342. ----------- Timers ------------
  343. if timerSpawn == nil then
  344. timerSpawn = timer.performWithDelay(500, spawnObjects, 0 )
  345. else
  346. end
  347.  
  348. end
  349. end
  350.  
  351.  
  352. -- "scene:hide()"
  353. function scene:hide( event )
  354.  
  355. local sceneGroup = self.view
  356. local phase = event.phase
  357.  
  358. if ( phase == "will" ) then
  359. -- Called when the scene is on screen (but is about to go off screen).
  360. -- Insert code here to "pause" the scene.
  361. -- Example: stop timers, stop animation, stop audio,
  362. --timer.pause( timerSpawn )
  363. physics.stop()
  364. spawnShit = nil
  365. score = nil
  366. timerSpawn = nil
  367. countdownTimer = nil
  368. overlayBg = nil
  369.  
  370. --timer.cancel(timerSpawn)
  371.  
  372. physics.removeBody( egon )
  373.  
  374. elseif ( phase == "did" ) then
  375. -- Called immediately after scene goes off screen.
  376. end
  377. end
  378.  
  379.  
  380. -- "scene:destroy()"
  381. function scene:destroy( event )
  382. local sceneGroup = self.view
  383.  
  384. -- Called prior to the removal of scene's view ("sceneGroup").
  385. -- Insert code here to clean up the scene.
  386. -- Example: remove display objects, save state, etc.
  387. bckBtn:removeEventListener("touch", goBack )
  388. egon:removeEventListener("touch", moveEgon )
  389. end
  390.  
  391.  
  392.  
  393. -- -------------------------------------------------------------------------------
  394.  
  395. -- Listener setup
  396. scene:addEventListener( "create", scene )
  397. scene:addEventListener( "show", scene )
  398. scene:addEventListener( "hide", scene )
  399. scene:addEventListener( "destroy", scene )
  400.  
  401. -- -------------------------------------------------------------------------------
  402.  
  403. return scene
  404.  
  405. score01.text = highScore[1]
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement