#include "tank.hpp"
//constructeur
tank::tank() : sprite()
{
    _sightRadius = 0;
    _RadsY=_RadsX = 0;
    _a = 1;
    _cooldown = 0;
    _count = 0;
    _health = 2;
    _posBullet = point(0,0,2);
}

tank::tank(const shell& model) : sprite(model)
{
    _sightRadius = 20;
}

//mise à jour
void tank::update()
{
    _count+=1;
    if(_count%600 == 0)
    {
        _a = rand() % 10 +1;
    }
    else if( _a > 50)
        _a = 1;

    setRad(0,sin(_a)*(_RadsY += pi/64),sin(_a)*(_RadsX += pi/600));
}

//recevoir de dommage
void tank::damage()
{
    if (_health)
        _health--;
}

//detection de hero
bool tank::watch(const sprite& hero)const
{
    point tmp = _pos- hero.getPos();
    return tmp.magSQ() < _sightRadius*_sightRadius;
}

//tirer
bullet tank::shoot(const sprite& hero, const shell& model)const
{
    bullet tmp(model);
    tmp.setRad(_radX, _radY, _RadsX);
    tmp.setPos(_pos + _dir*1.5);
    tmp.setSpeed(-0.3);
    tmp.setExpire(50);
    return tmp;
}

//encore en vie?
bool tank::health()const
{
    return _health > 0;
}
