Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

source: code/trunk/src/modules/overlays/hud/HUDEnemyHealthBar.cc @ 10090

Last change on this file since 10090 was 9667, checked in by landauf, 11 years ago

merged core6 back to trunk

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