Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

source: code/branches/mergeFS18/src/modules/superorxobros/SOBQBlock.cc @ 12031

Last change on this file since 12031 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
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        float collDisZ_ = getPosition().z - contactPoint.getPositionWorldOnB().getZ();
67        if (!used_ && v_z > 50.0 && collDisZ_ > 0) {
68            used_ = true;
69
70            for (WorldEntity* object : this->getAttachedObjects())
71                object->setVisible(!object->isVisible());           
72
73            SOB* SOBGame = orxonox_cast<SOB*>(getGametype());
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
77            if (type_ == "Coin") {
78                SOBGame->addCoin();
79                spawnCoin();
80            }
81            if (type_ == "Mushroom") {
82                spawnMushroom();
83            }
84
85        }
86        return true;
87    }
88
89
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
99     //The spawnmethods from above
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");
110            mush->setPosition(spawnpos);
111           
112        }
113     }
114
115          void SOBQBlock::spawnCoin() {
116        SOBCenterpoint* center_ = ((SOB*)getGametype())->center_;
117
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");
125            mush->setPosition(spawnpos);
126       
127        }
128     }
129
130
131}
Note: See TracBrowser for help on using the repository browser.