| [11931] | 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: | 
|---|
| [11992] | 23 |  *      Marc Dreher | 
|---|
 | 24 |  | 
|---|
| [11931] | 25 |  *      Co-authors: | 
|---|
 | 26 |  *      ... | 
|---|
 | 27 |  */ | 
|---|
 | 28 |  | 
|---|
 | 29 | #include "PacmanHUDinfo.h" | 
|---|
 | 30 |  | 
|---|
 | 31 | #include "core/CoreIncludes.h" | 
|---|
 | 32 | #include "core/XMLPort.h" | 
|---|
 | 33 | #include "util/Convert.h" | 
|---|
 | 34 |  | 
|---|
 | 35 | namespace orxonox | 
|---|
 | 36 | { | 
|---|
 | 37 |     RegisterClass(PacmanHUDinfo); | 
|---|
 | 38 |  | 
|---|
 | 39 |     PacmanHUDinfo::PacmanHUDinfo(Context* context) : OverlayText(context) | 
|---|
 | 40 |     { | 
|---|
 | 41 |         RegisterObject(PacmanHUDinfo); | 
|---|
 | 42 |  | 
|---|
 | 43 |         this->PacmanGame = nullptr; | 
|---|
 | 44 |         this->bShowPoints_ = false; | 
|---|
 | 45 |         this->bShowMessage_ = false; | 
|---|
| [11961] | 46 |         this->bShowGhoststatus_ = false; | 
|---|
| [11931] | 47 |         this->messageID = 0; | 
|---|
| [11961] | 48 |  | 
|---|
| [11931] | 49 |     } | 
|---|
 | 50 |  | 
|---|
 | 51 |     void PacmanHUDinfo::XMLPort(Element& xmlelement, XMLPort::Mode mode) | 
|---|
 | 52 |     { | 
|---|
 | 53 |         SUPER(PacmanHUDinfo, XMLPort, xmlelement, mode); | 
|---|
 | 54 |  | 
|---|
 | 55 |         XMLPortParam(PacmanHUDinfo, "showpoints",    setShowPoints,    getShowPoints,    xmlelement, mode).defaultValues(false); | 
|---|
 | 56 |         XMLPortParam(PacmanHUDinfo, "showmessage",   setShowMessage,   getShowMessage,   xmlelement, mode).defaultValues(false); | 
|---|
| [11961] | 57 |         XMLPortParam(PacmanHUDinfo, "showghoststatus",   setGhoststatus,   getGhoststatus,   xmlelement, mode).defaultValues(false); | 
|---|
| [11931] | 58 |         XMLPortParam(PacmanHUDinfo, "messageID",     setMessageID,     getMessageID,     xmlelement, mode).defaultValues(0); | 
|---|
| [11978] | 59 |         XMLPortParam(PacmanHUDinfo, "showgameover",   setGameover,   getGameover,   xmlelement, mode).defaultValues(false); | 
|---|
 | 60 |         XMLPortParam(PacmanHUDinfo, "showlive",   setlive,   getlive,   xmlelement, mode).defaultValues(false); | 
|---|
| [11979] | 61 |         XMLPortParam(PacmanHUDinfo, "showlevel",   setlevel,   getlevel,   xmlelement, mode).defaultValues(false); | 
|---|
| [11931] | 62 |         | 
|---|
 | 63 |      | 
|---|
 | 64 |     } | 
|---|
 | 65 |  | 
|---|
 | 66 |     void PacmanHUDinfo::tick(float dt) | 
|---|
 | 67 |     { | 
|---|
 | 68 |         SUPER(PacmanHUDinfo, tick, dt); | 
|---|
 | 69 |  | 
|---|
 | 70 |         if (this->PacmanGame) | 
|---|
 | 71 |         { | 
|---|
| [11976] | 72 |             bool death = this->PacmanGame->isdead(); | 
|---|
| [11978] | 73 |             if(death && showgameover){ | 
|---|
| [11976] | 74 |                 const std::string& deathmessage = "Game Over"; | 
|---|
| [11978] | 75 |                     setTextSize(0.08); | 
|---|
| [11976] | 76 |                     this->setCaption(deathmessage); | 
|---|
 | 77 |             } | 
|---|
 | 78 |              | 
|---|
| [11978] | 79 |             if(this->bShowPoints_) { | 
|---|
| [11992] | 80 |                     const std::string& points = "Collected points: "+multi_cast<std::string>(this->PacmanGame->getPoints()) + " of " + multi_cast<std::string>(this->PacmanGame->getTotalpoints()); | 
|---|
| [11978] | 81 |                     setTextSize(0.03); | 
|---|
| [11931] | 82 |                     this->setCaption(points); | 
|---|
| [11976] | 83 |             } | 
|---|
 | 84 |    | 
|---|
| [11978] | 85 |             if(this->bShowGhoststatus_){ | 
|---|
 | 86 |                     if(this->PacmanGame->getAfraid()) { | 
|---|
 | 87 |                        const std::string& ghoststatus = "Catch the ghosts! \n " + multi_cast<std::string>(this->PacmanGame->getTimer()) + " seconds left"; | 
|---|
 | 88 |                        setTextSize(0.03); | 
|---|
 | 89 |                        this->setCaption(ghoststatus); | 
|---|
 | 90 |                     } | 
|---|
 | 91 |                     else{ | 
|---|
 | 92 |                        const std::string& ghoststatus = "Do not get caught!";  | 
|---|
 | 93 |                        setTextSize(0.03); | 
|---|
 | 94 |                        this->setCaption(ghoststatus); | 
|---|
 | 95 |                     } | 
|---|
| [11976] | 96 |             } | 
|---|
| [11978] | 97 |  | 
|---|
 | 98 |             if(this->showlive){ | 
|---|
 | 99 |                 const std::string& live = "Remaining lives: "+multi_cast<std::string>(this->PacmanGame->getLives()); | 
|---|
 | 100 |                 setTextSize(0.03); | 
|---|
 | 101 |                 this->setCaption(live); | 
|---|
 | 102 |             } | 
|---|
 | 103 |  | 
|---|
| [11979] | 104 |             if(this->showlevel){ | 
|---|
 | 105 |                 const std::string& live = "Level: "+multi_cast<std::string>(this->PacmanGame->getLevel()); | 
|---|
 | 106 |                 setTextSize(0.03); | 
|---|
 | 107 |                 this->setCaption(live); | 
|---|
 | 108 |             } | 
|---|
 | 109 |  | 
|---|
 | 110 |  | 
|---|
| [11978] | 111 |             if(death && !(this->showgameover)){ | 
|---|
 | 112 |                 setTextSize(0.0); | 
|---|
 | 113 |             } | 
|---|
 | 114 |  | 
|---|
| [11931] | 115 |         } | 
|---|
| [11958] | 116 |     }     | 
|---|
| [11931] | 117 |  | 
|---|
 | 118 |     void PacmanHUDinfo::changedOwner() | 
|---|
 | 119 |     { | 
|---|
 | 120 |         SUPER(PacmanHUDinfo, changedOwner); | 
|---|
 | 121 |  | 
|---|
 | 122 |         if (this->getOwner() && this->getOwner()->getGametype()) | 
|---|
 | 123 |         { | 
|---|
 | 124 |             this->PacmanGame = orxonox_cast<Pacman*>(this->getOwner()->getGametype()); | 
|---|
 | 125 |         } | 
|---|
 | 126 |         else | 
|---|
 | 127 |         { | 
|---|
 | 128 |             this->PacmanGame = nullptr; | 
|---|
 | 129 |         } | 
|---|
 | 130 |     } | 
|---|
 | 131 | } | 
|---|