 @wallRight = null
 @ball = null
 @boxes = null
+
+score = 0
+lives = 3
 
 GameplayState =
   preload: () ->


  collideBlock: (ball, block) ->
    block.kill()

    if ball.body.touching.up or ball.body.touching.down
      ball.body.velocity.y *= -2

    game.physics.arcade.overlap(@ball, @wallRight, @collideX)
    game.physics.arcade.collide(@ball, @boxes, @collideBlock)

    if @ball.body.position.y > 1100
      lives--
      @ball.body.position.y = 880
      @ball.body.position.x = 320
      @ball.body.velocity.y *= -1

      if lives is 0
        @ball.body.velocity.y *= 0
        @ball.body.velocity.x *= 0

  render: () ->
    game.debug.body(@square)
    game.debug.body(@wallTop)
    game.debug.body(@wallLeft)
    game.debug.body(@wallRight)
    game.debug.body(@ball)
    game.debug.text(score, 80, 100)
    game.debug.text(lives, 520, 100)

    @boxes.forEachAlive((box) -> game.debug.body(box))

