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 | * ... |
---|
24 | * Co-authors: |
---|
25 | * ... |
---|
26 | * |
---|
27 | */ |
---|
28 | |
---|
29 | /** |
---|
30 | @file TetrisStone.cc |
---|
31 | @brief Implementation of the TetrisStone class. |
---|
32 | */ |
---|
33 | |
---|
34 | #include "TetrisStone.h" |
---|
35 | |
---|
36 | #include "core/CoreIncludes.h" |
---|
37 | #include "core/XMLPort.h" |
---|
38 | |
---|
39 | #include "Tetris.h" |
---|
40 | |
---|
41 | namespace orxonox |
---|
42 | { |
---|
43 | CreateFactory(TetrisStone); |
---|
44 | |
---|
45 | /** |
---|
46 | @brief |
---|
47 | Constructor. Registers and initializes the object. |
---|
48 | */ |
---|
49 | TetrisStone::TetrisStone(BaseObject* creator) : Pawn(creator) |
---|
50 | { |
---|
51 | RegisterObject(TetrisStone); |
---|
52 | |
---|
53 | this->size_ = 10.0f; |
---|
54 | this->delay_ = false; |
---|
55 | this->delayTimer_.setTimer(0.2f, false, createExecutor(createFunctor(&TetrisStone::enableMovement, this))); |
---|
56 | this->lockRotation_ = false; |
---|
57 | |
---|
58 | } |
---|
59 | |
---|
60 | /** |
---|
61 | @brief |
---|
62 | Overloaded the function to rotate the stone. |
---|
63 | @param value |
---|
64 | A vector whose first component is the angle by which to rotate. |
---|
65 | */ |
---|
66 | void TetrisStone::moveFrontBack(const Vector2& value) |
---|
67 | { |
---|
68 | if(value.x < 0) //speedup on key down |
---|
69 | { |
---|
70 | this->setVelocity(this->getVelocity()*1.1); |
---|
71 | } |
---|
72 | else if(!this->lockRotation_) //rotate when key up is pressed |
---|
73 | { |
---|
74 | this->lockRotation_ = true; // multiple calls of this function have to be filtered out. |
---|
75 | this->rotationTimer_.setTimer(0.1f, false, createExecutor(createFunctor(&TetrisStone::unlockRotation, this))); |
---|
76 | Quaternion q(Degree(90), Vector3::UNIT_Z); |
---|
77 | this->setOrientation(this->getOrientation()*q); //rotation: roll 90° |
---|
78 | |
---|
79 | } |
---|
80 | } |
---|
81 | |
---|
82 | /** |
---|
83 | @brief |
---|
84 | Overloaded the function to steer the stone right and left |
---|
85 | @param value |
---|
86 | A vector whose first component is the direction in which we want to steer the stone. |
---|
87 | */ |
---|
88 | void TetrisStone::moveRightLeft(const Vector2& value) |
---|
89 | { |
---|
90 | if(!this->delay_) |
---|
91 | { |
---|
92 | const Vector3& position = this->getPosition(); |
---|
93 | Vector3 newPos = Vector3(position.x+value.x/abs(value.x)*this->size_, position.y, position.z); |
---|
94 | if(!this->tetris_->isValidMove(this, newPos)) |
---|
95 | return; |
---|
96 | |
---|
97 | this->setPosition(newPos); |
---|
98 | this->delay_ = true; |
---|
99 | this->delayTimer_.startTimer(); |
---|
100 | } |
---|
101 | } |
---|
102 | |
---|
103 | /** |
---|
104 | @brief |
---|
105 | Is called when the player changed. |
---|
106 | */ |
---|
107 | void TetrisStone::changedPlayer() |
---|
108 | { |
---|
109 | this->setVelocity(0, 0, 0); |
---|
110 | } |
---|
111 | } |
---|