import Game from '@/core/game'
import Unit from '@/classes/unit'

import { angle, subtract, rotate } from '@/core/vector2'

const VIEW_ANGLE = 60 * Math.PI / 180

export default class CTUnit extends Unit {

    constructor (position) {
        super(position, 'green')

        this.weapon.firerate = 500
    }

    update (dt) {
        const playerVisible = Game.func('isPlayerVisible')(this)

        if (playerVisible) {
            const playerPosition = Game.func('getPlayerPosition')()
            const angleToPlayer = angle(subtract(playerPosition, this.position))

            this.direction = rotate([1, 0], angleToPlayer)
            this.firing = true
        } else {
            this.firing = false
        }

        this.move(dt)
    }

}
