Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

source: code/branches/OrxoBlox_FS19/src/modules/OrxoBlox/OrxoBloxScore.cc @ 12368

Last change on this file since 12368 was 12366, checked in by ahuwyler, 6 years ago

Here and there

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 *      Fabian 'x3n' Landau
24 *   Co-authors:
25 *      ...
26 *
27 */
28
29/**
30    @file OrxoBloxScore.cc
31    @brief Implementation of the OrxoBloxScore class.
32*/
33
34#include "OrxoBloxScore.h"
35
36#include "core/CoreIncludes.h"
37#include "util/Convert.h"
38
39#include "infos/PlayerInfo.h"
40
41#include "OrxoBlox.h"
42
43namespace orxonox
44{
45    RegisterClass(OrxoBloxScore);
46
47    /**
48    @brief
49        Constructor. Registers and initializes the object.
50    */
51    OrxoBloxScore::OrxoBloxScore(Context* context) : OverlayText(context)
52    {
53        RegisterObject(OrxoBloxScore);
54
55        this->owner_ = nullptr;
56        this->player_ = nullptr;
57    }
58    /**
59    @brief
60        Destructor.
61    */
62    OrxoBloxScore::~OrxoBloxScore()
63    {
64    }
65
66   
67    /**
68    @brief
69        Is called each tick.
70        Creates and sets the caption to be displayed by the OrxoBloxScore.
71    @param dt
72        The time that has elapsed since the last tick.
73    */
74    void OrxoBloxScore::tick(float dt)
75    {
76        SUPER(OrxoBloxScore, tick, dt);
77
78        // If the owner is set. The owner being a OrxoBlox game.
79        if (this->owner_ != nullptr)
80        {
81            std::string score("0");
82            if(!this->owner_->hasEnded())
83            {
84                //get the player
85                player_ = this->owner_->getPlayer();
86            }
87
88            if(this->owner_->hasStarted())
89            {
90                // Save the name and score of each player as a string.
91                if (player_ != nullptr)
92                    score = multi_cast<std::string>(this->owner_->getScore(player_));
93            }
94            this->setCaption(score);
95        }
96    }
97
98    /**
99    @brief
100        Is called when the owner changes.
101        Sets the owner to nullptr, if it is not a pointer to a OrxoBlox game.
102    */
103    void OrxoBloxScore::changedOwner()
104    {
105        SUPER(OrxoBloxScore, changedOwner);
106
107        if (this->getOwner() != nullptr && this->getOwner()->getGametype())
108            this->owner_ = orxonox_cast<OrxoBlox*>(this->getOwner()->getGametype());
109        else
110            this->owner_ = nullptr;
111    }
112}
Note: See TracBrowser for help on using the repository browser.