Util   = require 'cgame/Util'
Entity = require 'cgame/Entity'

# Baller-ass spinning box
module.exports = class Box extends Entity

  constructor: ->
    super
    @color         = Util.randomInt 0, 360
    @size          = Util.randomInt 15, 100
    @opacity       = Util.randomFloat 0.3, 1.0
    @rotation      = Util.randomFloat 0, 2*Math.PI
    @rotationSpeed = Util.randomFloat -Math.PI, Math.PI
    @velocity      = x: 0, y: 0

  render: (ctx) ->
    ctx.save()
    ctx.translate @x, @y
    ctx.rotate @rotation
    ctx.globalAlpha = @opacity
    ctx.fillStyle = "hsl(#{@color}, 70%, 50%)"
    ctx.fillRect -@size/2, -@size/2, @size, @size
    ctx.restore()

  update: (dt) ->
    @rotation = @rotation + (@rotationSpeed * dt/1000) % (Math.PI*2)
    @x += @velocity.x * dt/1000
    @y += @velocity.y * dt/1000
