1 | #include "dxstdafx.h"
|
---|
2 | #include "GameScene.h"
|
---|
3 | #include "Player.h"
|
---|
4 | #include "UserPlayer.h"
|
---|
5 | #include "AIPlayer.h"
|
---|
6 | #include "SimpleWeapon.h"
|
---|
7 | #include "SimpleBullet.h"
|
---|
8 | #include "Bullet.h"
|
---|
9 | #include "Weapon.h"
|
---|
10 | #include "Terrain.h"
|
---|
11 | #include "HUD.h"
|
---|
12 | #include "Ocean.h"
|
---|
13 | #include "SkyBox.h"
|
---|
14 | #include "GameSceneLoader.h"
|
---|
15 | #include "Goodie.h"
|
---|
16 | #include "UniversalWeapon.h"
|
---|
17 | #include "SoundNode.h"
|
---|
18 | #include <cstdlib>
|
---|
19 | #include <ctime>
|
---|
20 | #include <typeinfo>
|
---|
21 | #include <string>
|
---|
22 |
|
---|
23 | #define M_PI 3.1415
|
---|
24 |
|
---|
25 | extern bool GLOBAL_player_freezeQ;
|
---|
26 |
|
---|
27 | GameScene::GameScene(void) : Scene()
|
---|
28 | {
|
---|
29 | srand( (unsigned)time( NULL ) );
|
---|
30 | this->terrain = 0;
|
---|
31 | this->ocean = 0;
|
---|
32 | this->skybox = 0;
|
---|
33 | this->bgSoundChannel = -1;
|
---|
34 | this->cameraFixedCount = 0;
|
---|
35 | this->flyCamEnabled = false;
|
---|
36 |
|
---|
37 | this->sadSound = NULL;
|
---|
38 |
|
---|
39 | this->happySound = NULL;
|
---|
40 |
|
---|
41 | this->alreadyUsed = false;
|
---|
42 | this->aiPlayerFireEnable = true;
|
---|
43 | this->showFPS = false;
|
---|
44 |
|
---|
45 | this->maxEnemyCount = 1;
|
---|
46 |
|
---|
47 | this->recalcTransformations = true;
|
---|
48 |
|
---|
49 | this->currentlypaused = false;
|
---|
50 | this->preparepaused = false;
|
---|
51 |
|
---|
52 | this->ignoreKeys = false;
|
---|
53 | }
|
---|
54 |
|
---|
55 | GameScene::~GameScene(void)
|
---|
56 | {
|
---|
57 | //this->clearScene();
|
---|
58 | /*if(this->defaultRenderTarget) {
|
---|
59 | delete this->defaultRenderTarget;
|
---|
60 | this->defaultRenderTarget = NULL;
|
---|
61 | }*/
|
---|
62 | }
|
---|
63 |
|
---|
64 | void GameScene::clearScene()
|
---|
65 | {
|
---|
66 | //this->fetchPhysicResults();
|
---|
67 |
|
---|
68 |
|
---|
69 | this->terrain = 0;
|
---|
70 | this->ocean = 0;
|
---|
71 | this->skybox = 0;
|
---|
72 | this->bgSoundChannel = -1;
|
---|
73 | this->cameraFixedCount = 0;
|
---|
74 | this->flyCamEnabled = false;
|
---|
75 | this->firstFrame = true;
|
---|
76 |
|
---|
77 | /*if(this->happySound) {
|
---|
78 | this->happySound->killMe();
|
---|
79 | this->happySound=NULL;
|
---|
80 | }
|
---|
81 | if(this->sadSound) {
|
---|
82 | this->sadSound->killMe();
|
---|
83 | this->sadSound=NULL;
|
---|
84 | }*/
|
---|
85 |
|
---|
86 |
|
---|
87 | //Game cleanup
|
---|
88 |
|
---|
89 | /*std::list<SPTR<Node> >::iterator it;
|
---|
90 | Player* p;
|
---|
91 | exception e;
|
---|
92 | for(it=this->playerList.begin();it!=this->playerList.end();it++) {
|
---|
93 | p = (Player*) (*it).get();
|
---|
94 | if(p) {
|
---|
95 | try {
|
---|
96 | if(p->upperSpringActor) {
|
---|
97 | this->pScene->releaseActor(*p->upperSpringActor);
|
---|
98 | this->pScene->releaseJoint(*p->upperJoint);
|
---|
99 | p->upperJoint = NULL;
|
---|
100 | p->upperSpringActor = NULL;
|
---|
101 | }
|
---|
102 | } catch(exception e) {
|
---|
103 | }
|
---|
104 | }
|
---|
105 | }*/
|
---|
106 |
|
---|
107 | this->cleanUpScene();
|
---|
108 |
|
---|
109 | playerList.clear();
|
---|
110 | goodieList.clear();
|
---|
111 | bulletList.clear();
|
---|
112 | materialXMLVector.clear();
|
---|
113 | materialPhysicVector.clear();
|
---|
114 | refWeaponVector.clear(); //List of all Weapons
|
---|
115 | refBulletVector.clear();
|
---|
116 | this->cameraFixedCount = 0;
|
---|
117 | this->sadSound = NULL;
|
---|
118 | this->happySound = NULL;
|
---|
119 | this->currentlypaused = false;
|
---|
120 | this->preparepaused = false;
|
---|
121 |
|
---|
122 | Scene::clearScene();
|
---|
123 |
|
---|
124 | }
|
---|
125 |
|
---|
126 | void GameScene::initScene(GameManager &_manager) {
|
---|
127 | this->ignoreKeys = false;
|
---|
128 | this->resultVisible = false;
|
---|
129 | this->won = false;
|
---|
130 | this->recalcTransformations = true;
|
---|
131 | this->resultShowingTimer = 0;
|
---|
132 | this->setContactReport(&this->userContactReport);
|
---|
133 | this->setTriggerReport(&this->userTriggerReport);
|
---|
134 | this->setNotifyReport(&this->userNotify);
|
---|
135 | this->descSet = false;
|
---|
136 | this->currentlypaused = false;
|
---|
137 | this->preparepaused = false;
|
---|
138 |
|
---|
139 | GLOBAL_player_freezeQ = false;
|
---|
140 |
|
---|
141 | Scene::initScene(_manager);
|
---|
142 |
|
---|
143 | //Define ColDetGroups
|
---|
144 |
|
---|
145 | //Terrain Stuff
|
---|
146 | this->pScene->setActorGroupPairFlags(UserContactReport::COLGROUP_TERRAIN, UserContactReport::COLGROUP_TERRAIN, NX_IGNORE_PAIR);
|
---|
147 | //this->pScene->setActorGroupPairFlags(UserContactReport::COLGROUP_TERRAIN, UserContactReport::COLGROUP_PLAYER, NX_IGNORE_PAIR);
|
---|
148 | this->pScene->setActorGroupPairFlags(UserContactReport::COLGROUP_TERRAIN, UserContactReport::COLGROUP_BULLET, NX_NOTIFY_ON_START_TOUCH);
|
---|
149 | this->pScene->setActorGroupPairFlags(UserContactReport::COLGROUP_TERRAIN, UserContactReport::COLGROUP_GOODIE, NX_IGNORE_PAIR);
|
---|
150 | this->pScene->setActorGroupPairFlags(UserContactReport::COLGROUP_TERRAIN, UserContactReport::COLGROUP_OTHER, NX_IGNORE_PAIR);
|
---|
151 |
|
---|
152 | //Bullet Stuff
|
---|
153 | this->pScene->setActorGroupPairFlags(UserContactReport::COLGROUP_BULLET, UserContactReport::COLGROUP_GOODIE, NX_NOTIFY_ON_START_TOUCH);
|
---|
154 | this->pScene->setActorGroupPairFlags(UserContactReport::COLGROUP_BULLET, UserContactReport::COLGROUP_OTHER, NX_NOTIFY_ON_START_TOUCH);
|
---|
155 | this->pScene->setActorGroupPairFlags(UserContactReport::COLGROUP_BULLET, UserContactReport::COLGROUP_OBSTACLE, NX_NOTIFY_ON_START_TOUCH);
|
---|
156 | this->pScene->setActorGroupPairFlags(UserContactReport::COLGROUP_BULLET, UserContactReport::COLGROUP_ONEPLAYER, NX_NOTIFY_ON_START_TOUCH);
|
---|
157 | this->pScene->setActorGroupPairFlags(UserContactReport::COLGROUP_BULLET, UserContactReport::COLGROUP_MOREPLAYER, NX_NOTIFY_ON_START_TOUCH);
|
---|
158 |
|
---|
159 | //Player Stuff
|
---|
160 | this->pScene->setGroupCollisionFlag(UserContactReport::COLGROUP_PLAYER, UserContactReport::COLGROUP_TERRAIN, false);
|
---|
161 | this->pScene->setActorGroupPairFlags(UserContactReport::COLGROUP_PLAYER, UserContactReport::COLGROUP_BULLET, NX_NOTIFY_ON_START_TOUCH);
|
---|
162 | this->pScene->setActorGroupPairFlags(UserContactReport::COLGROUP_PLAYER, UserContactReport::COLGROUP_GOODIE, NX_NOTIFY_ON_START_TOUCH);
|
---|
163 | this->pScene->setActorGroupPairFlags(UserContactReport::COLGROUP_PLAYER, UserContactReport::COLGROUP_PLAYER, NX_NOTIFY_ON_START_TOUCH | NX_NOTIFY_ON_END_TOUCH);
|
---|
164 | this->pScene->setActorGroupPairFlags(UserContactReport::COLGROUP_PLAYER, UserContactReport::COLGROUP_FIRE, NX_NOTIFY_ON_START_TOUCH);
|
---|
165 | this->pScene->setActorGroupPairFlags(UserContactReport::COLGROUP_PLAYER, UserContactReport::COLGROUP_ICE, NX_NOTIFY_ON_START_TOUCH);
|
---|
166 |
|
---|
167 | this->pScene->setGroupCollisionFlag(UserContactReport::COLGROUP_NOSELFCOL, UserContactReport::COLGROUP_NOSELFCOL, false);
|
---|
168 | this->pScene->setGroupCollisionFlag(UserContactReport::COLGROUP_NOCOL, UserContactReport::COLGROUP_NOSELFCOL, false);
|
---|
169 |
|
---|
170 | //Disable flag for noCol group!
|
---|
171 | this->pScene->setActorGroupPairFlags(UserContactReport::COLGROUP_NOCOL, UserContactReport::COLGROUP_TERRAIN, NX_IGNORE_PAIR);
|
---|
172 | this->pScene->setActorGroupPairFlags(UserContactReport::COLGROUP_NOCOL, UserContactReport::COLGROUP_PLAYER, NX_IGNORE_PAIR);
|
---|
173 | this->pScene->setActorGroupPairFlags(UserContactReport::COLGROUP_NOCOL, UserContactReport::COLGROUP_BULLET, NX_IGNORE_PAIR);
|
---|
174 | this->pScene->setActorGroupPairFlags(UserContactReport::COLGROUP_NOCOL, UserContactReport::COLGROUP_GOODIE, NX_IGNORE_PAIR);
|
---|
175 | this->pScene->setActorGroupPairFlags(UserContactReport::COLGROUP_NOCOL, UserContactReport::COLGROUP_OTHER, NX_IGNORE_PAIR);
|
---|
176 | this->pScene->setActorGroupPairFlags(UserContactReport::COLGROUP_NOCOL, UserContactReport::COLGROUP_NOCOL, NX_IGNORE_PAIR);
|
---|
177 |
|
---|
178 | this->pScene->setGroupCollisionFlag(UserContactReport::COLGROUP_NOCOL, UserContactReport::COLGROUP_TERRAIN, false);
|
---|
179 | this->pScene->setGroupCollisionFlag(UserContactReport::COLGROUP_NOCOL, UserContactReport::COLGROUP_PLAYER, false);
|
---|
180 | this->pScene->setGroupCollisionFlag(UserContactReport::COLGROUP_NOCOL, UserContactReport::COLGROUP_BULLET, false);
|
---|
181 | this->pScene->setGroupCollisionFlag(UserContactReport::COLGROUP_NOCOL, UserContactReport::COLGROUP_GOODIE, false);
|
---|
182 | this->pScene->setGroupCollisionFlag(UserContactReport::COLGROUP_NOCOL, UserContactReport::COLGROUP_OTHER, false);
|
---|
183 | this->pScene->setGroupCollisionFlag(UserContactReport::COLGROUP_NOCOL, UserContactReport::COLGROUP_NOCOL, false);
|
---|
184 | this->pScene->setGroupCollisionFlag(UserContactReport::COLGROUP_NOCOL, UserContactReport::COLGROUP_FIRE, false);
|
---|
185 | this->pScene->setGroupCollisionFlag(UserContactReport::COLGROUP_NOCOL, UserContactReport::COLGROUP_ONEPLAYER, false);
|
---|
186 | this->pScene->setGroupCollisionFlag(UserContactReport::COLGROUP_NOCOL, UserContactReport::COLGROUP_MOREPLAYER, false);
|
---|
187 | this->pScene->setGroupCollisionFlag(UserContactReport::COLGROUP_NOCOL, 0, false);
|
---|
188 |
|
---|
189 | //Disable Fire fire collision
|
---|
190 | this->pScene->setGroupCollisionFlag(UserContactReport::COLGROUP_FIRE, UserContactReport::COLGROUP_FIRE, false);
|
---|
191 |
|
---|
192 | if(!this->happySound) {
|
---|
193 | this->happySound = (SoundNode*) this->createNode(Scene::NODE_SOUND);
|
---|
194 | this->happySound->loadFile("./media/sound/win.mp3", false);
|
---|
195 | }
|
---|
196 | if(!this->sadSound) {
|
---|
197 | this->sadSound = (SoundNode*) this->createNode(Scene::NODE_SOUND);
|
---|
198 | this->sadSound->loadFile("./media/sound/lose.mp3", false);
|
---|
199 | }
|
---|
200 | this->cameraFixedCount=0;
|
---|
201 | }
|
---|
202 |
|
---|
203 | void GameScene::renderScene(float fElapsedTime)
|
---|
204 | {
|
---|
205 | if(this->isVisible()) {
|
---|
206 | if(this->device==0) {
|
---|
207 | this->device = DXUTGetD3DDevice();
|
---|
208 | this->physxRenderer.setDevice(*this->device);
|
---|
209 | }
|
---|
210 |
|
---|
211 | if(this->preparepaused) {
|
---|
212 | this->currentlypaused = true;
|
---|
213 | }
|
---|
214 |
|
---|
215 | //this->device->SetRenderTarget(0, this->finalImageSurface);
|
---|
216 | //this->manager->printToConsole("renderScene");
|
---|
217 | //Execute RenderChain
|
---|
218 | /*std::list<void(Scene::*)()>::iterator chainIt;
|
---|
219 | for(chainIt=this->renderChain.begin(); chainIt!=this->renderChain.end(); chainIt++) {
|
---|
220 | (*this.**chainIt)();
|
---|
221 | }*/
|
---|
222 | if(this->firstFrame) {
|
---|
223 | this->playBackgroundSound();
|
---|
224 | }
|
---|
225 |
|
---|
226 | if(!this->currentlypaused) {
|
---|
227 | this->takeTime();
|
---|
228 | }
|
---|
229 |
|
---|
230 | //ClearScreen
|
---|
231 | //this->clearRenderTargetAndZBuffer();
|
---|
232 | //Clear SharedResources
|
---|
233 | this->clearSharedResources();
|
---|
234 | //Fetch Physic Results
|
---|
235 | if(this->recalcTransformations && !this->currentlypaused) {
|
---|
236 | this->fetchPhysicResults();
|
---|
237 | }
|
---|
238 | //Fading Stuff
|
---|
239 | if(!this->currentlypaused) {
|
---|
240 | this->doFade();
|
---|
241 | //FIRST GAME UPDATE
|
---|
242 | this->updateGameFirst();
|
---|
243 | //Trigger updates
|
---|
244 | this->updateTrigger();
|
---|
245 | //Update Nodes
|
---|
246 | this->updateNodes();
|
---|
247 | //Calculate Transformations
|
---|
248 | if(this->recalcTransformations) {
|
---|
249 | this->calculateTransformations();
|
---|
250 | }
|
---|
251 | //SECOND GAME UPDATE
|
---|
252 | this->updateGameSecond();
|
---|
253 | }
|
---|
254 |
|
---|
255 | //startRenderPasses
|
---|
256 | this->startRenderPasses();
|
---|
257 |
|
---|
258 | //Cleanup Memory
|
---|
259 | this->cleanUpScene();
|
---|
260 |
|
---|
261 | if(!this->currentlypaused) {
|
---|
262 | //Start Physic
|
---|
263 | if(this->recalcTransformations) {
|
---|
264 | this->startPhysic();
|
---|
265 | }
|
---|
266 | }
|
---|
267 | this->cnt = 0;
|
---|
268 | this->firstFrame = false;
|
---|
269 | }
|
---|
270 | }
|
---|
271 |
|
---|
272 | void GameScene::cleanUpScene()
|
---|
273 | {
|
---|
274 | std::list<SPTR<Node> >::iterator it;
|
---|
275 | std::list<SPTR<Node> >::iterator nit;
|
---|
276 | std::vector<SPTR<Renderer> >::iterator rit;
|
---|
277 | Node* node;
|
---|
278 | for(it=this->zombieNodeList.begin();it!=this->zombieNodeList.end();it++) {
|
---|
279 | node = (*it).get();
|
---|
280 | node->getFather()->removeChild(*it);
|
---|
281 |
|
---|
282 | //Delete Renderer
|
---|
283 | if(node->hasRenderer())
|
---|
284 | {
|
---|
285 | Renderer *r = node->getRenderer().get();
|
---|
286 | for(rit=this->rendererList.begin();rit!=this->rendererList.end();rit++) {
|
---|
287 | if((*rit).get() == r)
|
---|
288 | {
|
---|
289 | this->rendererList.erase(rit);
|
---|
290 | break;
|
---|
291 | }
|
---|
292 | }
|
---|
293 | }
|
---|
294 |
|
---|
295 | //Delete Physic Actor
|
---|
296 | if(node->getActor()!=NULL)
|
---|
297 | {
|
---|
298 | this->pScene->releaseActor(*node->getActor());
|
---|
299 | }
|
---|
300 |
|
---|
301 | this->deleteNodeInList(node, this->nodeList);
|
---|
302 | this->deleteNodeInList(node, this->particleList);
|
---|
303 | this->deleteNodeInList(node, this->soundNodeList);
|
---|
304 | this->deleteNodeInList(node, this->playerList);
|
---|
305 | this->deleteNodeInList(node, this->goodieList);
|
---|
306 | this->deleteNodeInList(node, this->bulletList);
|
---|
307 | }
|
---|
308 | this->zombieNodeList.clear();
|
---|
309 | }
|
---|
310 |
|
---|
311 | Terrain* GameScene::getTerrain()
|
---|
312 | {
|
---|
313 | return this->terrain;
|
---|
314 | }
|
---|
315 |
|
---|
316 | HUD* GameScene::getHUD()
|
---|
317 | {
|
---|
318 | return this->hud;
|
---|
319 | }
|
---|
320 |
|
---|
321 | Node* GameScene::createNode(int type)
|
---|
322 | {
|
---|
323 | return this->createNode(type, this->root, true, false);
|
---|
324 | }
|
---|
325 |
|
---|
326 | Node* GameScene::createNode(int type, Node &father)
|
---|
327 | {
|
---|
328 | return this->createNode(type, father, true, false);
|
---|
329 | }
|
---|
330 |
|
---|
331 | Node* GameScene::createNode(int type, bool addDefaultRenderer)
|
---|
332 | {
|
---|
333 | return this->createNode(type, this->root, addDefaultRenderer, false);
|
---|
334 | }
|
---|
335 |
|
---|
336 | Node* GameScene::createNode(int type, Node &father, bool addDefaultRenderer) {
|
---|
337 | return this->createNode(type, father, addDefaultRenderer, false);
|
---|
338 | }
|
---|
339 |
|
---|
340 | Node* GameScene::createNode(int type, Node &father, bool addDefaultRenderer, bool isReference)
|
---|
341 | {
|
---|
342 | switch(type) {
|
---|
343 | case NODE_TERRAIN:
|
---|
344 | {
|
---|
345 | SPTR<Node> node(new Terrain);
|
---|
346 | father.addChild(node);
|
---|
347 | this->nodeList.push_back(node);
|
---|
348 | node->setScene(*this);
|
---|
349 | Node *temp = node.get();
|
---|
350 | this->terrain = (Terrain *) temp;
|
---|
351 | return temp;
|
---|
352 | }
|
---|
353 | break;
|
---|
354 | case NODE_OCEAN:
|
---|
355 | {
|
---|
356 | SPTR<Node> node(new Ocean);
|
---|
357 | father.addChild(node);
|
---|
358 | this->nodeList.push_back(node);
|
---|
359 | node->setScene(*this);
|
---|
360 | Node *temp = node.get();
|
---|
361 | this->ocean = (Ocean *) temp;
|
---|
362 | return temp;
|
---|
363 | }
|
---|
364 | break;
|
---|
365 | case NODE_HUD:
|
---|
366 | {
|
---|
367 | SPTR<Node> node(new HUD);
|
---|
368 | father.addChild(node);
|
---|
369 | this->nodeList.push_back(node);
|
---|
370 | node->setScene(*this);
|
---|
371 | Node *temp = node.get();
|
---|
372 | this->hud = (HUD *) temp;
|
---|
373 | return temp;
|
---|
374 | }
|
---|
375 | break;
|
---|
376 | case NODE_SKYBOX:
|
---|
377 | {
|
---|
378 | SPTR<Node> node(new SkyBox);
|
---|
379 | father.addChild(node);
|
---|
380 | this->nodeList.push_back(node);
|
---|
381 | node->setScene(*this);
|
---|
382 | Node *temp = node.get();
|
---|
383 | this->skybox = (SkyBox *) temp;
|
---|
384 | return temp;
|
---|
385 | }
|
---|
386 | break;
|
---|
387 | case NODE_USERPLAYER:
|
---|
388 | {
|
---|
389 | SPTR<Node> node(new UserPlayer);
|
---|
390 | father.addChild(node);
|
---|
391 | this->nodeList.push_back(node);
|
---|
392 | this->playerList.push_back(node);
|
---|
393 | node->setScene(*this);
|
---|
394 | this->player = (UserPlayer *) node.get();
|
---|
395 | return node.get();
|
---|
396 | }
|
---|
397 | break;
|
---|
398 | case NODE_AIPLAYER:
|
---|
399 | {
|
---|
400 | SPTR<Node> node(new AIPlayer);
|
---|
401 | father.addChild(node);
|
---|
402 | this->nodeList.push_back(node);
|
---|
403 | this->playerList.push_back(node);
|
---|
404 | node->setScene(*this);
|
---|
405 | return node.get();
|
---|
406 | }
|
---|
407 | break;
|
---|
408 | case NODE_SIMPLEWEAPON:
|
---|
409 | {
|
---|
410 | SPTR<Node> node(new SimpleWeapon);
|
---|
411 | node->setScene(*this);
|
---|
412 | if(!isReference) {
|
---|
413 | father.addChild(node);
|
---|
414 | this->nodeList.push_back(node);
|
---|
415 | } else {
|
---|
416 | this->refWeaponVector.push_back(node);
|
---|
417 | }
|
---|
418 | return node.get();
|
---|
419 | }
|
---|
420 | break;
|
---|
421 | case NODE_GOODIE:
|
---|
422 | {
|
---|
423 | SPTR<Node> node(new Goodie);
|
---|
424 | node->setScene(*this);
|
---|
425 | //if(!isReference) {
|
---|
426 | father.addChild(node);
|
---|
427 | this->nodeList.push_back(node);
|
---|
428 | /*} else {
|
---|
429 | this->refWeaponList.push_back(node);
|
---|
430 | }*/
|
---|
431 | if(addDefaultRenderer) {
|
---|
432 | SPTR<Renderer> renderer(new SimpleMeshRenderer);
|
---|
433 | renderer->setScene(*this);
|
---|
434 | WPTR<Node> wn(node);
|
---|
435 | renderer->setNode(wn);
|
---|
436 | node->setRenderer(renderer);
|
---|
437 | renderer->init();
|
---|
438 | this->rendererList.push_back(renderer);
|
---|
439 | }
|
---|
440 | return node.get();
|
---|
441 | }
|
---|
442 | break;
|
---|
443 | case NODE_SIMPLEBULLET:
|
---|
444 | {
|
---|
445 | SPTR<Node> node(new SimpleBullet);
|
---|
446 | node->setScene(*this);
|
---|
447 | if(!isReference) {
|
---|
448 | father.addChild(node);
|
---|
449 | this->nodeList.push_back(node);
|
---|
450 | this->bulletList.push_back(node);
|
---|
451 | } else {
|
---|
452 | this->refBulletVector.push_back(node);
|
---|
453 | }
|
---|
454 | return node.get();
|
---|
455 | }
|
---|
456 | break;
|
---|
457 | case NODE_UNIVERSALWEAPON:
|
---|
458 | {
|
---|
459 | SPTR<Node> node(new UniversalWeapon);
|
---|
460 | node->setScene(*this);
|
---|
461 | if(!isReference) {
|
---|
462 | father.addChild(node);
|
---|
463 | this->nodeList.push_back(node);
|
---|
464 | } else {
|
---|
465 | this->refWeaponVector.push_back(node);
|
---|
466 | }
|
---|
467 | return node.get();
|
---|
468 | }
|
---|
469 | break;
|
---|
470 | default:
|
---|
471 | return Scene::createNode(type, father, addDefaultRenderer, isReference);
|
---|
472 | break;
|
---|
473 | }
|
---|
474 | }
|
---|
475 |
|
---|
476 | void GameScene::loadGame(std::string filename)
|
---|
477 | {
|
---|
478 | GameSceneLoader loader;
|
---|
479 | if(!loader.loadGameScene(*this, filename, this->manager)) {//loadGameScene(*this, filename)) {
|
---|
480 | this->manager->printToConsole("Loading failed!");
|
---|
481 |
|
---|
482 | //Initialize rest
|
---|
483 | //TODO Object3d preloading, sound preloading usw.
|
---|
484 | }
|
---|
485 | }
|
---|
486 |
|
---|
487 | /*void GameScene::setMaterialId(int desiredId, int realId) {
|
---|
488 | int ids[2];
|
---|
489 | ids[0] = desiredId;
|
---|
490 | ids[1] = realId;
|
---|
491 | this->desiredToRealMaterialId.push_back(ids);
|
---|
492 | }*/
|
---|
493 |
|
---|
494 |
|
---|
495 | std::list<SPTR<Node> > * GameScene::getPlayerList()
|
---|
496 | {
|
---|
497 | return &this->playerList;
|
---|
498 | }
|
---|
499 |
|
---|
500 |
|
---|
501 | std::list<SPTR<Node> > * GameScene::getGoodieList()
|
---|
502 | {
|
---|
503 | return &this->goodieList;
|
---|
504 | }
|
---|
505 |
|
---|
506 | /*void GameScene::registerHealthPackage(Goodie* hp, float arrivalTime)
|
---|
507 | {
|
---|
508 |
|
---|
509 | this->setTrigger(this->TRIGGER_UNSETSTANDBY, hp, this->getRandomTime(arrivalTime, timeVariation));
|
---|
510 | }
|
---|
511 |
|
---|
512 | void GameScene::registerWeaponPackage(Goodie* wp, float arrivalTime)
|
---|
513 | {
|
---|
514 |
|
---|
515 | }
|
---|
516 |
|
---|
517 | void GameScene::registerBulletPackage(Goodie* mp, float arrivalTime)
|
---|
518 | {
|
---|
519 |
|
---|
520 | }*/
|
---|
521 |
|
---|
522 | float GameScene::getRandomTime(float timeBase, float timeVariation)
|
---|
523 | {
|
---|
524 | return timeBase + ((((float) rand())/RAND_MAX)-0.5f)*timeVariation*2;
|
---|
525 | }
|
---|
526 |
|
---|
527 | void GameScene::executeTrigger(SPTR<Trigger> trigger)
|
---|
528 | {
|
---|
529 | Scene::executeTrigger(trigger);
|
---|
530 |
|
---|
531 | Trigger *t = trigger.get();
|
---|
532 | Node* node;
|
---|
533 | Node* secondNode;
|
---|
534 | Player* tempPlayer;
|
---|
535 | Vector normal;
|
---|
536 | Vector pos;
|
---|
537 |
|
---|
538 | switch(t->getType())
|
---|
539 | {
|
---|
540 | case this->TRIGGER_IMPACTTERRAIN:
|
---|
541 | node = t->getNode().get(); //Bullet
|
---|
542 | normal = t->getNormal();
|
---|
543 | ((Bullet*) node)->impactTerrain(normal);
|
---|
544 | break;
|
---|
545 | case this->TRIGGER_IMPACTPLAYER:
|
---|
546 | node = t->getNode().get(); //Bullet
|
---|
547 | secondNode = t->getSecondNode().get(); //Player
|
---|
548 | normal = t->getNormal();
|
---|
549 | ((Bullet*) node)->impactPlayer((Player*) secondNode, normal);
|
---|
550 | break;
|
---|
551 | case this->TRIGGER_IMPACTGOODIE:
|
---|
552 | node = t->getNode().get();
|
---|
553 | secondNode = t->getSecondNode().get(); //Goodie
|
---|
554 | normal = t->getNormal();
|
---|
555 | ((Bullet*) node)->impactGoodie((Goodie*) secondNode, normal);
|
---|
556 | break;
|
---|
557 | case this->TRIGGER_IMPACTOTHER:
|
---|
558 | node = t->getNode().get();
|
---|
559 | secondNode = t->getSecondNode().get(); //Object3d
|
---|
560 | normal = t->getNormal();
|
---|
561 | ((Bullet*) node)->impactOther((Object3d*) secondNode, normal);
|
---|
562 | break;
|
---|
563 | case this->TRIGGER_GOODIECATCH:
|
---|
564 | {
|
---|
565 | node = t->getNode().get(); //Player
|
---|
566 | secondNode = t->getSecondNode().get(); //Goddie
|
---|
567 | Goodie *goodie = (Goodie*) secondNode;
|
---|
568 | Player *p = (Player*) node;
|
---|
569 | this->manager->printToConsole("General Goodie catch!");
|
---|
570 | switch(goodie->getGoodieType()) {
|
---|
571 | case Goodie::GOODIE_HEALTH:
|
---|
572 | this->manager->printToConsole(" health!");
|
---|
573 | p->addHealth(goodie->getHealthAmount());
|
---|
574 | break;
|
---|
575 | case Goodie::GOODIE_WEAPON:
|
---|
576 | //this->manager->printToConsole("GOODIE_WEAPON adding not yet implemented!");
|
---|
577 | this->manager->printToConsole(" weapon!");
|
---|
578 | if(goodie->getWeaponType()<=3) {
|
---|
579 | SimpleWeapon *weapon = (SimpleWeapon *) this->createNode(this->NODE_SIMPLEWEAPON, *p->schale, true);
|
---|
580 | weapon->setWeaponType(goodie->getWeaponType());
|
---|
581 | weapon->addMunition(goodie->getArmorAmount());
|
---|
582 | weapon->initWeapon();
|
---|
583 | p->addWeapon(*weapon);
|
---|
584 | } else {
|
---|
585 | p->addWeapon(*this->cloneWeaponFromReference(goodie->getWeaponType()));
|
---|
586 | }
|
---|
587 | break;
|
---|
588 | case Goodie::GOODIE_AMO:
|
---|
589 | this->manager->printToConsole(" amo!");
|
---|
590 | p->addMunition(goodie->getWeaponType(), goodie->getArmorAmount());
|
---|
591 | break;
|
---|
592 | }
|
---|
593 | SoundNode* goodiePick = (SoundNode*) this->createNode(GameScene::NODE_SOUND);
|
---|
594 | goodiePick->loadFile("./media/sound/goodiePick.mp3", false);
|
---|
595 | goodiePick->setKillSoundNodeAfterPlayed(true);
|
---|
596 | goodiePick->play();
|
---|
597 | secondNode->killMe();
|
---|
598 | }
|
---|
599 | break;
|
---|
600 | case this->TRIGGER_IMPACTFIRE:
|
---|
601 | node = t->getNode().get();
|
---|
602 | secondNode = t->getSecondNode().get();
|
---|
603 | if(node->userData != secondNode) {
|
---|
604 | Player* p = (Player*) secondNode;
|
---|
605 | p->setHealth(p->getRealHealth() - 0.1f);
|
---|
606 | p->hitByFire();
|
---|
607 | if(p->isToasted()) {
|
---|
608 | this->hud->displayToasted(0.5, 0.01f);
|
---|
609 | }
|
---|
610 | }
|
---|
611 | break;
|
---|
612 | case this->TRIGGER_IMPACTICE:
|
---|
613 | node = t->getNode().get();
|
---|
614 | secondNode = t->getSecondNode().get();
|
---|
615 | if(node->userData != secondNode) {
|
---|
616 | Player* p = (Player*) secondNode;
|
---|
617 | p->setHealth(p->getRealHealth() - 0.05f);
|
---|
618 | p->hitByIce();
|
---|
619 | /*if(p->isToasted()) {
|
---|
620 | this->hud->displayToasted(1.0, 0.01f);
|
---|
621 | }*/
|
---|
622 | }
|
---|
623 | break;
|
---|
624 | case this->TRIGGER_CREATEPLAYER:
|
---|
625 | case this->TRIGGER_CREATEMOREPLAYER:
|
---|
626 | this->manager->printToConsole("Create ONE Player");
|
---|
627 | if(this->gameMode==1) {
|
---|
628 | node = t->getNode().get(); //Create Trigger Object
|
---|
629 | secondNode = t->getSecondNode().get(); //Bullet
|
---|
630 | tempPlayer = ((Bullet*)secondNode)->myPlayer; //Player of bullet
|
---|
631 | //if(tempPlayer == this->player && this->playerList.size()-1 < this->maxEnemyCount) {
|
---|
632 | if(tempPlayer == this->player && int(this->playerList.size())-1 < this->maxEnemyCount) {
|
---|
633 | pos = node->getAbsolutePosition();
|
---|
634 | pos.y++;
|
---|
635 | SimpleWeapon* weapon = NULL;
|
---|
636 | Player* p = (Player*) this->createNode(GameScene::NODE_AIPLAYER);
|
---|
637 | p->setAvatareFileName(this->enemyModel);
|
---|
638 | p->setTeam(this->player->getTeam()+1);
|
---|
639 | p->initPlayer(pos.x, pos.y, pos.z);
|
---|
640 | //Add Standard Weapon
|
---|
641 | weapon = (SimpleWeapon *) this->createNode(this->NODE_SIMPLEWEAPON, *p->schale, true);
|
---|
642 | weapon->setWeaponType(0);
|
---|
643 | weapon->addMunition(1000);
|
---|
644 | weapon->initWeapon();
|
---|
645 | p->addWeapon(*weapon);
|
---|
646 | p->setActiveWeapon(0);
|
---|
647 | if(t->getType()==this->TRIGGER_CREATEPLAYER) {
|
---|
648 | node->killMe();
|
---|
649 | }
|
---|
650 | }
|
---|
651 | secondNode->killMe();
|
---|
652 | }
|
---|
653 | break;
|
---|
654 | }
|
---|
655 | }
|
---|
656 |
|
---|
657 | void GameScene::updateGameFirst()
|
---|
658 | {
|
---|
659 | //this->manager->printToConsole("updateGameFirst");
|
---|
660 | //Send Keys to UserPlayer
|
---|
661 | /*player->accelerate(this->keyDown['W']);
|
---|
662 | player->stop(this->keyDown['S']);
|
---|
663 | player->toLeft(this->keyDown['A']);
|
---|
664 | player->toRight(this->keyDown['D']);*/
|
---|
665 |
|
---|
666 | /*if(this->keyDown['O']) {
|
---|
667 | this->manager->printToConsole("adding upforce!");
|
---|
668 | this->player->addUpForce();
|
---|
669 | }*/
|
---|
670 |
|
---|
671 | if(this->descSet) {
|
---|
672 | this->descSet = false;
|
---|
673 | this->hud->message(this->description, this->descDuration, 0.01f);
|
---|
674 | }
|
---|
675 |
|
---|
676 | //switch to menue scene:
|
---|
677 | if(this->keyDown[VK_ESCAPE]) {
|
---|
678 | this->keyDown[VK_ESCAPE] = false;
|
---|
679 | manager->switchToMenueScene();
|
---|
680 | }
|
---|
681 |
|
---|
682 | //fly around cam:
|
---|
683 |
|
---|
684 | /*if(this->keyDown['F']) {
|
---|
685 | this->flyCamEnabled = true;
|
---|
686 | }
|
---|
687 | if(this->keyDown['G'])
|
---|
688 | this->flyCamEnabled = false;*/
|
---|
689 |
|
---|
690 | //Update Camera
|
---|
691 | int screenWidth = this->manager->screenWidth; //TODO rausnehmen und durch richtigen wert ersetzen
|
---|
692 | int screenHeight = this->manager->screenHeight;
|
---|
693 |
|
---|
694 | /*if(this->flyCamEnabled) {
|
---|
695 | Vector viewPos;
|
---|
696 | Vector lookAtPos;
|
---|
697 | Vector dir;
|
---|
698 | viewPos = this->activeCamera->getAbsolutePosition();
|
---|
699 | lookAtPos = this->activeCamera->getLookAtTarget();
|
---|
700 | dir = lookAtPos - viewPos;
|
---|
701 | dir.normalize();
|
---|
702 | float rX = 0;
|
---|
703 | float rY = 0;
|
---|
704 | float dZ = 0;
|
---|
705 | float dX = 0;
|
---|
706 | float dY = 0;
|
---|
707 |
|
---|
708 | if(this->keyDown[VK_RIGHT]) {
|
---|
709 | rY++;
|
---|
710 | }
|
---|
711 | if(this->keyDown[VK_LEFT]) {
|
---|
712 | rY--;
|
---|
713 | }
|
---|
714 | if(this->keyDown[VK_UP]) {
|
---|
715 | rX++;
|
---|
716 | }
|
---|
717 | if(this->keyDown[VK_DOWN]) {
|
---|
718 | rX--;
|
---|
719 | }
|
---|
720 | if(this->keyDown['W']) {
|
---|
721 | dZ++;
|
---|
722 | }
|
---|
723 | if(this->keyDown['S']) {
|
---|
724 | dZ--;
|
---|
725 | }
|
---|
726 | if(this->keyDown['D']) {
|
---|
727 | dX--;
|
---|
728 | }
|
---|
729 | if(this->keyDown['A']) {
|
---|
730 | dX++;
|
---|
731 | }
|
---|
732 | if(this->keyDown['E']) {
|
---|
733 | dY++;
|
---|
734 | }
|
---|
735 | if(this->keyDown['C']) {
|
---|
736 | dY--;
|
---|
737 | }
|
---|
738 |
|
---|
739 | float rotSpeed = 0.05f;
|
---|
740 | D3DXQUATERNION quat;
|
---|
741 | D3DXMATRIX rotMat;
|
---|
742 | D3DXQuaternionIdentity(&quat);
|
---|
743 | D3DXQuaternionRotationYawPitchRoll(&quat, rY*rotSpeed, rX*rotSpeed, 0);
|
---|
744 | D3DXMatrixRotationQuaternion(&rotMat, &quat);
|
---|
745 | D3DXVec4Transform(&dir, &dir, &rotMat);
|
---|
746 |
|
---|
747 | lookAtPos = viewPos + dir;
|
---|
748 |
|
---|
749 | Vector upVec(0, 1, 0);
|
---|
750 | Vector rightVec;
|
---|
751 | rightVec = dir.crossProd(upVec);
|
---|
752 | float speed = 1;
|
---|
753 | dir = dir*dZ*speed;
|
---|
754 | rightVec = rightVec*dX*speed;
|
---|
755 | upVec = upVec*dY*speed;
|
---|
756 |
|
---|
757 | lookAtPos = lookAtPos+dir+rightVec+upVec;
|
---|
758 | viewPos = viewPos+dir+rightVec+upVec;
|
---|
759 |
|
---|
760 | this->activeCamera->setLookAtTarget(lookAtPos.x, lookAtPos.y, lookAtPos.z);
|
---|
761 | this->activeCamera->setPosition(viewPos.x, viewPos.y, viewPos.z);
|
---|
762 | this->skybox->getBoxObject()->setPosition(viewPos.x, 1, viewPos.z);
|
---|
763 | return;
|
---|
764 | }*/
|
---|
765 |
|
---|
766 | //Update Player instructions
|
---|
767 | if(!ignoreKeys) {
|
---|
768 | if(this->keyDown['W']) player->accelerate();
|
---|
769 | if(this->keyDown['S']) player->stop();
|
---|
770 | if(this->keyDown['A']) player->toLeft();
|
---|
771 | if(this->keyDown['D']) player->toRight();
|
---|
772 | }
|
---|
773 |
|
---|
774 | //Set active Weapons
|
---|
775 | if(this->keyDown['1']) player->setActiveWeapon(0);
|
---|
776 | if(this->keyDown['2']) player->setActiveWeapon(1);
|
---|
777 | if(this->keyDown['3']) player->setActiveWeapon(2);
|
---|
778 | if(this->keyDown['4']) player->setActiveWeapon(3);
|
---|
779 | if(this->keyDown['5']) player->setActiveWeapon(4);
|
---|
780 | if(this->keyDown['6']) player->setActiveWeapon(5);
|
---|
781 | if(this->keyDown['7']) player->setActiveWeapon(6);
|
---|
782 | if(this->keyDown['8']) player->setActiveWeapon(7);
|
---|
783 | if(this->keyDown['9']) player->setActiveWeapon(8);
|
---|
784 |
|
---|
785 | /*std::list<SPTR<Node> >::iterator it;
|
---|
786 | if(this->keyDown['Z']) {
|
---|
787 | for(it = this->playerList.begin(); it!=this->playerList.end();it++) {
|
---|
788 | ((Player*) (*it).get())->switchToPublicPhysic();
|
---|
789 | }
|
---|
790 | }
|
---|
791 | //this->player->switchToPublicPhysic();
|
---|
792 | if(this->keyDown['H']) {
|
---|
793 | for(it = this->playerList.begin(); it!=this->playerList.end();it++) {
|
---|
794 | ((Player*) (*it).get())->switchToPrivatePhysic();
|
---|
795 | }
|
---|
796 | }*/
|
---|
797 | //this->player->switchToPrivatePhysic();
|
---|
798 |
|
---|
799 |
|
---|
800 | /*if(this->keyDown['J']) this->sObj->rotate(0,0,-0.2);
|
---|
801 | if(this->keyDown['L']) this->sObj->rotate(0,0,0.2);
|
---|
802 | if(this->keyDown['I']) this->sObj->rotate(-0.2,0,0);
|
---|
803 | if(this->keyDown['K']) this->sObj->rotate(0.2,0,0);
|
---|
804 | if(this->keyDown['U']) this->sObj->rotate(0,-0.2,0);
|
---|
805 | if(this->keyDown['M']) this->sObj->rotate(0,0.2,0);
|
---|
806 | if(this->keyDown['Y']) this->sObj->translate(0,0,6);
|
---|
807 | if(this->keyDown['X']) this->sObj->translate(0,0,-6);*/
|
---|
808 |
|
---|
809 |
|
---|
810 | if(this->cameraFixedCount>5) {
|
---|
811 | /*char temp[100];
|
---|
812 | sprintf(temp, "1/dt = %f", 1/dt);
|
---|
813 | this->manager->printToConsole(temp);*/
|
---|
814 | int camFactor = 12;
|
---|
815 |
|
---|
816 | Vector diff;
|
---|
817 | D3DXMATRIX mYaw;
|
---|
818 | D3DXMATRIX mXaw;
|
---|
819 | D3DXMATRIX bla;
|
---|
820 |
|
---|
821 | //dLookAtPoint = oldDLookAtPoint;
|
---|
822 | //dViewPoint = oldDViewPoint;
|
---|
823 | dViewPoint = player->getDesiredViewPoint();
|
---|
824 | dLookAtPoint = player->getDesiredLookAtPoint();
|
---|
825 |
|
---|
826 | D3DXMatrixRotationY(&mYaw, (FLOAT)-M_PI/3*(0.5f-((float)this->mousePos[0])/screenWidth)*2);
|
---|
827 |
|
---|
828 | //Yaw berechnen
|
---|
829 | diff = dViewPoint - dLookAtPoint;
|
---|
830 | Vector tDiff;
|
---|
831 |
|
---|
832 | //if (this->flyCamEnabled) {
|
---|
833 | // D3DXVec4Transform(&tDiff, &diff, &bla);
|
---|
834 | //} else {
|
---|
835 | D3DXVec4Transform(&tDiff, &diff, &mYaw);
|
---|
836 | //}
|
---|
837 |
|
---|
838 | dViewPoint = dLookAtPoint + tDiff;
|
---|
839 |
|
---|
840 | //Falls Terrain höher als Cameraposition
|
---|
841 | Vector tempView = dViewPoint;
|
---|
842 | tempView.y += 5;
|
---|
843 | float h= this->getTerrainHeight(tempView);
|
---|
844 | int dHeight = 3;
|
---|
845 | if(h>dViewPoint.y) {
|
---|
846 | dViewPoint.y = h+dHeight;
|
---|
847 | }
|
---|
848 | if(!this->player->gotHit) {
|
---|
849 | lookAtPoint = lookAtPoint + (dLookAtPoint-lookAtPoint)*this->dt*(float)camFactor;
|
---|
850 | viewPoint = viewPoint + (dViewPoint-viewPoint)*this->dt*(float)camFactor;
|
---|
851 | } else {
|
---|
852 | lookAtPoint = lookAtPoint + (dLookAtPoint-lookAtPoint)*this->dt*(float)camFactor;
|
---|
853 | viewPoint = viewPoint + (dViewPoint-viewPoint)*this->dt*(float)camFactor/5;
|
---|
854 | }
|
---|
855 |
|
---|
856 | //Test if ViewPoint eventually collides with objects in scene
|
---|
857 |
|
---|
858 | if(viewPoint.y < h+dHeight/2) {
|
---|
859 | /*if(viewPoint.y-h==0) {
|
---|
860 | h = viewPoint.y-0.5f;
|
---|
861 | }
|
---|
862 | viewPoint.y += (dHeight/2)/(viewPoint.y-h);*/
|
---|
863 | viewPoint.y = dViewPoint.y;
|
---|
864 | }
|
---|
865 | //lookAtPoint.setXYZ(100, 30, 100);
|
---|
866 | //viewPoint.setXYZ(0, 100, 0);
|
---|
867 | this->activeCamera->setLookAtTarget(lookAtPoint.x, lookAtPoint.y, lookAtPoint.z);
|
---|
868 | this->activeCamera->setPosition(viewPoint.x, viewPoint.y, viewPoint.z);
|
---|
869 |
|
---|
870 |
|
---|
871 | // update Skybox - hier richtig?
|
---|
872 | this->skybox->getBoxObject()->setPosition(viewPoint.x, 1, viewPoint.z);
|
---|
873 | } else {
|
---|
874 | this->activeCamera->setLookAtTarget(this->player->getAbsolutePosition());
|
---|
875 | this->cameraFixedCount++;
|
---|
876 | }
|
---|
877 | }
|
---|
878 |
|
---|
879 | void GameScene::updateGameSecond()
|
---|
880 | {
|
---|
881 | /*D3DXVECTOR3 * D3DXVec3Unproject(
|
---|
882 | D3DXVECTOR3 * pOut,
|
---|
883 | CONST D3DXVECTOR3 * pV,
|
---|
884 | CONST D3DVIEWPORT9 * pViewport,
|
---|
885 | CONST D3DXMATRIX * pProjection,
|
---|
886 | CONST D3DXMATRIX * pView,
|
---|
887 | CONST D3DXMATRIX * pWorld
|
---|
888 | );*/
|
---|
889 | if(this->cameraFixedCount>2) {
|
---|
890 | D3DXVECTOR3 mousePosSource;
|
---|
891 | mousePosSource.x = (float)this->mousePos[0];
|
---|
892 | mousePosSource.y = (float)this->mousePos[1];
|
---|
893 | mousePosSource.z = 0;
|
---|
894 |
|
---|
895 | D3DXVECTOR3 unprojectedMouseNear, unprojectedMouseFar;
|
---|
896 | D3DVIEWPORT9 pViewport;
|
---|
897 |
|
---|
898 | this->device->GetViewport(&pViewport);
|
---|
899 |
|
---|
900 | D3DXVec3Unproject(&unprojectedMouseNear, &mousePosSource, &pViewport, &this->getProjectionMatrix(), &this->getViewMatrix(), &this->worldMatrix);
|
---|
901 | mousePosSource.z = 1;
|
---|
902 | D3DXVec3Unproject(&unprojectedMouseFar, &mousePosSource, &pViewport, &this->getProjectionMatrix(), &this->getViewMatrix(), &this->worldMatrix);
|
---|
903 |
|
---|
904 | NxVec3 NxNear(unprojectedMouseNear.x, unprojectedMouseNear.y, unprojectedMouseNear.z);
|
---|
905 | NxVec3 NxFar(unprojectedMouseFar.x, unprojectedMouseFar.y, unprojectedMouseFar.z);
|
---|
906 |
|
---|
907 | NxVec3 direction;
|
---|
908 | direction.subtract(NxFar, NxNear);
|
---|
909 | direction.normalize();
|
---|
910 | NxRay ray(NxNear, direction);
|
---|
911 |
|
---|
912 | NxRaycastHit hit;
|
---|
913 | Vector target;
|
---|
914 |
|
---|
915 | // Get the closest shape
|
---|
916 | NxU32 mask = 0;
|
---|
917 | /*mask |= UserContactReport::COLGROUP_NOCOL;
|
---|
918 | mask |= UserContactReport::COLGROUP_TERRAIN;*/
|
---|
919 | mask = 0xFFFFFFFF;
|
---|
920 | NxShape* closestShape = this->pScene->raycastClosestShape(ray, NX_ALL_SHAPES, hit, mask);
|
---|
921 | if (closestShape && closestShape->getActor().userData != this->player)
|
---|
922 | {
|
---|
923 | //this->manager->printToConsole("HIT");
|
---|
924 | //NxVec3& worldImpact = hit.worldImpact;
|
---|
925 | target.setNxVector(hit.worldImpact);
|
---|
926 | //dist = hit.distance;
|
---|
927 | } else {
|
---|
928 | //this->manager->printToConsole("Not HIT");
|
---|
929 | target.setXYZ(unprojectedMouseFar.x, unprojectedMouseFar.y, unprojectedMouseFar.z);
|
---|
930 | }
|
---|
931 |
|
---|
932 | this->player->getActiveWeapon()->setFireAt(target);
|
---|
933 | if(this->mouseButton[this->MOUSE_LEFT]) {
|
---|
934 | player->getActiveWeapon()->fire();
|
---|
935 | }
|
---|
936 | }
|
---|
937 |
|
---|
938 | //Set HUD Time
|
---|
939 | int minutes, seconds, intDuration;
|
---|
940 | this->gameDuration-=this->dt;
|
---|
941 | intDuration = (int) this->gameDuration;
|
---|
942 | seconds = intDuration%60;
|
---|
943 | minutes = (intDuration-seconds)/60;
|
---|
944 | this->hud->setTime(minutes, seconds);
|
---|
945 |
|
---|
946 |
|
---|
947 | //Check if Challenge is over!
|
---|
948 | std::list<SPTR<Node> >::iterator it;
|
---|
949 | std::list<SPTR<Node> >::iterator tit;
|
---|
950 | Player* p;
|
---|
951 | Player* tp;
|
---|
952 | if(!this->resultVisible) {
|
---|
953 | if(this->gameDuration>0) {
|
---|
954 | if(this->player->getHealth()<=0) {
|
---|
955 | this->initLose();
|
---|
956 | } else {
|
---|
957 | for(it = this->playerList.begin();it!=this->playerList.end();it++) {
|
---|
958 | p = (Player*) (*it).get();
|
---|
959 | if(p != this->player && p->getHealth()<=0) {
|
---|
960 | //Reset activeOpponent from a player if that opponent should be deleted!
|
---|
961 | for(tit = this->playerList.begin();tit!=this->playerList.end();tit++) {
|
---|
962 | tp = (Player*) (*tit).get();
|
---|
963 | if(p != tp && p->isA(GameScene::NODE_AIPLAYER) && ((AIPlayer*) tp)->activeOpponent == p) {
|
---|
964 | ((AIPlayer*) tp)->activeOpponent = NULL;
|
---|
965 | }
|
---|
966 | }
|
---|
967 | if(!p->getSoftKill()) {
|
---|
968 | #if(0)
|
---|
969 | p->setSoftKill(true,4);
|
---|
970 | #elif(0)
|
---|
971 | p->setSoftKill(false,0); // MG
|
---|
972 | #elif(1)
|
---|
973 | p->setSoftKill(true,1); // MG
|
---|
974 | #endif
|
---|
975 | }
|
---|
976 | }
|
---|
977 | }
|
---|
978 | if(this->playerList.size()<=1) {
|
---|
979 | this->initWin();
|
---|
980 | }
|
---|
981 | }
|
---|
982 | } else { //Time's up
|
---|
983 | float sumHealth = 0;
|
---|
984 | for(it = this->playerList.begin();it!=this->playerList.end();it++) {
|
---|
985 | p = (Player*) (*it).get();
|
---|
986 | if(p != this->player) {
|
---|
987 | sumHealth += max(0.0f, p->getHealth());
|
---|
988 | }
|
---|
989 | }
|
---|
990 | if(this->player->getHealth()>sumHealth) {
|
---|
991 | this->initWin();
|
---|
992 | } else {
|
---|
993 | this->initLose();
|
---|
994 | }
|
---|
995 | }
|
---|
996 | } else {
|
---|
997 | this->resultShowingTimer-=this->dt;
|
---|
998 | if(!this->won && this->resultShowingTimer<=5.75f) {
|
---|
999 | this->recalcTransformations = false;
|
---|
1000 | }
|
---|
1001 | if(this->won && this->resultShowingTimer<=5.75f) {
|
---|
1002 | this->player->resetValues();
|
---|
1003 | //GLOBAL_player_freezeQ = true;
|
---|
1004 | this->ignoreKeys = true;
|
---|
1005 | }
|
---|
1006 | if(this->resultShowingTimer<=0) {
|
---|
1007 | this->manager->switchToMenueScene();
|
---|
1008 | }
|
---|
1009 | }
|
---|
1010 | if(this->showFPS) {
|
---|
1011 | char temp[16];
|
---|
1012 | sprintf(temp, "FPS: %f", DXUTGetFPS());
|
---|
1013 | this->manager->printToConsole(temp);
|
---|
1014 | this->hud->message(temp, 1.0f, 1.0f);
|
---|
1015 | }
|
---|
1016 | this->hud->setAmmo(this->player->getAmo());
|
---|
1017 | }
|
---|
1018 |
|
---|
1019 | void GameScene::initWin()
|
---|
1020 | {
|
---|
1021 | this->won=true;
|
---|
1022 | this->player->initWin();
|
---|
1023 | this->resultVisible = true;
|
---|
1024 | this->hud->displayWin(6, 0.01f);
|
---|
1025 | this->resultShowingTimer = 6;
|
---|
1026 |
|
---|
1027 | if(this->happySound) {
|
---|
1028 | this->happySound->play();
|
---|
1029 | }
|
---|
1030 | }
|
---|
1031 |
|
---|
1032 | void GameScene::initLose()
|
---|
1033 | {
|
---|
1034 | this->player->initLose();
|
---|
1035 | this->won = false;
|
---|
1036 | this->resultVisible = true;
|
---|
1037 | this->hud->displayLose(6, 0.01f);
|
---|
1038 | this->resultShowingTimer = 6;
|
---|
1039 | if(this->sadSound) {
|
---|
1040 | this->sadSound->play();
|
---|
1041 | }
|
---|
1042 | }
|
---|
1043 |
|
---|
1044 | //void GameScene::setBackgroundSound(std::string filename) {
|
---|
1045 | // this->bgMusicStream = FSOUND_Stream_Open(filename.c_str(), FSOUND_LOOP_NORMAL, 0, 0);
|
---|
1046 | //}
|
---|
1047 | //
|
---|
1048 | //void GameScene::setBackgroundSoundVolume(float vol) {
|
---|
1049 | // this->bgSoundVolume = vol;
|
---|
1050 | // if(this->bgSoundChannel!=-1) {
|
---|
1051 | // FSOUND_SetVolume(this->bgSoundChannel, (int)(255*this->bgSoundVolume));
|
---|
1052 | // }
|
---|
1053 | //}
|
---|
1054 | //
|
---|
1055 | //void GameScene::playBackgroundSound() {
|
---|
1056 | // if(this->bgMusicStream!=NULL) {
|
---|
1057 | // this->bgSoundChannel = FSOUND_Stream_Play(FSOUND_FREE, this->bgMusicStream);
|
---|
1058 | // FSOUND_SetVolume(this->bgSoundChannel, (int)(255*this->bgSoundVolume));
|
---|
1059 | // }
|
---|
1060 | //}
|
---|
1061 |
|
---|
1062 | void GameScene::connectMaterialIds(int physicId, int xmlId)
|
---|
1063 | {
|
---|
1064 | //this->materialConnectVector.push_back(temp);
|
---|
1065 | this->materialXMLVector.push_back(xmlId);
|
---|
1066 | this->materialPhysicVector.push_back(physicId);
|
---|
1067 | }
|
---|
1068 |
|
---|
1069 | int GameScene::getPhysicMaterialId(int xmlId)
|
---|
1070 | {
|
---|
1071 | for(UINT i=0;i<this->materialXMLVector.size();i++) {
|
---|
1072 | if(this->materialXMLVector.at(i) == xmlId) {
|
---|
1073 | return this->materialPhysicVector.at(i);
|
---|
1074 | }
|
---|
1075 | }
|
---|
1076 | return 0;
|
---|
1077 | }
|
---|
1078 |
|
---|
1079 | Bullet* GameScene::cloneBulletFromReference(int type)
|
---|
1080 | {
|
---|
1081 | Bullet* temp;
|
---|
1082 | for(UINT i=0;i<this->refBulletVector.size();i++) {
|
---|
1083 | temp = (Bullet*) this->refBulletVector.at(i).get();
|
---|
1084 | if(type == temp->getBulletType()) {
|
---|
1085 | return (Bullet*) temp->clone();
|
---|
1086 | }
|
---|
1087 | }
|
---|
1088 | return NULL;
|
---|
1089 | }
|
---|
1090 |
|
---|
1091 | Weapon* GameScene::cloneWeaponFromReference(int type)
|
---|
1092 | {
|
---|
1093 | Weapon* temp;
|
---|
1094 | for(UINT i=0;i<this->refWeaponVector.size();i++) {
|
---|
1095 | temp = (Weapon*) this->refWeaponVector.at(i).get();
|
---|
1096 | if(type == temp->getWeaponType()) {
|
---|
1097 | this->manager->printToConsole("GameScene::cloneWeaponFromReference.....clone in weapon initialized?");
|
---|
1098 | return (Weapon*) temp->clone();
|
---|
1099 | }
|
---|
1100 | }
|
---|
1101 | return NULL;
|
---|
1102 | }
|
---|
1103 |
|
---|
1104 | void GameScene::reduceHealthOnPlayers(Bullet* bullet)
|
---|
1105 | {
|
---|
1106 | //this->manager->printToConsole("REDUCING HEALTH");
|
---|
1107 | Vector dist;
|
---|
1108 | Vector bulletPos;
|
---|
1109 | bulletPos = bullet->getAbsolutePosition();
|
---|
1110 | Player* p;
|
---|
1111 | float forceFactor;
|
---|
1112 | for(UINT i=0;i<bullet->playerList.size();i++) {
|
---|
1113 | p = bullet->playerList.at(i);
|
---|
1114 | dist = p->getAbsolutePosition() - bulletPos;
|
---|
1115 | forceFactor = max(0.0f, (bullet->impactRadius - dist.length())/bullet->impactRadius);
|
---|
1116 | p->setHealth(p->getHealth()- forceFactor*bullet->impactDamage);
|
---|
1117 | }
|
---|
1118 | }
|
---|
1119 |
|
---|
1120 | /*void GameScene::updateSoundNodeVolume()
|
---|
1121 | {
|
---|
1122 | Scene::updateSoundNodeVolume();
|
---|
1123 | if(this->bgSoundChannel!=-1) {
|
---|
1124 | FSOUND_SetVolume(this->bgSoundChannel, (int)(255*this->bgSoundVolume*this->sceneAlpha));
|
---|
1125 | }
|
---|
1126 | }*/
|
---|
1127 |
|
---|
1128 | float GameScene::getTerrainHeight(Vector v)
|
---|
1129 | {
|
---|
1130 | NxVec3 direction(0, -1, 0);
|
---|
1131 | NxRay ray(v.getNxVector(), direction);
|
---|
1132 | NxRaycastHit hit;
|
---|
1133 | Vector hv = v;
|
---|
1134 |
|
---|
1135 | // Get the closest shape
|
---|
1136 | NxShape* closestShape = this->pScene->raycastClosestShape(ray, NX_ALL_SHAPES, hit, 0xFFFFFFFF, NX_MAX_F32);//0xffffff);
|
---|
1137 | if (closestShape)
|
---|
1138 | {
|
---|
1139 | hv.y = hit.worldImpact.y;
|
---|
1140 | } else {
|
---|
1141 | hv.y = 0;
|
---|
1142 | }
|
---|
1143 | float h = this->terrain->getHeight(v.x, v.z);
|
---|
1144 | hv.y = (hv.y>=h) ? hv.y : h;
|
---|
1145 | return hv.y;
|
---|
1146 | }
|
---|
1147 |
|
---|
1148 | void GameScene::setChallengeDescription(std::string _description, float _descDuration)
|
---|
1149 | {
|
---|
1150 | this->descSet = true;
|
---|
1151 | this->description = _description;
|
---|
1152 | this->descDuration = _descDuration;
|
---|
1153 | }
|
---|
1154 |
|
---|
1155 | void GameScene::setMaxEnemyCount(int maxEnemyCount)
|
---|
1156 | {
|
---|
1157 | this->maxEnemyCount = maxEnemyCount;
|
---|
1158 | }
|
---|
1159 |
|
---|
1160 | void GameScene::hasWon() {
|
---|
1161 | std::list<SPTR<Node> >::iterator it;
|
---|
1162 | Player* p;
|
---|
1163 | for(it = this->playerList.begin();it!=this->playerList.end();it++) {
|
---|
1164 | p = (Player*) (*it).get();
|
---|
1165 | if(p != this->player) {
|
---|
1166 | //this->manager->printToConsole("setting health = 0");
|
---|
1167 | p->setHealth(0);
|
---|
1168 | }
|
---|
1169 | }
|
---|
1170 | } |
---|