Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

add and update score

  • Loading branch information...
commit b3f09c0c60904d20f6c6d69817196fb56c7eecfe 1 parent 1555677
@willmcneilly authored
Showing with 11 additions and 0 deletions.
  1. +11 −0 scripts/coffee/game.coffee
View
11 scripts/coffee/game.coffee
@@ -11,6 +11,7 @@ module.exports = class Game
@laserDelta = 0
@averageEnemySpawnTime = 1000
@enemyDelta = 0
+ @score = 0
preload: ->
@game.load.image('bg', '/assets/images/background.png')
@@ -26,6 +27,7 @@ module.exports = class Game
@createPlayer()
@createLasers()
@createEnemies()
+ @createScoreText()
@cursor = @game.input.keyboard.createCursorKeys()
update: ->
@@ -40,6 +42,8 @@ module.exports = class Game
@fire()
@spawnEnemy()
+ @updateScoreText()
+
@game.physics.overlap(@player, @enemies, @playerHit, null, this)
@game.physics.overlap(@lasers, @enemies, @enemyHit, null, this)
@@ -75,6 +79,9 @@ module.exports = class Game
@spawnOneEnemy()
@enemyDelta = @game.time.now + @enemySpawnTime()
+ createScoreText: ->
+ @scoreText = @game.add.text(0, 0, @score, { fontSize: '14px', fill: 'white'})
+
enemySpawnTime: ->
spawnTimeRange = @averageEnemySpawnTime * 0.2
upper = @averageEnemySpawnTime + spawnTimeRange
@@ -92,3 +99,7 @@ module.exports = class Game
enemyHit: (laser, enemy) ->
laser.kill()
enemy.kill()
+ @score += 1
+
+ updateScoreText: ->
+ @scoreText.content = @score
Please sign in to comment.
Something went wrong with that request. Please try again.