Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

source: code/branches/mergeFS18/src/modules/pacman/PacmanHUDinfo.cc @ 12045

Last change on this file since 12045 was 11992, checked in by dreherm, 6 years ago

Testversion 1

File size: 4.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 *      Marc Dreher
24
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
35namespace 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;
46        this->bShowGhoststatus_ = false;
47        this->messageID = 0;
48
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);
57        XMLPortParam(PacmanHUDinfo, "showghoststatus",   setGhoststatus,   getGhoststatus,   xmlelement, mode).defaultValues(false);
58        XMLPortParam(PacmanHUDinfo, "messageID",     setMessageID,     getMessageID,     xmlelement, mode).defaultValues(0);
59        XMLPortParam(PacmanHUDinfo, "showgameover",   setGameover,   getGameover,   xmlelement, mode).defaultValues(false);
60        XMLPortParam(PacmanHUDinfo, "showlive",   setlive,   getlive,   xmlelement, mode).defaultValues(false);
61        XMLPortParam(PacmanHUDinfo, "showlevel",   setlevel,   getlevel,   xmlelement, mode).defaultValues(false);
62       
63   
64    }
65
66    void PacmanHUDinfo::tick(float dt)
67    {
68        SUPER(PacmanHUDinfo, tick, dt);
69
70        if (this->PacmanGame)
71        {
72            bool death = this->PacmanGame->isdead();
73            if(death && showgameover){
74                const std::string& deathmessage = "Game Over";
75                    setTextSize(0.08);
76                    this->setCaption(deathmessage);
77            }
78           
79            if(this->bShowPoints_) {
80                    const std::string& points = "Collected points: "+multi_cast<std::string>(this->PacmanGame->getPoints()) + " of " + multi_cast<std::string>(this->PacmanGame->getTotalpoints());
81                    setTextSize(0.03);
82                    this->setCaption(points);
83            }
84 
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                    }
96            }
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
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
111            if(death && !(this->showgameover)){
112                setTextSize(0.0);
113            }
114
115        }
116    }   
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}
Note: See TracBrowser for help on using the repository browser.