class Rocket
{
    static WIDTH = 100;
    static HEIGHT = 120;

    constructor( engine , map , x , y )
    {
        this.engine = engine;
        this.map = map;
        this.x = x;
        this.y = y;
        this.quad = new Sparrow.Quad( this.engine , this.x-Rocket.WIDTH/2 , this.y-Rocket.HEIGHT/2 , Rocket.WIDTH , Rocket.HEIGHT , { file: "img/rocket.png" , filter: this.engine.gl.NEAREST } );
        
        this.M_translation = new mat4();
        this.dy = 0;
        this.b_launched = false;

        this.sound = new Audio( "sounds/rocket.ogg" );
        this.sound.volume = 1;
    }

    delete()
    {
        this.quad.delete();
    }

    reset()
    {
        this.dy = 0;
        this.y = 0;
        this.b_launched = false;
    }

    launch()
    {
        this.b_launched = true;
        this.sound.play();
    }

    update( dt )
    {
        if ( this.b_launched )
        {
            this.dy -= 0.01;
            this.y += this.dy;
            this.M_translation.data[12] = this.x;
            this.M_translation.data[13] = this.y;

            if ( this.y < -1000 )
            {
                this.map.victory();
            }
        }
    }

    draw()
    {
        if ( this.b_launched )
        {
            this.engine.defaultShader2D.setUniformModel( this.M_translation );
            this.quad.draw();
        }
    }
}