Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

source: code/branches/mergeFS18/src/modules/tetris/TetrisStone.cc @ 12394

Last change on this file since 12394 was 11083, checked in by muemart, 9 years ago

Fix some clang-tidy warnings.
Also, Serialise.h was doing some C-style casts that ended up being const casts. I moved those const casts as close to the source as possible and changed the loadAndIncrease functions to not do that.

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