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 | * Noah Zarro |
---|
24 | * Theo von Arx |
---|
25 | * Co-authors: |
---|
26 | * |
---|
27 | * |
---|
28 | */ |
---|
29 | |
---|
30 | /** |
---|
31 | @file SOBGumbaBoss.cc |
---|
32 | @brief All items in this minigame inherit from this class. Items can move around like platforms and enemies. |
---|
33 | */ |
---|
34 | |
---|
35 | #include "SOB.h" |
---|
36 | #include "SOBGumba.h" |
---|
37 | #include "SOBGumbaBoss.h" |
---|
38 | #include "SOBFireball.h" |
---|
39 | #include "SOBFigure.h" |
---|
40 | |
---|
41 | #include "core/CoreIncludes.h" |
---|
42 | #include "core/XMLPort.h" |
---|
43 | #include "util/Output.h" |
---|
44 | #include <BulletCollision/NarrowPhaseCollision/btManifoldPoint.h> |
---|
45 | |
---|
46 | |
---|
47 | |
---|
48 | namespace orxonox |
---|
49 | { |
---|
50 | RegisterClass(SOBGumbaBoss); |
---|
51 | |
---|
52 | SOBGumbaBoss::SOBGumbaBoss(Context* context) : SOBGumba(context) |
---|
53 | { |
---|
54 | RegisterObject(SOBGumbaBoss); |
---|
55 | |
---|
56 | gumbaMaxTime_ = 1; |
---|
57 | gumbaTime_ = 0; |
---|
58 | maxGumbas = 2; //Max Gumbas spawnable by a Boss |
---|
59 | |
---|
60 | } |
---|
61 | |
---|
62 | |
---|
63 | bool SOBGumbaBoss::collidesAgainst(WorldEntity* otherObject, const btCollisionShape* ownCollisionShape, btManifoldPoint& contactPoint) { |
---|
64 | |
---|
65 | //Every object with mass -1 does not change the direction of the GumbaBoss. For example the ground floor! The other objects switch the direction of the GumbaBoss. |
---|
66 | if (changeAllowed_ && otherObject->getMass() != -1) { |
---|
67 | goesRight_ = !goesRight_; |
---|
68 | changeAllowed_ = false; |
---|
69 | } |
---|
70 | |
---|
71 | return true; |
---|
72 | } |
---|
73 | |
---|
74 | |
---|
75 | |
---|
76 | |
---|
77 | void SOBGumbaBoss::tick(float dt) |
---|
78 | { |
---|
79 | SUPER(SOBGumbaBoss, tick, dt); |
---|
80 | |
---|
81 | if (!changeAllowed_) { |
---|
82 | changedOn_+= dt; |
---|
83 | // After a collision, we don't listen for collisions for 200ms - that's because one wall can cause several collisions! |
---|
84 | if (changedOn_> 0.200) { |
---|
85 | changeAllowed_ = true; |
---|
86 | changedOn_ = 0.0; |
---|
87 | |
---|
88 | } |
---|
89 | } |
---|
90 | |
---|
91 | gumbaTime_ += dt; |
---|
92 | |
---|
93 | if(gumbaTime_ > gumbaMaxTime_){ //Spawn Gumba |
---|
94 | int gumbaCounter=0; |
---|
95 | |
---|
96 | for (SOBGumba* gumbaInstance : ObjectList<SOBGumba>()) |
---|
97 | { |
---|
98 | if (gumbaInstance != nullptr && gumbaInstance->creator_==this) |
---|
99 | { |
---|
100 | gumbaCounter++; |
---|
101 | } |
---|
102 | } |
---|
103 | |
---|
104 | |
---|
105 | if(gumbaCounter<maxGumbas){ |
---|
106 | spawnGumba(); |
---|
107 | gumbaTime_ = 0; |
---|
108 | } |
---|
109 | } |
---|
110 | |
---|
111 | int dir = 1; |
---|
112 | if (!goesRight_) |
---|
113 | dir = -1; |
---|
114 | |
---|
115 | Vector3 velocity = getVelocity(); |
---|
116 | velocity.z -= gravityAcceleration_*dt; |
---|
117 | velocity.x = dir*speed_; |
---|
118 | setVelocity(velocity); |
---|
119 | |
---|
120 | lastPos_ = getPosition(); |
---|
121 | |
---|
122 | } |
---|
123 | void SOBGumbaBoss::spawnGumba() { |
---|
124 | SOBCenterpoint* center_ = ((SOB*)getGametype())->center_; |
---|
125 | |
---|
126 | SOBGumba* gumba = new SOBGumba(center_->getContext()); |
---|
127 | Vector3 spawnpos = this->getWorldPosition(); |
---|
128 | spawnpos.z += 0; |
---|
129 | gumba->creator_=this; |
---|
130 | |
---|
131 | if (gumba != nullptr && center_ != nullptr) |
---|
132 | { |
---|
133 | gumba->addTemplate("gumbaShootable"); |
---|
134 | bool direction = ((this->getWorldOrientation().getRoll().valueRadians())>-1.6&&(this->getWorldOrientation().getRoll().valueRadians()<1.6)); |
---|
135 | gumba->setDirection(direction); |
---|
136 | if(direction) |
---|
137 | { |
---|
138 | spawnpos.x+=20; |
---|
139 | } |
---|
140 | else |
---|
141 | { |
---|
142 | spawnpos.x-=20; |
---|
143 | } |
---|
144 | spawnpos.z+=15; |
---|
145 | gumba->setPosition(spawnpos); |
---|
146 | |
---|
147 | } |
---|
148 | |
---|
149 | Vector3 velocity = gumba->getVelocity(); |
---|
150 | velocity.z -= 100; |
---|
151 | gumba->setVelocity(velocity); |
---|
152 | } |
---|
153 | } |
---|