 
 class Cannonball extends Projectile
 
-  constructor: (@x, @y, @game)->
+  constructor: (@x, y, @game)->
     @image = @game.assets.cannonball
     super @game
     @width   = 25
     @height  = @width
+    @y       = y + 2*@height
     @speed   = 20
     @strenth = 1
 

    window.requestAnimationFrame => @frame()
    @assets.toggleBgMusicPlayback()

  renderBackground: ->
    @ctx.clearRect 0, 0, @width, @height

  updateExplosions: ->
    for explosion of @explosions
      @explosions[explosion].update()

  renderExplosions: ->
    for explosion of @explosions
      @explosions[explosion].render()

  updateProjectiles: ->
    for projectile of @projectiles
      @projectiles[projectile].update()

  renderProjectiles: ->
    for projectile of @projectiles
      @projectiles[projectile].render()

  updateEnemies: ->
    for enemy of @enemies
      @enemies[enemy].update()

  renderEnemies: ->
    for enemy of @enemies
      @enemies[enemy].render()

  handleCollisions: ->
    for projectile of @projectiles


  constructor: (@game)->
    super
    @y =  @height+(Math.random()*200)
    @x =  -@width
    @move @x, @y
    @isRight = true
    @sinIndex = Math.random()*10

  update: ->
    @y = @y + 10*Math.sin(@sinIndex / 5)
    @sinIndex += 1
    if @isRight
      @move(@x + @speed)
    else
      @move(@x - @speed)
    if @x < 0
      @isRight = true
      @image = @game.assets.enemyShip
    if @x > @game.width - @width
      @isRight = false
      @image = @game.assets.enemyShipLeft


  move: (x)->
    super x
