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