Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

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

Last change on this file since 8494 was 8494, checked in by msalomon, 13 years ago

RaceCheckPoint type and test level for the spaceRace gametype.

File size: 2.7 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       
48        this->setRadarObjectColour(ColourValue::Red);
49        this->setRadarObjectShape(RadarViewable::Dot);
50        this->setRadarVisibility(false);
51    }
52   
53    RaceCheckPoint::~RaceCheckPoint()
54    {
55    }
56   
57    void RaceCheckPoint::tick(float dt)
58    {
59        Trigger::tick(dt);
60       
61        SpaceRace* gametype = orxonox_cast<SpaceRace*>(this->getGametype().get());
62        if (this->getCheckpointIndex() == gametype->getCheckpointsReached()) this->setRadarVisibility(true);
63        else  this->setRadarVisibility(false);
64    }
65
66   
67    void RaceCheckPoint::XMLPort(Element& xmlelement, XMLPort::Mode mode)
68    {
69        SUPER(RaceCheckPoint, XMLPort, xmlelement, mode);
70       
71        XMLPortParam(RaceCheckPoint, "checkpointindex", setCheckpointIndex, getCheckpointIndex, xmlelement, mode).defaultValues(0);
72        XMLPortParam(RaceCheckPoint, "islast", setLast, getLast, xmlelement, mode).defaultValues(false);
73    }
74   
75    void RaceCheckPoint::triggered(bool bIsTriggered)
76    {
77        DistanceTrigger::triggered(bIsTriggered);
78       
79        SpaceRace* gametype = orxonox_cast<SpaceRace*>(this->getGametype().get());
80        if (gametype)
81        {
82            if (this->getCheckpointIndex() == gametype->getCheckpointsReached() && bIsTriggered)
83            {
84                if (this->getLast())
85                {
86                  gametype->end();
87                }
88                else
89                {
90                  gametype->newCheckpointReached();
91                  this->setRadarObjectColour(ColourValue::Green); //sets the radar colour of the checkpoint to green if it is reached, else it is red.
92                }
93            }
94        }
95    }
96   
97}
Note: See TracBrowser for help on using the repository browser.