#include "Laser.h" #include "../Karte/Karte.h" #include "../Spieler/Spieler.h" #include "../Define.h" // Inhalt der Laser Klasse aus Laser.h // Konstruktor Laser::Laser( int id, Vertex pos, Vertex speed, int sNum, double intensität, int tf ) : Object2D() { this->id = id; setPosition( pos ); setSpeed( speed ); this->sNum = sNum; this->intensität = intensität; this->startIntensität = intensität; this->tf = tf; setCollision( 0 ); save(); } // privat char Laser::getOutCode( Punkt& p, Bild &zrObj ) const { char ret = 0; if( p.x < 0 ) ret |= 1; else if( p.x >= zrObj.getDrawGr().x ) ret |= 2; if( p.y < 0 ) ret |= 4; else if( p.y >= zrObj.getDrawGr().y ) ret |= 8; return ret; } // nicht constant Rect2< float > Laser::getBoundingBox() const { Rect2< float > r = Rect2< float >(); r.topLeft.x = -abs( getSpeed().x ); r.topLeft.y = -abs( getSpeed().y ); r.bottomRight.x = abs( getSpeed().x ); r.bottomRight.y = abs( getSpeed().y ); r.topLeft = getWorldPos( r.topLeft ); r.bottomRight = getWorldPos( r.bottomRight ); return r; } bool Laser::tick( const WeltInfo &info, double tv ) { __super::tick( info, tv ); intensität -= tv * 2; return 1; } void Laser::render( Mat3< float > &kamMat, Bild &zRObj, const char *kamName ) { int fa = (int)( ( intensität / startIntensität ) * 255 ); int f = ( ( fa << 24 ) & 0xFF000000 ) | ( tf & 0xFFFFFF ); Mat3< float > mat = kamMat * getObjectMatrix(); Punkt a = (Punkt)( mat * Vertex( 0, 0 ) ); Punkt b = (Punkt)( mat * ( getSpeed() / getSpeed().getLength() * 10 ) ); zRObj.drawLinieBorderedAlpha( a, b, f, 0xFFFFFFFF ); } void Laser::save() { last.pos = getPosition(); last.speed = getSpeed(); last.intensity = intensität; } void Laser::load() { intensität = last.intensity; setPosition( last.pos ); setSpeed( last.speed ); } // constant int Laser::getId() const { return id; } int Laser::getSpieler() const { return sNum; } double Laser::getIntensität( Vertex targetSpeed ) const { return intensität * ( ( speed - targetSpeed ).getLength() / 200 ); } // Reference Counting Laser *Laser::getThis() { ref++; return this; } Laser *Laser::release() { ref--; if( !ref ) delete this; return 0; }