Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

player, enemy and laser collision detection

  • Loading branch information...
commit 155567760691e6e0072fa3089fc4a5256d75a800 1 parent 87438bc
@willmcneilly authored
Showing with 9 additions and 0 deletions.
  1. +9 −0 scripts/coffee/game.coffee
View
9 scripts/coffee/game.coffee
@@ -40,6 +40,8 @@ module.exports = class Game
@fire()
@spawnEnemy()
+ @game.physics.overlap(@player, @enemies, @playerHit, null, this)
+ @game.physics.overlap(@lasers, @enemies, @enemyHit, null, this)
createPlayer: ->
@player = @game.add.sprite(0, 0, 'player')
@@ -83,3 +85,10 @@ module.exports = class Game
enemy = @enemies.getFirstExists(false)
enemy.reset(@game.rnd.realInRange(enemy.width, @game.world.width - enemy.width), -enemy.width)
enemy.body.velocity.y =+ 300
+
+ playerHit: (player, enemy) ->
+ enemy.kill()
+
+ enemyHit: (laser, enemy) ->
+ laser.kill()
+ enemy.kill()
Please sign in to comment.
Something went wrong with that request. Please try again.