Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

source: code/branches/cpp11_v2/src/modules/towerdefense/TowerDefenseSelecter.cc @ 10825

Last change on this file since 10825 was 10629, checked in by fvultier, 9 years ago

Merged towerdefenseFabien branch back to trunk. The towerdefense Minigame is now a plugin.

  • Property svn:eol-style set to native
File size: 4.7 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 *      Fabien Vultier
24 *   Co-authors:
25 *      ...
26 *
27 */
28
29/**
30    @file TowerDefenseSelecter.cc
31    @brief This class represents your figure when you play the minigame. Here the movement of the figure, activating items, ... are handled.
32*/
33
34#include "TowerDefenseSelecter.h"
35
36#include "core/CoreIncludes.h"
37#include "core/XMLPort.h"
38#include "graphics/Model.h"
39
40namespace orxonox
41{
42    RegisterClass(TowerDefenseSelecter);
43
44    TowerDefenseSelecter::TowerDefenseSelecter(Context* context) : ControllableEntity(context)
45    {
46        RegisterObject(TowerDefenseSelecter);
47
48        // initialize variables
49        moveUpPressed_ = false;
50        moveDownPressed_ = false;
51        moveLeftPressed_ = false;
52        moveRightPressed_ = false;
53        boostPressed_ = false;
54        buildTower_ = false;
55        setSelectedPosition(0,0);     
56    }
57
58    TowerDefenseSelecter::~TowerDefenseSelecter()
59    {
60
61    }
62
63    void TowerDefenseSelecter::XMLPort(Element& xmlelement, XMLPort::Mode mode)
64    {
65        SUPER(TowerDefenseSelecter, XMLPort, xmlelement, mode);
66    }
67
68    void TowerDefenseSelecter::tick(float dt)
69    {
70        SUPER(TowerDefenseSelecter, tick, dt);
71
72        time_ += dt;
73
74        if (hasLocalController() && time_ >= 0.25)
75        {   
76            time_ = 0;
77
78            int selecterPosX = selectedPos_->GetX();
79            int selecterPosY = selectedPos_->GetY();
80
81            if (moveUpPressed_ == true)
82            {               
83                moveUpPressed_ = false;
84                selectedPos_->Set(selecterPosX, selecterPosY + 1);
85                updatePosition();
86            }
87            if (moveDownPressed_ == true)
88            {
89                moveDownPressed_ = false;
90                selectedPos_->Set(selecterPosX, selecterPosY - 1);
91                updatePosition();
92            }
93            if (moveLeftPressed_ == true)
94            {
95                moveLeftPressed_ = false;
96                selectedPos_->Set(selecterPosX - 1, selecterPosY);
97                updatePosition();
98            }
99            if (moveRightPressed_ == true)
100            {
101                moveRightPressed_ = false;
102                selectedPos_->Set(selecterPosX + 1, selecterPosY);
103                updatePosition();
104            }
105            if (boostPressed_ == true)
106            {
107                boostPressed_ = false;
108                buildTower_ = true;
109            }
110        }         
111    }
112
113
114    void TowerDefenseSelecter::moveFrontBack(const Vector2& value)
115    {
116        if (value.x > 0)
117        {
118            moveUpPressed_ = true;
119            moveDownPressed_ = false;
120        }
121        else
122        {
123            moveUpPressed_ = false;
124            moveDownPressed_ = true;
125        }
126    }
127
128    void TowerDefenseSelecter::moveRightLeft(const Vector2& value)
129    {
130        if (value.x > 0)
131        {
132            moveLeftPressed_ = false;
133            moveRightPressed_ = true;
134        }
135        else
136        {
137            moveLeftPressed_ = true;
138            moveRightPressed_ = false;
139        }
140    }
141
142    void TowerDefenseSelecter::rotateYaw(const Vector2& value)
143    {
144    }
145
146    void TowerDefenseSelecter::rotatePitch(const Vector2& value)
147    {
148    }
149
150    void TowerDefenseSelecter::rotateRoll(const Vector2& value)
151    {
152    }
153
154    void TowerDefenseSelecter::fire(unsigned int firemode)
155    {
156    }
157
158    void TowerDefenseSelecter::fired(unsigned int firemode)
159    {
160       
161    }
162
163    void TowerDefenseSelecter::boost(bool bBoost)
164    {
165        if (bBoost == true)
166        {
167            boostPressed_ = true;
168        }
169    }
170
171    void TowerDefenseSelecter::updatePosition()
172    {
173        setPosition(selectedPos_->get3dcoordinate());
174    }
175
176    void TowerDefenseSelecter::setSelectedPosition(TDCoordinate* newPos)
177    {
178        selectedPos_ = newPos;
179        updatePosition();
180    }
181
182    void TowerDefenseSelecter::setSelectedPosition(int x,  int y)
183    {
184        setSelectedPosition(new TDCoordinate(x,y));
185    }
186}
Note: See TracBrowser for help on using the repository browser.