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