Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

source: code/branches/SOBv2_HS17/src/modules/superorxobros/SOBQBlock.cc @ 11591

Last change on this file since 11591 was 11591, checked in by varxth, 6 years ago

Fix in QBlock

File size: 3.8 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 *      Julien Kindle
24 *   Co-authors:
25 *     
26 *
27 */
28
29/**
30    @file SOBQBlock.cc
31    @brief If this QBlock is created, attachedToFigure_ is set to false. When the figure picks it up, the variable is set to true and the figure starts flying fast until the fuel is reduced to zero.
32*/
33
34#include "SOBQBlock.h"
35
36#include "core/CoreIncludes.h"
37#include "core/XMLPort.h"
38#include "SOB.h"
39#include "SOBMushroom.h"
40#include "SOBCoin.h"
41#include <BulletCollision/NarrowPhaseCollision/btManifoldPoint.h>
42
43
44namespace orxonox
45{
46    RegisterClass(SOBQBlock);
47
48    SOBQBlock::SOBQBlock(Context* context) : SOBItem(context)
49    {
50        RegisterObject(SOBQBlock);
51        used_ = false;
52
53    }
54
55    SOBQBlock::~SOBQBlock()
56    {
57
58    }
59
60   
61    bool SOBQBlock::collidesAgainst(WorldEntity* otherObject, const btCollisionShape* ownCollisionShape, btManifoldPoint& contactPoint) {
62
63
64        //If you hit the QBlock, the visibility of all attached objects get inverted! Pretty easy way to create changing blocks :)
65        float v_z = otherObject->getVelocity().z;
66        int collDisZ_ = getPosition().z - contactPoint.getPositionWorldOnB().getZ();
67        orxout() << "Distanz in z: " << collDisZ_ << endl;
68        if (!used_ && v_z > 50.0 && collDisZ_ > 0) {
69            used_ = true;
70
71            for (WorldEntity* object : this->getAttachedObjects())
72                object->setVisible(!object->isVisible());           
73
74            SOB* SOBGame = orxonox_cast<SOB*>(getGametype());
75
76            //Spawn either a powerup mushroom or a coin animation (also just an object, have a look at the SOBCoin class)
77            //The spawn methods are declared at the bottom of this file
78            if (type_ == "Coin") {
79                SOBGame->addCoin();
80                spawnCoin();
81            }
82            if (type_ == "Mushroom") {
83                spawnMushroom();
84            }
85
86        }
87        return true;
88    }
89
90
91    void SOBQBlock::XMLPort(Element& xmlelement, XMLPort::Mode mode)
92    {
93        SUPER(SOBQBlock, XMLPort, xmlelement, mode);
94        XMLPortParam(SOBQBlock, "type",     setType,     getType,     xmlelement, mode).defaultValues(false);
95
96
97     }
98
99
100     //The spawnmethods from above
101     void SOBQBlock::spawnMushroom() {
102        SOBCenterpoint* center_ = ((SOB*)getGametype())->center_;
103
104         SOBMushroom* mush = new SOBMushroom(center_->getContext());
105         Vector3 spawnpos = this->getWorldPosition();
106         spawnpos.z += 0;
107
108        if (mush != nullptr && center_ != nullptr)
109        {
110            mush->addTemplate("mushroom");
111            mush->setPosition(spawnpos);
112           
113        }
114     }
115
116          void SOBQBlock::spawnCoin() {
117        SOBCenterpoint* center_ = ((SOB*)getGametype())->center_;
118
119         SOBCoin* mush = new SOBCoin(center_->getContext());
120         Vector3 spawnpos = this->getWorldPosition();
121         spawnpos.z += 0;
122
123        if (mush != nullptr && center_ != nullptr)
124        {
125            mush->addTemplate("coin");
126            mush->setPosition(spawnpos);
127       
128        }
129     }
130
131
132}
Note: See TracBrowser for help on using the repository browser.