#include "OrxoBloxScore.h" #include "core/CoreIncludes.h" #include "util/Convert.h" #include "infos/PlayerInfo.h" #include "OrxoBlox.h" namespace orxonox { RegisterClass(OrxoBloxScore); /** @brief Constructor. Registers and initializes the object. */ OrxoBloxScore::OrxoBloxScore(Context* context) : OverlayText(context) { RegisterObject(OrxoBloxScore); this->owner_ = nullptr; this->player_ = nullptr; } /** @brief Destructor. */ OrxoBloxScore::~OrxoBloxScore() { } /** @brief Is called each tick. Creates and sets the caption to be displayed by the OrxoBloxScore. @param dt The time that has elapsed since the last tick. */ void OrxoBloxScore::tick(float dt) { SUPER(OrxoBloxScore, tick, dt); // If the owner is set. The owner being a OrxoBlox game. if (this->owner_ != nullptr) { std::string score("0"); if(!this->owner_->hasEnded()) { //get the player player_ = this->owner_->getPlayer(); } if(this->owner_->hasStarted()) { // Save the name and score of each player as a string. if (player_ != nullptr) score = multi_cast(this->owner_->getScore(player_)); } this->setCaption(score); } } /** @brief Is called when the owner changes. Sets the owner to nullptr, if it is not a pointer to a OrxoBlox game. */ void OrxoBloxScore::changedOwner() { SUPER(OrxoBloxScore, changedOwner); if (this->getOwner() != nullptr && this->getOwner()->getGametype()) this->owner_ = orxonox_cast(this->getOwner()->getGametype()); else this->owner_ = nullptr; } }