Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

source: code/branches/towerdefenseFS15/src/modules/towerdefense/TowerDefenseSelecter.cc @ 10406

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

There is now a cube that can be moved on the playground using the arrow keys.

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        setSelectedPosition(0,0);     
54    }
55
56    TowerDefenseSelecter::~TowerDefenseSelecter()
57    {
58
59    }
60
61    void TowerDefenseSelecter::XMLPort(Element& xmlelement, XMLPort::Mode mode)
62    {
63        SUPER(TowerDefenseSelecter, XMLPort, xmlelement, mode);
64    }
65
66    void TowerDefenseSelecter::tick(float dt)
67    {
68        SUPER(TowerDefenseSelecter, tick, dt);
69
70        if (hasLocalController())
71        {
72            int selecterPosX = selectedPos_->GetX();
73            int selecterPosY = selectedPos_->GetY();
74
75            if (moveUpPressed_ == true)
76            {
77                selectedPos_->Set(selecterPosX, selecterPosY + 1);
78                updatePosition();
79                orxout() << "up" << endl;
80            }
81            if (moveDownPressed_ == true)
82            {
83                selectedPos_->Set(selecterPosX, selecterPosY - 1);
84                updatePosition();
85                orxout() << "Down" << endl;
86            }
87
88            if (moveLeftPressed_ == true)
89            {
90                selectedPos_->Set(selecterPosX - 1, selecterPosY);
91                updatePosition();
92                orxout() << "Left" << endl;
93            }
94            if (moveRightPressed_ == true)
95            {
96                selectedPos_->Set(selecterPosX + 1, selecterPosY);
97                updatePosition();
98                orxout() << "Right" << endl;
99            }
100
101            /*
102            if (firePressed_ && timeSinceLastFire_ >= maxFireRate_)
103            {
104                firePressed_ = false;
105                timeSinceLastFire_ = 0.0;
106            }
107            */
108        }
109
110        // Reset key variables
111        moveUpPressed_ = false;
112        moveDownPressed_ = false;
113        moveLeftPressed_ = false;
114        moveRightPressed_ = false;
115        //firePressed_ = false;
116    }
117
118
119    void TowerDefenseSelecter::moveFrontBack(const Vector2& value)
120    {
121        if (value.x > 0)
122        {
123            moveUpPressed_ = true;
124            moveDownPressed_ = false;
125        }
126        else
127        {
128            moveUpPressed_ = false;
129            moveDownPressed_ = true;
130        }
131    }
132
133    void TowerDefenseSelecter::moveRightLeft(const Vector2& value)
134    {
135        if (value.x > 0)
136        {
137            moveLeftPressed_ = false;
138            moveRightPressed_ = true;
139        }
140        else
141        {
142            moveLeftPressed_ = true;
143            moveRightPressed_ = false;
144        }
145    }
146
147    void TowerDefenseSelecter::rotateYaw(const Vector2& value)
148    {
149    }
150
151    void TowerDefenseSelecter::rotatePitch(const Vector2& value)
152    {
153    }
154
155    void TowerDefenseSelecter::rotateRoll(const Vector2& value)
156    {
157    }
158
159    void TowerDefenseSelecter::fire(unsigned int firemode)
160    {
161    }
162
163    void TowerDefenseSelecter::fired(unsigned int firemode)
164    {
165        //firePressed_ = true;
166    }
167
168    void TowerDefenseSelecter::updatePosition()
169    {
170        setPosition(selectedPos_->get3dcoordinate());
171    }
172
173    void TowerDefenseSelecter::setSelectedPosition(TDCoordinate* newPos)
174    {
175        selectedPos_ = newPos;
176        updatePosition();
177    }
178
179    void TowerDefenseSelecter::setSelectedPosition(int x,  int y)
180    {
181        setSelectedPosition(new TDCoordinate(x,y));
182    }
183
184
185}
Note: See TracBrowser for help on using the repository browser.