| 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 | *      Manuel Meier | 
|---|
| 24 | *   Co-authors: | 
|---|
| 25 | *      ... | 
|---|
| 26 | * | 
|---|
| 27 | */ | 
|---|
| 28 |  | 
|---|
| 29 | /** | 
|---|
| 30 | @file OrxoKartFlag.cc | 
|---|
| 31 | @brief The Flags that are being set in the OrxoKart Minigame They support two coordinates from 0-9 each | 
|---|
| 32 | */ | 
|---|
| 33 |  | 
|---|
| 34 | #include "OrxoKartFlag.h" | 
|---|
| 35 | #include "OrxoKartKart.h" | 
|---|
| 36 |  | 
|---|
| 37 | #include "core/CoreIncludes.h" | 
|---|
| 38 |  | 
|---|
| 39 | #include "graphics/Model.h" | 
|---|
| 40 | #include "objects/collisionshapes/BoxCollisionShape.h" | 
|---|
| 41 | #include "core/XMLPort.h" | 
|---|
| 42 |  | 
|---|
| 43 | namespace orxonox | 
|---|
| 44 | { | 
|---|
| 45 | RegisterClass(OrxoKartFlag); | 
|---|
| 46 |  | 
|---|
| 47 | OrxoKartFlag::OrxoKartFlag(Context* context) : StaticEntity(context) | 
|---|
| 48 | { | 
|---|
| 49 | RegisterObject(OrxoKartFlag); | 
|---|
| 50 |  | 
|---|
| 51 | this->model_ = nullptr; | 
|---|
| 52 | this->cs_ = nullptr; | 
|---|
| 53 | this->collided_ = false; | 
|---|
| 54 | this->kartCollider = nullptr; | 
|---|
| 55 |  | 
|---|
| 56 | this->enableCollisionCallback(); | 
|---|
| 57 | this->setCollisionResponse(true); | 
|---|
| 58 | this->setCollisionType(CollisionType::Static); | 
|---|
| 59 | } | 
|---|
| 60 |  | 
|---|
| 61 | /** | 
|---|
| 62 | @brief | 
|---|
| 63 | Destructor. | 
|---|
| 64 | */ | 
|---|
| 65 | OrxoKartFlag::~OrxoKartFlag() | 
|---|
| 66 | { | 
|---|
| 67 | if (this->isInitialized()) | 
|---|
| 68 | { | 
|---|
| 69 | if (this->model_) | 
|---|
| 70 | this->model_->destroy(); | 
|---|
| 71 | if (this->cs_) | 
|---|
| 72 | this->cs_->destroy(); | 
|---|
| 73 | } | 
|---|
| 74 | } | 
|---|
| 75 |  | 
|---|
| 76 | /** | 
|---|
| 77 | @brief | 
|---|
| 78 | Initializes the flag. | 
|---|
| 79 | @param xCoordinate | 
|---|
| 80 | X-Coordinate of the flage, 0-9, origin is bottom left | 
|---|
| 81 | @param yCoordinate | 
|---|
| 82 | Y-Coordinate of the flage, 0-9, origin is bottom left | 
|---|
| 83 | @param cellSize | 
|---|
| 84 | The size of the cells | 
|---|
| 85 | */ | 
|---|
| 86 | void OrxoKartFlag::init(int n, int s) | 
|---|
| 87 | { | 
|---|
| 88 |  | 
|---|
| 89 | cs_ = new BoxCollisionShape(this->getContext()); | 
|---|
| 90 | cs_->setHalfExtents(Vector3(s*n, 1, s*n)); | 
|---|
| 91 | cs_->setPosition(Vector3(s*n*0.5f,-60.0f, s*n*0.5f)); | 
|---|
| 92 |  | 
|---|
| 93 | this->attachCollisionShape(cs_); | 
|---|
| 94 |  | 
|---|
| 95 |  | 
|---|
| 96 | } | 
|---|
| 97 |  | 
|---|
| 98 | /** | 
|---|
| 99 | @brief | 
|---|
| 100 | Checks if the OrxoKartship collided with the flag | 
|---|
| 101 | */ | 
|---|
| 102 | bool OrxoKartFlag::collidesAgainst(WorldEntity* otherObject, const btCollisionShape* ownCollisionShape, btManifoldPoint& contactPoint) | 
|---|
| 103 | { | 
|---|
| 104 | if(otherObject->isA(Class(OrxoKartKart))) { | 
|---|
| 105 | collided_ = true; | 
|---|
| 106 | kartCollider = (OrxoKartKart*) otherObject; | 
|---|
| 107 | } | 
|---|
| 108 |  | 
|---|
| 109 | return false; | 
|---|
| 110 | } | 
|---|
| 111 | } | 
|---|