Advertisement
alestane

Simplified counting

Jan 6th, 2014
185
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 2.14 KB | None | 0 0
  1. function enemys.hit_rightWall_event(self, event, movement)  -- should be called when 'Enemy' hits the right wall
  2.     self.movement  = -self.movement
  3.     self.numberOfWallHits = self.numberOfWallHits + 1
  4.     checkNumHits(self)
  5. end
  6.  
  7. function enemys.hit_leftWall_event(self, event, movement)  -- should be called when 'Enemy' hits the left wall
  8.     self.movement = -self.movement
  9.     self.numberOfWallHits = self.numberOfWallHits + 1
  10.     checkNumHits(self)
  11. end
  12.  
  13. function enemys.collision(self, event, movement)
  14.     if event.phase == 'began' then
  15.         if event.other.name == "leftWall" then
  16.             scene:dispatchEvent{name="hit_leftWall_event"}
  17.         elseif event.other.name == "rightWall" then
  18.             local message = {name="hit_rightWall_event"}
  19.             scene:dispatchEvent{name="hit_rightWall_event"}
  20.         elseif event.other.name == "floorWall" then
  21.             loadAd()
  22.         elseif event.other.name == "bullet" then
  23.             --if(enableSound) then
  24.                 enemyShotChan = audio.play(shot,{channel=7 })
  25.             -- end
  26.  
  27.             event.target:removeSelf()
  28.             removeArrayItem(self)
  29.             timer.cancel(self.clock)
  30.  
  31.             scene:dispatchEvent{name="enemyDead"}
  32.             Runtime:removeEventListener( "enterFrame", self )
  33.             self.image:removeEventListener( "collision", self ) --DISPATCHING AND NULLING THE INVADER
  34.             scene:removeEventListener('hit_rightWall_event', self)
  35.             scene:removeEventListener('hit_leftWall_event', self)
  36.             scene:removeEventListener('hit_floorWall_event',self)
  37.         if self.image.y ~= drop then
  38.             local explosion2 = display.newSprite(budSprites2.sheets.explosion, budSprites2.sequences.explosion)
  39.             explosion2:scale(1.5, 1.5)
  40.             explosion2:play()
  41.             explosion2.x, explosion2.y = self.image.x, self.image.y
  42.  
  43.             timer.performWithDelay(260,
  44.                 function()
  45.                     if explosion2.removeSelf then
  46.                         explosion2:removeSelf()
  47.                     end
  48.                 end
  49.             )
  50.         end
  51.  
  52.         local currentScore = getScores( )
  53.  
  54.         -- EFM SCORES - Extract scores from enemies and add to current score
  55.         local myValue = self.myValue
  56.         --print("Bang you got: ", myValue, " points" )
  57.         currentScore = currentScore + myValue
  58.         setScores( currentScore )
  59.  
  60.         end
  61.     end
  62. end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement