1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495 |
- #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 );
- }
|