Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

source: code/branches/spacerace/src/modules/gametypes/RaceCheckPoint.cc @ 8552

Last change on this file since 8552 was 8552, checked in by msalomon, 13 years ago
File size: 3.0 KB
Line 
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 *      Mauro Salomon
24 *   Co-authors:
25 *      ...
26 *
27 */
28
29#include "RaceCheckPoint.h"
30
31#include "core/CoreIncludes.h"
32#include "core/XMLPort.h"
33#include "SpaceRace.h"
34
35namespace orxonox
36{
37    CreateFactory(RaceCheckPoint);
38   
39    RaceCheckPoint::RaceCheckPoint(BaseObject* creator):
40        DistanceTrigger(creator),
41        RadarViewable(creator, static_cast<WorldEntity*>(this))
42    {
43        RegisterObject(RaceCheckPoint);
44       
45        this->bCheckpointIndex_ = 0;
46        this->bIsLast_ = false;
47        this->bTimeLimit_ = 0;
48       
49        this->setRadarObjectColour(ColourValue::Red);
50        this->setRadarObjectShape(RadarViewable::Dot);
51        this->setRadarVisibility(false);
52    }
53   
54    RaceCheckPoint::~RaceCheckPoint()
55    {
56    }
57   
58    void RaceCheckPoint::tick(float dt)
59    {
60        Trigger::tick(dt);
61       
62        SpaceRace* gametype = orxonox_cast<SpaceRace*>(this->getGametype().get());
63        if (this->getCheckpointIndex() == gametype->getCheckpointsReached()) this->setRadarVisibility(true);
64        else  this->setRadarVisibility(false);
65       
66        if (this->bTimeLimit_ != 0 && gametype->getTimerIsActive()) {
67          float time = gametype->getTime() - this->bTimeLimit_;
68          if (time > 0) {
69            gametype->timeIsUp();
70            gametype->end();
71          }
72        }
73    }
74
75   
76    void RaceCheckPoint::XMLPort(Element& xmlelement, XMLPort::Mode mode)
77    {
78        SUPER(RaceCheckPoint, XMLPort, xmlelement, mode);
79       
80        XMLPortParam(RaceCheckPoint, "checkpointindex", setCheckpointIndex, getCheckpointIndex, xmlelement, mode).defaultValues(0);
81        XMLPortParam(RaceCheckPoint, "islast", setLast, getLast, xmlelement, mode).defaultValues(false);
82        XMLPortParam(RaceCheckPoint, "timelimit", setTimelimit, getTimeLimit, xmlelement, mode).defaultValues(0);
83    }
84   
85    void RaceCheckPoint::triggered(bool bIsTriggered)
86    {
87        DistanceTrigger::triggered(bIsTriggered);
88       
89        SpaceRace* gametype = orxonox_cast<SpaceRace*>(this->getGametype().get());
90        if (gametype)
91        {
92            if (this->getCheckpointIndex() == gametype->getCheckpointsReached() && bIsTriggered)
93            {
94                if (this->getLast())
95                {
96                  gametype->end();
97                }
98                else
99                {
100                  gametype->newCheckpointReached();
101                  this->setRadarObjectColour(ColourValue::Green); //sets the radar colour of the checkpoint to green if it is reached, else it is red.
102                }
103            }
104        }
105    }
106   
107}
Note: See TracBrowser for help on using the repository browser.