123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289 |
- #include "MiniGame.h"
- #include <Rahmen.h>
- #include <Datei.h>
- #include <InitDatei.h>
- #include <DateiSystem.h>
- #include <MausEreignis.h>
- // Inhalt der Minigame Klasse aus MiniGame.h
- // Konstruktor
- MiniGame::MiniGame( char *name )
- {
- xPos = 0;
- yPos = 0;
- xAbs = 0;
- yAbs = 0;
- zXPos = 0;
- zYPos = 0;
- xSpeed = 0;
- ySpeed = 0;
- this->name = new Text( name );
- bgBild = 0;
- mausAlpha = new AlphaFeld();
- mausAlpha->setSize( 248, 98 );
- mausAlpha->setFarbe( 0xFF00FF00 );
- mausAlpha->setStrength( 50 );
- rahmen = new LRahmen();
- rahmen->setSize( 250, 100 );
- rahmen->setFarbe( 0xFFFFFFFF );
- rahmen->setRamenBreite( 1 );
- sichtbar = 1;
- alpha = 0;
- mausIn = 0;
- ok = 1;
- rend = 0;
- ref = 1;
- Text *pfad = new Text( "data/Minigames/" );
- pfad->append( name );
- if( !DateiExistiert( pfad->getThis() ) )
- {
- ok = 0;
- pfad->release();
- return;
- }
- pfad->append( "/mg.ini" );
- if( !DateiExistiert( pfad->getThis() ) )
- {
- ok = 0;
- pfad->release();
- return;
- }
- InitDatei *mgIni = new InitDatei( pfad );
- if( !mgIni->laden() )
- {
- ok = 0;
- mgIni->release();
- return;
- }
- if( !mgIni->wertExistiert( "TitelBild" ) || !mgIni->wertExistiert( "TitelBildPfad" ) || !mgIni->wertExistiert( "DllPfad" ) )
- {
- ok = 0;
- mgIni->release();
- return;
- }
- Text *bPfad = new Text( "data/Minigames/" );
- bPfad->append( name );
- bPfad->append( "/" );
- bPfad->append( mgIni->zWert( "TitelBildPfad" )->getText() );
- if( !DateiExistiert( bPfad->getThis() ) )
- {
- ok = 0;
- bPfad->release();
- mgIni->release();
- return;
- }
- LTDBDatei *bDat = new LTDBDatei();
- bDat->setDatei( bPfad );
- bDat->leseDaten( 0 );
- bgBild = bDat->laden( 0, mgIni->getWert( "TitelBild" ) );
- bDat->release();
- mgIni->release();
- if( !bgBild )
- ok = 0;
- }
- // Destruktor
- MiniGame::~MiniGame()
- {
- name->release();
- if( bgBild )
- bgBild->release();
- mausAlpha->release();
- rahmen->release();
- }
- // nicht constant
- void MiniGame::setPosition( int x, int y )
- {
- if( !xPos && !yPos )
- {
- xPos = x;
- yPos = y;
- }
- zXPos = x;
- zYPos = y;
- xAbs = (int)( zXPos - xPos );
- yAbs = (int)( zYPos - yPos );
- }
- void MiniGame::setSichtbar( bool sichtbar )
- {
- this->sichtbar = sichtbar;
- }
- void MiniGame::doMausEreignis( MausEreignis &me )
- {
- if( !this->sichtbar )
- return;
- if( me.mx > xPos && me.mx < xPos + 250 && me.my > yPos && me.my < yPos + 100 )
- {
- if( !mausIn )
- {
- rend = 1;
- rahmen->setFarbe( 0xFF00FF00 );
- }
- mausIn = 1;
- }
- else
- {
- if( mausIn )
- {
- rend = 1;
- rahmen->setFarbe( 0xFFFFFFFF );
- }
- mausIn = 0;
- }
- me.verarbeitet |= mausIn;
- }
- bool MiniGame::tick( double z )
- {
- bool ret = rend;
- rend = 0;
- int val = (int)( z * 150 );
- if( sichtbar && alpha != 255 )
- {
- if( alpha + val > 255 )
- alpha = 255;
- else
- alpha += val;
- ret = 1;
- }
- if( !sichtbar && alpha )
- {
- if( alpha - val < 0 )
- alpha = 0;
- else
- alpha -= val;
- ret = 1;
- }
- if( xPos != zXPos || yPos != zYPos )
- {
- if( xPos != zXPos )
- {
- if( xAbs > 0 )
- {
- if( zXPos - xPos >= xAbs / 2 )
- xSpeed += xAbs * z;
- else
- {
- xSpeed -= xAbs * z;
- if( xSpeed < zXPos - xPos )
- xSpeed += xAbs * z;
- }
- }
- else
- {
- if( zXPos - xPos <= xAbs / 2 )
- xSpeed += xAbs * z;
- else
- {
- xSpeed -= xAbs * z;
- if( xSpeed > zXPos - xPos )
- xSpeed += xAbs * z;
- }
- }
- }
- if( yPos != zYPos )
- {
- if( yAbs > 0 )
- {
- if( zYPos - yPos >= yAbs / 2 )
- ySpeed += yAbs * z;
- else
- {
- ySpeed -= yAbs * z;
- if( ySpeed < zYPos - yPos )
- ySpeed += yAbs * z;
- }
- }
- else
- {
- if( zYPos - yPos <= yAbs / 2 )
- ySpeed += yAbs * z;
- else
- {
- ySpeed -= yAbs * z;
- if( ySpeed > zYPos - yPos )
- ySpeed += yAbs * z;
- }
- }
- }
- xPos += xSpeed * z;
- yPos += ySpeed * z;
- if( xAbs > 0 )
- {
- if( xPos >= zXPos )
- {
- xPos = zXPos;
- xSpeed = 0;
- }
- }
- else
- {
- if( xPos <= zXPos )
- {
- xPos = zXPos;
- xSpeed = 0;
- }
- }
- if( yAbs > 0 )
- {
- if( yPos >= zYPos )
- {
- yPos = zYPos;
- ySpeed = 0;
- }
- }
- else
- {
- if( yPos <= zYPos )
- {
- yPos = zYPos;
- ySpeed = 0;
- }
- }
- ret = 1;
- }
- return ret;
- }
- void MiniGame::render( Bild &zRObj )
- {
- zRObj.setAlpha( alpha );
- zRObj.drawBild( (int)( xPos ), (int)( yPos ), 250, 100, *bgBild );
- rahmen->setPosition( (int)xPos, (int)yPos );
- rahmen->render( zRObj );
- if( mausIn )
- {
- mausAlpha->setPosition( (int)xPos + 1, (int)yPos + 1 );
- mausAlpha->render( zRObj );
- }
- zRObj.releaseAlpha();
- }
- // constant
- Text *MiniGame::zName()
- {
- return name;
- }
- bool MiniGame::istOk() const
- {
- return ok;
- }
- // Reference Counting
- MiniGame *MiniGame::getThis()
- {
- ref++;
- return this;
- }
- MiniGame *MiniGame::release()
- {
- ref--;
- if( !ref )
- delete this;
- return 0;
- }
|