Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

source: code/trunk/src/modules/superorxobros/SOBQBlock.cc @ 12378

Last change on this file since 12378 was 11783, checked in by landauf, 7 years ago

merged Presentation_HS17_merge back to trunk

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