Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

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

Last change on this file since 11723 was 11416, checked in by jkindle, 8 years ago

Added the animation for the level end (walk into castle), Coins for the blocks, Castleblocks and Flagblocks

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