Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

source: code/branches/Presentation_HS17_merge/src/modules/towerdefense/TowerDefenseSelecter.cc @ 11772

Last change on this file since 11772 was 11071, checked in by landauf, 9 years ago

merged branch cpp11_v3 back to trunk

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