#include "Geschoss.h" #include "Spiel.h" Geschoss::Geschoss( int id, float speed, GeschossTyp typ, Richtung r, int x, int y, Spieler *besitzer ) : GameObject( GESCHOSS, x, y, 15, 15 ) { setX( getX() - 15.f / 2 ); setY( getY() - 15.f / 2 ); this->speed = speed; this->richtung = r; this->besitzer = besitzer; tunnelBenutzt = 0; umgelenkt = 0; geschosseGetroffen = 0; schalter = 0; intersectWithOwner = 1; this->id = id; setTyp( typ ); } Geschoss::~Geschoss() { if( besitzer ) besitzer->release(); } void Geschoss::invertDirection() { richtung = invert( richtung ); } void Geschoss::addUmlenkung( Spiel *zSpiel ) { zSpiel->setGeschossZuletztUmgelenkt( dynamic_cast( getThis() ) ); umgelenkt++; } void Geschoss::addGeschossTreffer( Spiel *zSpiel ) { zSpiel->setGeschossZuletztGeschossGetroffen( dynamic_cast( getThis() ) ); geschosseGetroffen++; } void Geschoss::addTunnel( Spiel *zSpiel ) { zSpiel->setGeschossZuletztTunnelBenutzt( dynamic_cast( getThis() ) ); schalter++; } void Geschoss::addSchalter() { id++; } void Geschoss::setSpeed( float speed ) { this->speed = speed; } void Geschoss::setBesitzer( Spieler *besitzer ) { if( this->besitzer ) this->besitzer->release(); this->besitzer = besitzer; } void Geschoss::setTyp( GeschossTyp typ ) { this->typ = typ; if( typ == GESCHOSS_PFEIL ) { if( richtung == OBEN || richtung == UNTEN ) { setX( getX() + getWidth() / 2 - 7.f / 2 ); setY( getY() + getHeight() / 2 - 15 ); setWidth( 7 ); setHeight( 30 ); } else { setX( getX() + getWidth() / 2 - 15 ); setY( getY() + getHeight() / 2 - 7.f / 2 ); setWidth( 30 ); setHeight( 7 ); } } else if( typ == GESCHOSS_FEUERBALL ) { setX( getX() + getWidth() / 2 - 10 ); setY( getY() + getHeight() / 2 - 10 ); setWidth( 20 ); setHeight( 20 ); } else { setX( getX() + getWidth() / 2 - 15.f / 2 ); setY( getY() + getHeight() / 2 - 15.f / 2 ); setWidth( 15 ); setHeight( 15 ); } } void Geschoss::setRichtung( Richtung r ) { richtung = r; } void Geschoss::tick( double zeit ) { switch( richtung ) { case OBEN: y -= (float)zeit * speed; break; case UNTEN: y += (float)zeit * speed; break; case RECHTS: x += (float)zeit * speed; break; case LINKS: x -= (float)zeit * speed; break; default: break; } } bool Geschoss::intersectsWith( GameObject *zObj ) { if( zObj == besitzer && intersectWithOwner ) { intersectWithOwner &= GameObject::intersectsWith( zObj ); return 0; } return GameObject::intersectsWith( zObj ); } int Geschoss::getId() const { return id; } GeschossTyp Geschoss::getTyp() const { return typ; } Spieler *Geschoss::zBesitzer() const { return besitzer; } Spieler *Geschoss::getBesitzer() const { return besitzer ? dynamic_cast( besitzer->getThis() ) : 0; } Richtung Geschoss::getRichtung() const { return richtung; } FeuerballTreffer::FeuerballTreffer( int id, int x, int y, Spieler *besitzer, int maxZeit ) : GameObject( FEUERBALL_TREFFER, x - 75, y - 75, 150, 150 ) { this->id = id; this->besitzer = besitzer; this->timeLeft = (float)maxZeit; count = 0; } FeuerballTreffer::~FeuerballTreffer() { besitzer->release(); } void FeuerballTreffer::tick( double zeit ) { timeLeft -= (float)zeit; count++; } bool FeuerballTreffer::isOver() const { return timeLeft <= 0; } bool FeuerballTreffer::makeDamage() const { return count % 2; } Spieler *FeuerballTreffer::zVerursacher() const { return besitzer; }