Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

source: code/branches/OrxoBlox_FS19/src/modules/overlays/hud/HUDEnemyHealthBar.cc

Last change on this file 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: 2.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 *      Matthias Spalinger
24 *   Co-authors:
25 *      Fabian 'x3n' Landau
26 *
27 */
28
29#include "HUDEnemyHealthBar.h"
30
31#include "core/config/ConfigValueIncludes.h"
32#include "core/CoreIncludes.h"
33#include "worldentities/pawns/Pawn.h"
34
35namespace orxonox
36{
37    RegisterClass(HUDEnemyHealthBar);
38
39    HUDEnemyHealthBar::HUDEnemyHealthBar(Context* context) : HUDHealthBar(context)
40    {
41        RegisterObject(HUDEnemyHealthBar);
42
43        this->setConfigValues();
44        this->owner_ = nullptr;
45    }
46
47    HUDEnemyHealthBar::~HUDEnemyHealthBar()
48    {
49    }
50
51    void HUDEnemyHealthBar::setConfigValues()
52    {
53        SetConfigValue(useEnemyBar_, true);
54    }
55
56    void HUDEnemyHealthBar::tick(float dt)
57    {
58        this->updateTarget();
59
60        SUPER(HUDEnemyHealthBar, tick, dt);
61    }
62
63    void HUDEnemyHealthBar::updateTarget()
64    {
65        Pawn* pawn = nullptr;
66        if (this->owner_ && this->useEnemyBar_)
67        {
68            // Get the owner's current target (target is usually a Model)
69            WorldEntity* target = this->owner_->getTarget();
70            // Find the Pawn that belongs to this target (if any)
71            while (target && !target->isA(Class(Pawn)))
72                target = target->getParent();
73            pawn = orxonox_cast<Pawn*>(target);
74            // Don't show the HealthBar if the pawn is invisible
75            if (pawn && !pawn->isVisible())
76                pawn = nullptr;
77        }
78        // Set the pawn as owner of the HealthBar
79        this->setHealthBarOwner(pawn);
80        this->setVisible(pawn != nullptr);
81    }
82
83    void HUDEnemyHealthBar::changedOwner()
84    {
85        SUPER(HUDEnemyHealthBar, changedOwner);
86
87        this->owner_ = orxonox_cast<ControllableEntity*>(this->getOwner());
88        this->updateTarget();
89    }
90}
Note: See TracBrowser for help on using the repository browser.