Skip to content

Commit

Permalink
player, enemy and laser collision detection
Browse files Browse the repository at this point in the history
  • Loading branch information
willmcneilly committed Mar 1, 2014
1 parent 87438bc commit 1555677
Showing 1 changed file with 9 additions and 0 deletions.
9 changes: 9 additions & 0 deletions scripts/coffee/game.coffee
Expand Up @@ -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')
Expand Down Expand Up @@ -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()

0 comments on commit 1555677

Please sign in to comment.