Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

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

File:
1 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);
Note: See TracChangeset for help on using the changeset viewer.