Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

source: code/branches/pickupsFS14/src/modules/jump/JumpScore.cc @ 10074

Last change on this file since 10074 was 10074, checked in by fvultier, 10 years ago

new items added. improved level generator.

File size: 3.6 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 *      Fabian 'x3n' Landau
24 *   Co-authors:
25 *      ...
26 *
27 */
28
29/**
30    @file JumpScore.cc
31    @brief Implementation of the JumpScore class.
32*/
33
34#include "JumpScore.h"
35
36#include "core/CoreIncludes.h"
37#include "core/XMLPort.h"
38#include "util/Convert.h"
39
40#include "infos/PlayerInfo.h"
41
42#include "Jump.h"
43#include "sound/WorldSound.h" /////////////////////////////
44
45namespace orxonox
46{
47    RegisterClass(JumpScore);
48
49    /**
50    @brief
51        Constructor. Registers and initializes the object.
52    */
53    JumpScore::JumpScore(Context* context) : OverlayText(context)
54    {
55        RegisterObject(JumpScore);
56
57        owner_ = NULL;
58        showScore_ = false;
59        showMessages_ = false;
60    }
61
62    /**
63    @brief
64        Destructor.
65    */
66    JumpScore::~JumpScore()
67    {
68
69    }
70
71    /**
72    @brief
73        Method to create a JumpScore through XML.
74    */
75    void JumpScore::XMLPort(Element& xmlelement, XMLPort::Mode mode)
76    {
77        SUPER(JumpScore, XMLPort, xmlelement, mode);
78
79        XMLPortParam(JumpScore, "showScore", setShowScore, getShowScore, xmlelement, mode);
80        XMLPortParam(JumpScore, "showMessages", setShowMessages, getShowMessages, xmlelement, mode);
81        XMLPortParam(JumpScore, "gameOverText", setGameOverText, getGameOverText, xmlelement, mode);
82    }
83
84    /**
85    @brief
86        Is called each tick.
87        Creates and sets the caption to be displayed by the JumpScore.
88    @param dt
89        The time that has elapsed since the last tick.
90    */
91    void JumpScore::tick(float dt)
92    {
93        SUPER(JumpScore, tick, dt);
94
95        // If the owner is set. The owner being a Jump game.
96
97        if (this->owner_ != NULL)
98        {
99            if (!owner_->hasEnded())
100            {
101                player_ = owner_->getPlayer();
102
103                if (player_ != NULL)
104                {
105                        if (showScore_ == true)
106                        {
107                        int score = owner_->getScore(player_);
108
109                        std::string str = multi_cast<std::string>(score);
110                        setCaption(str);
111                        }
112                        else if (showMessages_ == true)
113                        {
114
115                        setCaption(owner_->getDead(player_) == true ? gameOverText_ : "");
116                        }
117                }
118            }
119        }
120    }
121
122    /**
123    @brief
124        Is called when the owner changes.
125        Sets the owner to NULL, if it is not a pointer to a Jump game.
126    */
127    void JumpScore::changedOwner()
128    {
129        SUPER(JumpScore, changedOwner);
130
131        if (this->getOwner() != NULL && this->getOwner()->getGametype())
132        {
133            this->owner_ = orxonox_cast<Jump*>(this->getOwner()->getGametype().get());
134        }
135        else
136        {
137            this->owner_ = NULL;
138        }
139    }
140}
Note: See TracBrowser for help on using the repository browser.