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 A Boss Gumba, which shoots small Gumbas |
---|
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; // time after which a Gumba is shot |
---|
57 | gumbaTime_ = 0; // time since last gumba was shot |
---|
58 | maxGumbas_ = 50; // Max Gumbas spawnable by a Boss |
---|
59 | jumpTimeMax_ = 5; // time after which the gumba boss jumps |
---|
60 | jumpTime_ = 0; // time since last jump of gumba boss |
---|
61 | |
---|
62 | } |
---|
63 | |
---|
64 | // PRE: otherObject collides with this. |
---|
65 | // POST: collision is handled: velocity changed, small gumbas murdered |
---|
66 | bool SOBGumbaBoss::collidesAgainst(WorldEntity* otherObject, const btCollisionShape* ownCollisionShape, btManifoldPoint& contactPoint) { |
---|
67 | |
---|
68 | SOBGumba* gumba = orxonox_cast<SOBGumba*>(otherObject); |
---|
69 | SOBGumbaBoss* gumbaBoss = orxonox_cast<SOBGumbaBoss*>(otherObject); |
---|
70 | |
---|
71 | // if boss collides with small gumbas, destroy them. |
---|
72 | if (gumba != nullptr && gumbaBoss == nullptr && !(gumba->hasCollided_)) { |
---|
73 | gumba->die(); |
---|
74 | } |
---|
75 | |
---|
76 | |
---|
77 | //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. |
---|
78 | else if (changeAllowed_ && otherObject->getMass() != -1) { |
---|
79 | goesRight_ = !goesRight_; |
---|
80 | changeAllowed_ = false; |
---|
81 | } |
---|
82 | |
---|
83 | return true; |
---|
84 | } |
---|
85 | |
---|
86 | |
---|
87 | |
---|
88 | // POST: done what was to do in a time dt |
---|
89 | void SOBGumbaBoss::tick(float dt) |
---|
90 | { |
---|
91 | SUPER(SOBGumbaBoss, tick, dt); |
---|
92 | |
---|
93 | // increase timers: |
---|
94 | gumbaTime_ += dt; |
---|
95 | jumpTime_ += dt; |
---|
96 | |
---|
97 | // set y-component of position of gumba boss to 0, so he doesn't fall in to the nothing |
---|
98 | Vector3 position = getPosition(); |
---|
99 | position.y = 0; |
---|
100 | setPosition(position); |
---|
101 | |
---|
102 | |
---|
103 | if (!changeAllowed_) { |
---|
104 | changedOn_+= dt; |
---|
105 | // After a collision, we don't listen for collisions for 200ms - that's because one wall can cause several collisions! |
---|
106 | if (changedOn_> 0.200) { |
---|
107 | changeAllowed_ = true; |
---|
108 | changedOn_ = 0.0; |
---|
109 | |
---|
110 | } |
---|
111 | } |
---|
112 | |
---|
113 | |
---|
114 | if(gumbaTime_ > gumbaMaxTime_){ //Spawn Gumba |
---|
115 | int gumbaCounter=0; |
---|
116 | |
---|
117 | for (SOBGumba* gumbaInstance : ObjectList<SOBGumba>()) |
---|
118 | { |
---|
119 | if (gumbaInstance != nullptr && gumbaInstance->creator_==this) |
---|
120 | { |
---|
121 | gumbaCounter++; |
---|
122 | } |
---|
123 | } |
---|
124 | |
---|
125 | |
---|
126 | if(gumbaCounter<maxGumbas_){ //only maxGumbas are allowed at one time per Gumbaboss |
---|
127 | spawnGumba(); |
---|
128 | gumbaTime_ = 0; |
---|
129 | } |
---|
130 | } |
---|
131 | |
---|
132 | int dir = 1; |
---|
133 | if (!goesRight_) |
---|
134 | dir = -1; |
---|
135 | |
---|
136 | // |
---|
137 | if(getPosition().x < 1640) |
---|
138 | dir = 1; |
---|
139 | else if (getPosition().x > 1750) |
---|
140 | dir = -1; |
---|
141 | |
---|
142 | //change velocity |
---|
143 | Vector3 velocity = getVelocity(); |
---|
144 | if(jumpTime_ > jumpTimeMax_){ // jump if the time has come. |
---|
145 | velocity.z = speed_*15; |
---|
146 | jumpTime_ = 0; |
---|
147 | } |
---|
148 | else{ |
---|
149 | velocity.z -= gravityAcceleration_*dt; |
---|
150 | } |
---|
151 | velocity.x = dir*speed_; |
---|
152 | setVelocity(velocity); |
---|
153 | |
---|
154 | } |
---|
155 | |
---|
156 | // spawn gumbas |
---|
157 | void SOBGumbaBoss::spawnGumba() { |
---|
158 | SOBCenterpoint* center_ = ((SOB*)getGametype())->center_; |
---|
159 | |
---|
160 | SOBGumba* gumba = new SOBGumba(center_->getContext()); |
---|
161 | Vector3 spawnpos = this->getWorldPosition(); |
---|
162 | gumba->creator_=this; |
---|
163 | |
---|
164 | // we can shoot a gumba! |
---|
165 | if (gumba != nullptr && center_ != nullptr) |
---|
166 | { |
---|
167 | gumba->addTemplate("gumbaShootable"); |
---|
168 | gumba->setDirection(goesRight_); |
---|
169 | if(goesRight_) |
---|
170 | { |
---|
171 | spawnpos.x+=20; |
---|
172 | } |
---|
173 | else |
---|
174 | { |
---|
175 | spawnpos.x-=20; |
---|
176 | } |
---|
177 | spawnpos.z+=15; |
---|
178 | gumba->setPosition(spawnpos); |
---|
179 | |
---|
180 | } |
---|
181 | |
---|
182 | Vector3 velocity = gumba->getVelocity(); |
---|
183 | velocity.x += (2*goesRight_ -1) * 100; |
---|
184 | velocity.z += 200; |
---|
185 | gumba->setVelocity(velocity); |
---|
186 | } |
---|
187 | } |
---|