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