Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

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

Last change on this file since 12396 was 12396, checked in by pomselj, 5 years ago

Jesus safed our souls and stopped the crashing. Hallowed be his name and hallowed be his followers sevy and aryo, first of their names, saviors of the andals the raynars and the first nerds. Fourier is love btw

File size: 1.9 KB
Line 
1#include "OrxoBloxScore.h"
2
3#include "core/CoreIncludes.h"
4#include "util/Convert.h"
5
6#include "infos/PlayerInfo.h"
7
8#include "OrxoBlox.h"
9
10namespace orxonox
11{
12    RegisterClass(OrxoBloxScore);
13
14    /**
15    @brief
16        Constructor. Registers and initializes the object.
17    */
18    OrxoBloxScore::OrxoBloxScore(Context* context) : OverlayText(context)
19    {
20        RegisterObject(OrxoBloxScore);
21
22        this->owner_ = nullptr;
23        this->player_ = nullptr;
24    }
25    /**
26    @brief
27        Destructor.
28    */
29    OrxoBloxScore::~OrxoBloxScore()
30    {
31    }
32
33   
34    /**
35    @brief
36        Is called each tick.
37        Creates and sets the caption to be displayed by the OrxoBloxScore.
38    @param dt
39        The time that has elapsed since the last tick.
40    */
41    void OrxoBloxScore::tick(float dt)
42    {
43        SUPER(OrxoBloxScore, tick, dt);
44
45        // If the owner is set. The owner being a OrxoBlox game.
46        if (this->owner_ != nullptr)
47        {
48            std::string score("0");
49            if(!this->owner_->hasEnded())
50            {
51                //get the player
52                player_ = this->owner_->getPlayer();
53            }
54
55            if(this->owner_->hasStarted())
56            {
57                // Save the name and score of each player as a string.
58                if (player_ != nullptr)
59                    score = multi_cast<std::string>(this->owner_->getScore(player_));
60            }
61            this->setCaption(score);
62        }
63    }
64
65    /**
66    @brief
67        Is called when the owner changes.
68        Sets the owner to nullptr, if it is not a pointer to a OrxoBlox game.
69    */
70    void OrxoBloxScore::changedOwner()
71    {
72        SUPER(OrxoBloxScore, changedOwner);
73
74        if (this->getOwner() != nullptr && this->getOwner()->getGametype())
75            this->owner_ = orxonox_cast<OrxoBlox*>(this->getOwner()->getGametype());
76        else
77            this->owner_ = nullptr;
78    }
79}
Note: See TracBrowser for help on using the repository browser.