Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

source: code/branches/presentationFS16/src/modules/jump/JumpScore.cc @ 11193

Last change on this file since 11193 was 11071, checked in by landauf, 9 years ago

merged branch cpp11_v3 back to trunk

  • Property svn:eol-style set to native
File size: 3.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 *      Fabien Vultier
24 *   Co-authors:
25 *      ...
26 *
27 */
28
29/**
30    @file JumpScore.cc
31    @brief HUD of thejump minigame. If showScore_ is set, it displays the score. If showMessages_ is set, it displays the game over message.
32*/
33
34#include "JumpScore.h"
35
36#include "core/CoreIncludes.h"
37#include "core/XMLPort.h"
38#include "util/Convert.h"
39#include "infos/PlayerInfo.h"
40#include "Jump.h"
41
42namespace orxonox
43{
44    RegisterClass(JumpScore);
45
46    JumpScore::JumpScore(Context* context) : OverlayText(context)
47    {
48        RegisterObject(JumpScore);
49
50        owner_ = nullptr;
51        showScore_ = false;
52        showFuel_ = false;
53        showMessages_ = false;
54    }
55
56    JumpScore::~JumpScore()
57    {
58
59    }
60
61    void JumpScore::XMLPort(Element& xmlelement, XMLPort::Mode mode)
62    {
63        SUPER(JumpScore, XMLPort, xmlelement, mode);
64
65        XMLPortParam(JumpScore, "showScore", setShowScore, getShowScore, xmlelement, mode);
66        XMLPortParam(JumpScore, "showFuel", setShowFuel, getShowFuel, xmlelement, mode);
67        XMLPortParam(JumpScore, "showMessages", setShowMessages, getShowMessages, xmlelement, mode);
68        XMLPortParam(JumpScore, "gameOverText", setGameOverText, getGameOverText, xmlelement, mode);
69    }
70
71    void JumpScore::tick(float dt)
72    {
73        SUPER(JumpScore, tick, dt);
74
75        if (owner_ != nullptr)
76        {
77            if (!owner_->hasEnded())
78            {
79                player_ = owner_->getPlayer();
80
81                if (player_ != nullptr)
82                {
83                    if (showScore_ == true)
84                    {
85                        int score = owner_->getScore(player_);
86
87                        std::string str = multi_cast<std::string>(score);
88                        setCaption(str);
89                    }
90                    else if (showFuel_ == true)
91                    {
92                        float fuel = owner_->getFuel();
93                        std::string str;
94
95                        if (fuel <= 0.0)
96                        {
97                            str = "";
98                        }
99                        else
100                        {
101                            str = multi_cast<std::string>(fuel);
102                        }
103                        setCaption(str);
104                    }
105                    else if (showMessages_ == true)
106                    {
107                        setCaption(owner_->getDead(player_) == true ? gameOverText_ : "");
108                    }
109                }
110            }
111        }
112    }
113
114    void JumpScore::changedOwner()
115    {
116        SUPER(JumpScore, changedOwner);
117
118        if (this->getOwner() != nullptr && this->getOwner()->getGametype())
119        {
120            this->owner_ = orxonox_cast<Jump*>(this->getOwner()->getGametype());
121        }
122        else
123        {
124            this->owner_ = nullptr;
125        }
126    }
127}
Note: See TracBrowser for help on using the repository browser.