Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

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

Last change on this file since 8548 was 8548, checked in by msalomon, 13 years ago
File size: 2.9 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
67   
68    void RaceCheckPoint::XMLPort(Element& xmlelement, XMLPort::Mode mode)
69    {
70        SUPER(RaceCheckPoint, XMLPort, xmlelement, mode);
71       
72        XMLPortParam(RaceCheckPoint, "checkpointindex", setCheckpointIndex, getCheckpointIndex, xmlelement, mode).defaultValues(0);
73        XMLPortParam(RaceCheckPoint, "islast", setLast, getLast, xmlelement, mode).defaultValues(false);
74        XMLPortParam(RaceCheckPoint, "timelimit", setTimelimit, getTimeLimit, xmlelement, mode).defaultValues(0);
75    }
76   
77    void RaceCheckPoint::triggered(bool bIsTriggered)
78    {
79        DistanceTrigger::triggered(bIsTriggered);
80       
81        SpaceRace* gametype = orxonox_cast<SpaceRace*>(this->getGametype().get());
82        if (gametype)
83        {
84            if (this->getCheckpointIndex() == gametype->getCheckpointsReached() && bIsTriggered)
85            {
86                if (this->getLast())
87                {
88                  gametype->end();
89                }
90                else
91                {
92                  gametype->newCheckpointReached();
93                  this->setRadarObjectColour(ColourValue::Green); //sets the radar colour of the checkpoint to green if it is reached, else it is red.
94                }
95            }
96        }
97    }
98   
99}
Note: See TracBrowser for help on using the repository browser.