Advertisement
Rakoonic

Zombieeeeeees

Sep 24th, 2013
62
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 4.36 KB | None | 0 0
  1.  
  2. fullH = display.viewableContentHeight
  3.  
  4.  
  5.  
  6. system.activate( "multitouch" )
  7. local physics = require "physics"
  8. physics.start()
  9. physics.setGravity( 0, 0 )
  10. physics.setDrawMode( "hybrid" )
  11. --[[
  12. if system.getInfo("environment") == "simulator" then
  13.         local rcorona = require("rcorona")
  14.         rcorona.startServer(8181)
  15. end
  16.  --]]
  17.  
  18.  
  19. halfW = display.viewableContentWidth * 0.5
  20. halfH = display.viewableContentHeight * 0.5
  21. --local background = display.newImage( "Background Placeholder.png" )
  22. --background:setReferencePoint ( display.TopCenterReferencePoint )
  23. --background.x = halfW
  24. local stage = display.getCurrentStage()
  25. local zombies = display.newGroup()
  26.  
  27. for i = 1, fullH do
  28.     zombies:insert( display.newGroup() )
  29. end
  30.  
  31. zombieCollisionFilter = { categoryBits = 1, maskBits = 2 }
  32. zombieCollisionFilter3 = { categoryBits = 4, maskBits = 4 }
  33.  
  34.  
  35. -- Spawner
  36. local speedScalar = 5
  37. local sSpawn = function(event)
  38.   --      local sheetInfo = require("Zombie Placeholder")
  39.  --       local zombieSheet = graphics.newImageSheet( "Zombie Placeholder.png", sheetInfo:getSheet() )
  40. --        local sequenceData = { name = zombieWalk, start = 1, count = 8, time = 1500 }
  41. --        local s = display.newSprite( zombieSheet, sequenceData )
  42.         local s = display.newRect( 0, 0, 112, 187 )
  43.         s:setReferencePoint ( display.BottomCenterReferencePoint )
  44.         s.box = display.newRect( s.x, s.y, 50, 5 )
  45.         s.box:setReferencePoint ( display.BottomCenterReferencePoint )
  46.         s.box.isVisible = false
  47.         s.xScale = .07
  48.         s.yScale = .07
  49.         s.box:translate( halfW + math.random( -80, 80 ), halfH - 260 )
  50. --        physics.addBody( s, "dynamic", { density = 0, friction = 0, bounce = 0, --[[ filter = zombieCollisionFilter --]] }  )
  51.         physics.addBody( s.box, "dynamic", { density = 0, friction = 0, bounce = 0.0, filter = zombieCollisionFilter3} )
  52.         s.box.isFixedRotation = true
  53.         s.box:setLinearVelocity( 0 , 7 * speedScalar )
  54. --        s:play()
  55.         s.count = event.count
  56.         s.name = "zombie"
  57.         function s.box:resume ( event )
  58.                 timer.performWithDelay( 1000, function() s.box:setLinearVelocity( 0, 7 * speedScalar ) end )
  59.         end
  60.         function s:touch ( event )
  61.                 if event.phase == "ended" then
  62.                         timer.performWithDelay( 50, function() s.box:applyLinearImpulse( 0, -0.005, s.box.x, s.box.y ) end )
  63.                         timer.performWithDelay( 2000, function() s.box:setLinearVelocity( 0, 7 * speedScalar ) print ("stopping", s.box ) end )
  64.                 end
  65. --                return true
  66.         end
  67.         function s:enterFrame ( event )
  68.                 local object = s
  69. --              print (object, object.box, object.box.y)
  70.                 s.x = s.box.x
  71.                 s.y = s.box.y
  72.                 if object.box.y >= 1 and object.box.y <= fullH then
  73.                         zombies[ math.floor( (object.box.y) ) ]:insert( object )
  74. --                        print "sorted"
  75.                 end
  76.                 ScalePercent = ( s.y ) / 8 + 4
  77.                 s.xScale = 0.015 * ScalePercent
  78.                 s.yScale = 0.015 * ScalePercent
  79.                
  80.                 local col = 255 * math.min( s.y, fullH ) / fullH
  81.                 s:setFillColor( col )
  82.         end
  83.         lower = {}
  84.         upper = {}
  85.         function s.box:collision ( event )
  86.                 if event.target.y >= event.other.y then
  87.                         lower = event.target
  88.                         upper = event.other
  89.                 elseif event.target.y < event.other.y then
  90.                         lower = event.other
  91.                         upper = event.target
  92.                 end
  93.                 lowerXV, lowerYV = lower:getLinearVelocity()
  94.                 event.target:resume()
  95.                 event.other:resume()
  96.                 if event.phase == "began" then
  97.                         upper:setLinearVelocity( 0, lowerYV * math.random( 0.8, 1.1 ) )
  98.                         lower:setLinearVelocity( 0, lowerYV * 0.5 )
  99.                 end
  100.                 return true
  101.         end
  102.         s.box:addEventListener( "collision", s.box )
  103.         Runtime:addEventListener( "enterFrame", s )
  104.         s:addEventListener( "touch" )
  105.         return s
  106. end
  107.  
  108. function spawn ( event )
  109.         zombies:insert( 1, sSpawn( event ) )
  110. end
  111.  
  112. timer.performWithDelay( 150, spawn, 0 )
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement