123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123 |
- #include "Asteroid.h"
- #include <Text.h>
- #include <Globals.h>
- #include <TastaturEreignis.h>
- #include "Schuss.h"
- #include <iostream>
- // Inhalt der Asteroid Klasse aus Asteroid.h
- // Konstruktor
- Asteroid::Asteroid( Model2DData *data, Bild *textur, Vec2< float > p, Vec2< float > s, float rS, float r, float gr, char num )
- {
- asteroid = new Model2D();
- asteroid->setStyle( Model2D::Style::Sichtbar | Model2D::Style::Textur );
- asteroid->setModel( data );
- asteroid->setTextur( textur );
- asteroid->setDrehung( r );
- asteroid->setSize( gr );
- mGröße = 0;
- pos = p;
- speed = s;
- rSpeed = rS;
- id = num;
- ref = 1;
- }
- // Destruktor
- Asteroid::~Asteroid()
- {
- asteroid->release();
- }
- // nicht constant
- bool Asteroid::tick( double zeit, int breite, int höhe )
- {
- Vertex minP = (Vertex)asteroid->zModel()->minP * asteroid->getSize() + asteroid->getPosition();
- Vertex maxP = (Vertex)asteroid->zModel()->maxP * asteroid->getSize() + asteroid->getPosition();
- if( maxP.x < 0 && speed.x < 0 )
- pos.x += breite + asteroid->zModel()->maxP.x * asteroid->getSize();
- if( maxP.y < 0 && speed.y < 0 )
- pos.y += höhe + asteroid->zModel()->maxP.y * asteroid->getSize();
- if( minP.x > breite && speed.x > 0 )
- pos.x -= breite + asteroid->zModel()->maxP.x * asteroid->getSize();
- if( minP.y > höhe && speed.y > 0 )
- pos.y -= höhe + asteroid->zModel()->maxP.y * asteroid->getSize();
- asteroid->setPosition( pos );
- if( mGröße )
- {
- float gr = mGröße > zeit ? (float)zeit : mGröße;
- if( asteroid->getSize() < gr )
- asteroid->setSize( 0 );
- else
- asteroid->addSize( -gr );
- mGröße -= gr;
- }
- if( rSpeed )
- asteroid->addDrehung( rSpeed * (float)zeit );
- if( speed.x || speed.y )
- {
- pos += speed * (float)zeit;
- asteroid->setPosition( pos );
- }
- return asteroid->tick( zeit );
- }
- void Asteroid::render( Bild &zRObj )
- {
- asteroid->render( zRObj );
- }
- bool Asteroid::istGetroffen( Schuss *zSchuss )
- {
- if( zSchuss->istInM2( *asteroid ) )
- {
- mGröße += 0.4f;
- return 1;
- }
- return 0;
- }
- // constant
- void Asteroid::save( Datei *zD ) const
- {
- zD->schreibe( (char*)&id, 1 );
- zD->schreibe( (char*)&pos.x, 4 );
- zD->schreibe( (char*)&pos.y, 4 );
- zD->schreibe( (char*)&speed.x, 4 );
- zD->schreibe( (char*)&speed.y, 4 );
- zD->schreibe( (char*)&rSpeed, 4 );
- float r = asteroid->getDrehung();
- zD->schreibe( (char*)&r, 4 );
- float gr = asteroid->getSize();
- zD->schreibe( (char*)&gr, 4 );
- }
- bool Asteroid::amLeben() const
- {
- return asteroid->getSize() != 0;
- }
- Model2D *Asteroid::zModel() const
- {
- return asteroid;
- }
- Punkt Asteroid::getPos() const
- {
- return (Punkt)pos;
- }
- // Refernece Counting
- Asteroid *Asteroid::getThis()
- {
- ref++;
- return this;
- }
- Asteroid *Asteroid::release()
- {
- ref--;
- if( !ref )
- delete this;
- return 0;
- }
|