Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

Ignore:
Timestamp:
Mar 29, 2010, 4:33:22 PM (15 years ago)
Author:
benedict
Message:

Invisibility works. Timer for invi works.

Location:
code/branches/ppspickups2/src/modules/pickup/items
Files:
3 edited

Legend:

Unmodified
Added
Removed
  • code/branches/ppspickups2/src/modules/pickup/items/CMakeLists.txt

    r6524 r6641  
    22  HealthPickup.cc
    33  MetaPickup.cc
     4  InvisiblePickup.cc
    45)
  • code/branches/ppspickups2/src/modules/pickup/items/InvisiblePickup.cc

    r6555 r6641  
     1/*
     2 *   ORXONOX - the hottest 3D action shooter ever to exist
     3 *                    > www.orxonox.net <
     4 *
     5 *
     6 *   License notice:
     7 *
     8 *   This program is free software; you can redistribute it and/or
     9 *   modify it under the terms of the GNU General Public License
     10 *   as published by the Free Software Foundation; either version 2
     11 *   of the License, or (at your option) any later version.
     12 *
     13 *   This program is distributed in the hope that it will be useful,
     14 *   but WITHOUT ANY WARRANTY; without even the implied warranty of
     15 *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
     16 *   GNU General Public License for more details.
     17 *
     18 *   You should have received a copy of the GNU General Public License
     19 *   along with this program; if not, write to the Free Software
     20 *   Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.
     21 *
     22 *   Author:
     23 *      Benedict Simlinger
     24 *   Co-authors:
     25 *      ...
     26 *
     27 */
     28
     29/**
     30    @file InvisiblePickup.cc
     31    @brief Implementation of the InvisiblePickup class.
     32*/
     33
     34#include "InvisiblePickup.h"
     35
     36#include "core/CoreIncludes.h"
     37#include "core/XMLPort.h"
     38#include "util/StringUtils.h"
     39
     40#include "worldentities/pawns/Pawn.h"
     41#include "pickup/PickupIdentifier.h"
     42
     43#include <sstream>
     44
     45namespace orxonox
     46{
     47   
     48   
     49    CreateFactory(InvisiblePickup);
     50   
     51    /**
     52    @brief
     53        Constructor. Registers the object and initializes the member variables.
     54    */
     55    InvisiblePickup::InvisiblePickup(BaseObject* creator) : Pickup(creator)
     56    {
     57        RegisterObject(InvisiblePickup);
     58        //! Defines who is allowed to pick up the pickup.
     59        this->initialize();
     60    }
     61   
     62    /**
     63    @brief
     64        Destructor.
     65    */
     66    InvisiblePickup::~InvisiblePickup()
     67    {       
     68    }
     69   
     70   
     71    void InvisiblePickup::initializeIdentifier(void)
     72    {
     73        std::stringstream stream;
     74        stream << this->getDuration();
     75        std::string type1 = "duration";
     76        std::string val1 = stream.str();
     77        this->pickupIdentifier_->addParameter(type1, val1);
     78    }
     79   
     80    /**
     81    @brief
     82    Initializes the member variables.
     83    */
     84    void InvisiblePickup::initialize(void)
     85    {
     86        this->duration_ = 0.0;
     87        this->addTarget(ClassIdentifier<Pawn>::getIdentifier());
     88    }
     89 
     90   
     91   
     92
     93    /**
     94    @brief
     95        Method for creating a HealthPickup object through XML.
     96    */
     97    void InvisiblePickup::XMLPort(Element& xmlelement, orxonox::XMLPort::Mode mode)
     98    {
     99        SUPER(InvisiblePickup, XMLPort, xmlelement, mode);   
     100        XMLPortParam(InvisiblePickup, "duration", setDuration, getDuration, xmlelement, mode);
     101         
     102         this->initializeIdentifier();
     103    }
     104   
     105   
     106    /**
     107    @brief
     108        Is called when the pickup has transited from used to unused or the other way around.
     109    */
     110    void InvisiblePickup::changedUsed(void)
     111    {
     112        SUPER(InvisiblePickup, changedUsed);
     113       
     114       
     115        //! If the pickup is not picked up nothing must be done.
     116        if(!this->isPickedUp())
     117            return;
     118        if (this->isUsed())
     119        {
     120            this->setInvisible(true);
     121            this->startPickupTimer(this->getDuration());
     122        }
     123        else
     124          this->setInvisible(false);
     125       
     126    }
     127   
     128    /**
     129    @brief
     130        Helper to transform the PickupCarrier to a Pawn, and throw an error message if the conversion fails.
     131    @return
     132        A pointer to the Pawn, or NULL if the conversion failed.
     133    */
     134    Pawn* InvisiblePickup::carrierToPawnHelper(void)
     135    {
     136        PickupCarrier* carrier = this->getCarrier();
     137        Pawn* pawn = dynamic_cast<Pawn*>(carrier);
     138       
     139        if(pawn == NULL)
     140        {
     141            COUT(1) << "Invalid PickupCarrier in InvisiblePickup." << std::endl;
     142        }
     143        return pawn;
     144    }
     145   
     146    /**
     147    @brief
     148        Creates a duplicate of the input OrxonoxClass.
     149    @param item
     150        A pointer to the Orxonox class.
     151    */
     152    void InvisiblePickup::clone(OrxonoxClass*& item)
     153    {
     154        if(item == NULL)
     155            item = new InvisiblePickup(this);
     156       
     157        SUPER(InvisiblePickup, clone, item);
     158       
     159        InvisiblePickup* pickup = dynamic_cast<InvisiblePickup*>(item);
     160        pickup->setDuration(this->getDuration());
     161        pickup->initializeIdentifier();
     162    }
     163   
     164   
     165   
     166   
     167     
     168    /**
     169    @brief
     170        Sets the invisibility.
     171    @param health
     172        The invisibility.
     173    */
     174    bool InvisiblePickup::setInvisible(bool invisibility)
     175    {
     176     
     177      Pawn* pawn = this->carrierToPawnHelper();
     178      pawn->setVisible(!invisibility);
     179      return 0;
     180    }
     181   
     182   
     183   
     184    /**
     185    @brief
     186    Sets the duration.
     187    @param duration
     188    The duration
     189    */
     190    void InvisiblePickup::setDuration(float duration)
     191    {
     192        if(duration >= 0.0f)
     193        {
     194            this->duration_ = duration;
     195        }
     196        else
     197        {
     198            COUT(1) << "Invalid duration in InvisiblePickup." << std::endl;
     199            this->duration_ = 0;
     200        }
     201    }
     202   
     203   
     204   
     205    void InvisiblePickup::PickupTimerCallBack(void){
     206        this->setInvisible(false);
     207    }
     208
     209}
  • code/branches/ppspickups2/src/modules/pickup/items/InvisiblePickup.h

    r6555 r6641  
     1/*
     2 *   ORXONOX - the hottest 3D action shooter ever to exist
     3 *                    > www.orxonox.net <
     4 *
     5 *
     6 *   License notice:
     7 *
     8 *   This program is free software; you can redistribute it and/or
     9 *   modify it under the terms of the GNU General Public License
     10 *   as published by the Free Software Foundation; either version 2
     11 *   of the License, or (at your option) any later version.
     12 *
     13 *   This program is distributed in the hope that it will be useful,
     14 *   but WITHOUT ANY WARRANTY; without even the implied warranty of
     15 *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
     16 *   GNU General Public License for more details.
     17 *
     18 *   You should have received a copy of the GNU General Public License
     19 *   along with this program; if not, write to the Free Software
     20 *   Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.
     21 *
     22 *   Author:
     23 *      Benedict Simlinger
     24 *   Co-authors:
     25 *      ...
     26 *
     27 */
     28
     29/**
     30    @file InvisiblePickup.h
     31    @brief Declaration of the InvisiblePickup class.
     32*/
     33
     34#ifndef _InvisiblePickup_H__
     35#define _InvisiblePickup_H__
     36
     37#include "pickup/PickupPrereqs.h"
     38
     39#include <string>
     40#include <worldentities/pawns/Pawn.h>
     41#include "worldentities/StaticEntity.h"
     42
     43#include "pickup/Pickup.h"
     44
     45namespace orxonox {
     46       
     47    /**
     48    @brief
     49        A pickup that makes the Pawn invisible.
     50        There are 2 parameters that can be chosen:
     51        1) The activation type: It can be chosen to be either 'immediate' or 'onUse'. The activation type essentially (as indicated by the name) defines when the Pawn will be invisible, either immediately after being picked up or only after the player uses it.
     52        2) The duration type: It can be chosen how long the Pawn will be invisibel.
     53    @author
     54        Benedict Simlinger
     55    */
     56    class _PickupExport InvisiblePickup : public Pickup
     57    {
     58        public:
     59       
     60            InvisiblePickup(BaseObject* creator); //!< Constructor.
     61            virtual ~InvisiblePickup(); //!< Destructor.
     62            virtual void XMLPort(Element& xmlelement, orxonox::XMLPort::Mode mode); //!< Method for creating a HealthPickup object through XML.
     63            virtual void changedUsed(void); //!< Is called when the pickup has transited from used to unused or the other way around.
     64            virtual void clone(OrxonoxClass*& item); //!< Creates a duplicate of the input OrxonoxClass.
     65           
     66             /**
     67            @brief Checks wether the Pawn is invisible.
     68            @return Returns if the Pawn is invisible.
     69            */
     70            inline bool getInvisibility(bool)
     71                { return this->invisible_; }
     72            inline float getDuration()
     73                {return this->duration_;}
     74 
     75        protected:
     76            bool setInvisible(bool invisibility); //!< Set the Pawn to be invisible or visible again.
     77            void setDuration(float duration);
     78            void initializeIdentifier(void);
     79       
     80        private:
     81           void initialize(void); //!< Initializes the member variables.
     82            Pawn* carrierToPawnHelper(void); //!< Helper to transform the PickupCarrier to a Pawn, and throw an error message if the conversion fails.
     83            void PickupTimerCallBack(void); //!< Function that gets called when the timer ends.
     84            bool invisible_; //!< Helper to remember wether the Pawn is invisible.
     85            float duration_; //! Duration of invisibility.
     86    };
     87}
     88
     89#endif // _InvisiblePickup_H__
Note: See TracChangeset for help on using the changeset viewer.