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 | * Florian Zinggeler |
---|
24 | * |
---|
25 | */ |
---|
26 | |
---|
27 | #include "Asteroids2DHUDinfo.h" |
---|
28 | |
---|
29 | #include "core/CoreIncludes.h" |
---|
30 | #include "core/XMLPort.h" |
---|
31 | #include "util/Convert.h" |
---|
32 | //#include "Asteroids2D.h" |
---|
33 | |
---|
34 | namespace orxonox |
---|
35 | { |
---|
36 | RegisterClass(Asteroids2DHUDinfo); |
---|
37 | |
---|
38 | Asteroids2DHUDinfo::Asteroids2DHUDinfo(Context* context) : OverlayText(context) |
---|
39 | { |
---|
40 | RegisterObject(Asteroids2DHUDinfo); |
---|
41 | |
---|
42 | this->Asteroids2DGame = nullptr; |
---|
43 | this->Ship = nullptr; |
---|
44 | this->bShowPoints_ = true; |
---|
45 | this->bShowHealth_ = true; |
---|
46 | } |
---|
47 | |
---|
48 | void Asteroids2DHUDinfo::XMLPort(Element& xmlelement, XMLPort::Mode mode) |
---|
49 | { |
---|
50 | SUPER(Asteroids2DHUDinfo, XMLPort, xmlelement, mode); |
---|
51 | |
---|
52 | XMLPortParam(Asteroids2DHUDinfo,"showPoints", setShowPoints, getShowPoints, xmlelement, mode).defaultValues(false); |
---|
53 | XMLPortParam(Asteroids2DHUDinfo,"showHealth", setShowHealth, getShowHealth, xmlelement, mode).defaultValues(false); |
---|
54 | } |
---|
55 | |
---|
56 | void Asteroids2DHUDinfo::tick(float dt) |
---|
57 | { |
---|
58 | SUPER(Asteroids2DHUDinfo, tick, dt); |
---|
59 | |
---|
60 | |
---|
61 | if(this->bShowPoints_) |
---|
62 | { |
---|
63 | const std::string& points = multi_cast<std::string>(this->Asteroids2DGame->getPoints()); |
---|
64 | if (this->Asteroids2DGame->lives <= 0) |
---|
65 | { |
---|
66 | setTextSize(0.2); |
---|
67 | setPosition(Vector2(0.1, 0.02)); |
---|
68 | this->setCaption("Final score:\n" + points); |
---|
69 | this->setColour(ColourValue(1, 0, 0, 1)); |
---|
70 | } |
---|
71 | else |
---|
72 | { |
---|
73 | setTextSize(0.04); |
---|
74 | setPosition(Vector2(0.14, 0.02)); |
---|
75 | this->setColour(ColourValue(1, 1, 1, 1)); |
---|
76 | this->setCaption(points); |
---|
77 | } |
---|
78 | } |
---|
79 | |
---|
80 | /*if(this->bShowHealth_) |
---|
81 | { |
---|
82 | const std::string& health = multi_cast<std::string>(this->Ship->getHealth()); |
---|
83 | if (this->Asteroids2DGame->lives <= 0) |
---|
84 | { |
---|
85 | setTextSize(0.2); |
---|
86 | setPosition(Vector2(0.1, 0.02)); |
---|
87 | this->setCaption("Final score:\n" + health); |
---|
88 | this->setColour(ColourValue(1, 0, 0, 1)); |
---|
89 | } |
---|
90 | else |
---|
91 | { |
---|
92 | setTextSize(0.04); |
---|
93 | setPosition(Vector2(0.2, 0.02)); |
---|
94 | this->setColour(ColourValue(1, 1, 1, 1)); |
---|
95 | this->setCaption(health); |
---|
96 | } |
---|
97 | }*/ |
---|
98 | } |
---|
99 | |
---|
100 | void Asteroids2DHUDinfo::changedOwner() |
---|
101 | { |
---|
102 | SUPER(Asteroids2DHUDinfo, changedOwner); |
---|
103 | |
---|
104 | if (this->getOwner() && this->getOwner()->getGametype())//&& this->getOwner->getPlayer()) |
---|
105 | { |
---|
106 | this->Asteroids2DGame = orxonox_cast<Asteroids2D*>(this->getOwner()->getGametype()); |
---|
107 | //this->Ship = orxonox_cast<Asteroids2DShip*>(this->getOwner()->getPlayer()); |
---|
108 | } |
---|
109 | else |
---|
110 | { |
---|
111 | this->Asteroids2DGame = nullptr; |
---|
112 | } |
---|
113 | } |
---|
114 | } |
---|