Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

Changeset 8281


Ignore:
Timestamp:
Apr 21, 2011, 4:16:29 PM (13 years ago)
Author:
kmaurus
Message:

possibility to have several SpaceBoundaries instances in one level added

Location:
code/branches/spaceboundaries/src/orxonox/worldentities
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • code/branches/spaceboundaries/src/orxonox/worldentities/SpaceBoundaries.cc

    r8279 r8281  
    7474        }
    7575       
     76        this->pawnsIn_.clear();
     77       
    7678//        delete pColoredTextAreaOverlayElementFactory;
     79    }
     80   
     81    void SpaceBoundaries::checkWhoIsIn()
     82    {
     83        pawnsIn_.clear();
     84        for(ObjectListIterator<Pawn> current = ObjectList<Pawn>::begin(); current != ObjectList<Pawn>::end(); ++current)
     85        {
     86            Pawn* currentPawn = *current;
     87            float distance = this->computeDistance(currentPawn);
     88            if(distance <= this->maxDistance_)
     89            {
     90                pawnsIn_.push_back(currentPawn);
     91            }
     92        }
    7793    }
    7894   
     
    124140    void SpaceBoundaries::tick(float dt)
    125141    {
    126         for(ObjectListIterator<MobileEntity> item = ObjectList<MobileEntity>::begin(); item != ObjectList<MobileEntity>::end(); ++item)
    127         {
    128             MobileEntity* myMobileEntity = *item;
    129             Pawn* currentPawn = dynamic_cast<Pawn*>(myMobileEntity);
    130             if(currentPawn != NULL)
    131             {
    132                 float distance = this->computeDistance(currentPawn);
    133                 bool humanItem = this->isHumanPlayer(currentPawn);
    134                 COUT(0) << "Distanz:" << distance << std::endl; //!< message for debugging
    135                 if(distance > this->warnDistance_ && distance < this->maxDistance_) // Zeige Warnung an!
     142       
     143        COUT(0) << "Groesse der Liste: " << (int) pawnsIn_.size() << std::endl;
     144       
     145        //for(ObjectListIterator<Pawn> current = ObjectList<Pawn>::begin(); current != ObjectList<Pawn>::end(); ++current)
     146        for( std::list<Pawn*>::iterator current = pawnsIn_.begin(); current != pawnsIn_.end(); current++ )
     147        {
     148            Pawn* currentPawn = *current;
     149            float distance = this->computeDistance(currentPawn);
     150            bool humanItem = this->isHumanPlayer(currentPawn);
     151            COUT(0) << "Distanz:" << distance << std::endl; //!< message for debugging
     152            if(distance > this->warnDistance_ && distance < this->maxDistance_) // Zeige Warnung an!
     153            {
     154                COUT(0) << "You are leaving the area" << std::endl; //!< message for debugging
     155                if(humanItem)
    136156                {
    137                     COUT(0) << "You are leaving the area" << std::endl; //!< message for debugging
    138                     if(humanItem)
    139                     {
    140                         COUT(0) << "humanItem ist true" << std::endl;
    141                         this->displayWarning("Attention! You are leaving the area!");
    142                     } else {
    143                        
    144                     }
     157                    COUT(0) << "humanItem ist true" << std::endl;
     158                    this->displayWarning("Attention! You are leaving the area!");
     159                } else {
     160                   
    145161                }
    146                 if( (this->maxDistance_ - distance) < this->showDistance_)
     162            }
     163            if( (this->maxDistance_ - distance) < this->showDistance_)
     164            {
     165                // Zeige Grenze an!
     166                this->displayBoundaries(currentPawn);
     167            }
     168            if(distance > this->maxDistance_)
     169            {
     170                if(humanItem)
    147171                {
    148                     // Zeige Grenze an!
    149                     this->displayBoundaries(currentPawn);
     172                    COUT(0) << "Health should be decreasing!" << std::endl;
     173                    this->displayWarning("You are out of the area now!");
     174                    currentPawn->removeHealth( (distance - maxDistance_) * this->healthDecrease_);
     175                } else {
     176                   
    150177                }
    151                 if(distance > this->maxDistance_)
    152                 {
    153                     if(humanItem)
    154                     {
    155                         COUT(0) << "Health should be decreasing!" << std::endl;
    156                         this->displayWarning("You are out of the area now!");
    157                         currentPawn->removeHealth( (distance - maxDistance_) * this->healthDecrease_);
    158                     } else {
    159                        
    160                     }
    161                    
    162                     this->bounceBack(currentPawn);
    163                 }
    164             }
    165         }
     178               
     179                this->bounceBack(currentPawn);
     180            }
     181        }
     182        this->checkWhoIsIn();
    166183    }
    167184   
     
    242259           
    243260            item->lookAt( velocity + this->getPosition() );
    244 
     261           
    245262            item->setAcceleration(acceleration * dampingFactor);
    246263            item->setVelocity(velocity * dampingFactor);
  • code/branches/spaceboundaries/src/orxonox/worldentities/SpaceBoundaries.h

    r8244 r8281  
    2727 */
    2828 
    29  /* TODO: - Markiere SpaceBoundaries-Position mit einem schoenen Objekt
    30           - Reflexion an Grenze mit Quaternionen machen (--> vgl. Funktion bounceBack() )
     29 /* TODO:   - Mehrere SpaceBoundaries-Instanzen pro Level ermoeglichen
     30            - Pro Pawn ein Billboard verwenden
     31 */
     32 
     33 
     34 /* REALISIERUNGSIDEEN:
     35   
     36    Mehrere Instanzen:
     37        Im Konstruktor schauen, wer innerhalb der eigenen Grenzen ist und diese in eine Liste geben, die in jeder tick-Funktion
     38        durchgearbeitet wird.
     39        Moeglichkeit bereitstellen, ein Pawn durch ein Portal einer anderen Instanz von SpaceBoundaries zuzuweisen.
     40        Schauen, wie es zu handhaben ist, wenn ein neuer Spieler oder Bot nachtraeglich ins Spiel kommt.
     41 
    3142 */
    3243
     
    4455
    4556#include <string>
     57#include <list>
    4658
    4759/**
     
    6678            ~SpaceBoundaries();
    6779           
     80            void checkWhoIsIn();
     81           
    6882            void setMaxDistance(float r);
    6983            float getMaxDistance();
     
    8397
    8498        private:
     99            std::list<Pawn*> pawnsIn_;
     100       
    85101            float maxDistance_; //!< maximal zulaessige Entfernung von 'this->getPosition()'.
    86102            float warnDistance_; //!< Entfernung von 'this->getPosition()', ab der eine Warnung angezeigt wird, dass man bald das zulaessige Areal verlaesst.
Note: See TracChangeset for help on using the changeset viewer.