#include "Schuss.h"

// Inhalt der Schuss Klasse aus Schuss.h
// Konstruktor
Schuss::Schuss( Vec2< float > pos, Vec2< float > speed )
    : Object2D()
{
    setPosition( pos );
    setSpeed( speed );
	ref = 1;
}

// nicht constant
void Schuss::render( Mat3< float > &kamMat, Bild &zRObj )
{
	zRObj.drawLinie( (Punkt)(kamMat * position), (Punkt)( kamMat * (position - speed / 10) ), 0xFFFFFFFF );
}

// constant
Rect2< float > Schuss::getBoundingBox() const
{
    auto rect = Rect2< float >();
    rect.topLeft.x = min( position.x, ( position - this->speed / 10 ).x );
    rect.topLeft.y = min( position.y, ( position - this->speed / 10 ).y );
    rect.bottomRight.x = max( position.x, ( position - this->speed / 10 ).x );
    rect.bottomRight.y = max( position.y, ( position - this->speed / 10 ).y );
    return rect;
}

void Schuss::save( Datei *zD ) const
{
	zD->schreibe( (char*)&position.x, 4 );
	zD->schreibe( (char*)&position.y, 4 );
	zD->schreibe( (char*)&speed.x, 4 );
	zD->schreibe( (char*)&speed.y, 4 );
}