#include "dxstdafx.h" #include "GameScene.h" #include "Player.h" #include "UserPlayer.h" #include "AIPlayer.h" #include "SimpleWeapon.h" #include "SimpleBullet.h" #include "Bullet.h" #include "Weapon.h" #include "Terrain.h" #include "HUD.h" #include "Ocean.h" #include "SkyBox.h" #include "GameSceneLoader.h" #include "Goodie.h" #include "UniversalWeapon.h" #include "SoundNode.h" #include #include #include #include #define M_PI 3.1415 extern bool GLOBAL_player_freezeQ; GameScene::GameScene(void) : Scene() { srand( (unsigned)time( NULL ) ); this->terrain = 0; this->ocean = 0; this->skybox = 0; this->bgSoundChannel = -1; this->cameraFixedCount = 0; this->flyCamEnabled = false; this->sadSound = NULL; this->happySound = NULL; this->alreadyUsed = false; this->aiPlayerFireEnable = true; this->showFPS = false; this->maxEnemyCount = 1; this->recalcTransformations = true; this->currentlypaused = false; this->preparepaused = false; this->ignoreKeys = false; } GameScene::~GameScene(void) { //this->clearScene(); /*if(this->defaultRenderTarget) { delete this->defaultRenderTarget; this->defaultRenderTarget = NULL; }*/ } void GameScene::clearScene() { //this->fetchPhysicResults(); this->terrain = 0; this->ocean = 0; this->skybox = 0; this->bgSoundChannel = -1; this->cameraFixedCount = 0; this->flyCamEnabled = false; this->firstFrame = true; /*if(this->happySound) { this->happySound->killMe(); this->happySound=NULL; } if(this->sadSound) { this->sadSound->killMe(); this->sadSound=NULL; }*/ //Game cleanup /*std::list >::iterator it; Player* p; exception e; for(it=this->playerList.begin();it!=this->playerList.end();it++) { p = (Player*) (*it).get(); if(p) { try { if(p->upperSpringActor) { this->pScene->releaseActor(*p->upperSpringActor); this->pScene->releaseJoint(*p->upperJoint); p->upperJoint = NULL; p->upperSpringActor = NULL; } } catch(exception e) { } } }*/ this->cleanUpScene(); playerList.clear(); goodieList.clear(); bulletList.clear(); materialXMLVector.clear(); materialPhysicVector.clear(); refWeaponVector.clear(); //List of all Weapons refBulletVector.clear(); this->cameraFixedCount = 0; this->sadSound = NULL; this->happySound = NULL; this->currentlypaused = false; this->preparepaused = false; Scene::clearScene(); } void GameScene::initScene(GameManager &_manager) { this->ignoreKeys = false; this->resultVisible = false; this->won = false; this->recalcTransformations = true; this->resultShowingTimer = 0; this->setContactReport(&this->userContactReport); this->setTriggerReport(&this->userTriggerReport); this->setNotifyReport(&this->userNotify); this->descSet = false; this->currentlypaused = false; this->preparepaused = false; GLOBAL_player_freezeQ = false; Scene::initScene(_manager); //Define ColDetGroups //Terrain Stuff this->pScene->setActorGroupPairFlags(UserContactReport::COLGROUP_TERRAIN, UserContactReport::COLGROUP_TERRAIN, NX_IGNORE_PAIR); //this->pScene->setActorGroupPairFlags(UserContactReport::COLGROUP_TERRAIN, UserContactReport::COLGROUP_PLAYER, NX_IGNORE_PAIR); this->pScene->setActorGroupPairFlags(UserContactReport::COLGROUP_TERRAIN, UserContactReport::COLGROUP_BULLET, NX_NOTIFY_ON_START_TOUCH); this->pScene->setActorGroupPairFlags(UserContactReport::COLGROUP_TERRAIN, UserContactReport::COLGROUP_GOODIE, NX_IGNORE_PAIR); this->pScene->setActorGroupPairFlags(UserContactReport::COLGROUP_TERRAIN, UserContactReport::COLGROUP_OTHER, NX_IGNORE_PAIR); //Bullet Stuff this->pScene->setActorGroupPairFlags(UserContactReport::COLGROUP_BULLET, UserContactReport::COLGROUP_GOODIE, NX_NOTIFY_ON_START_TOUCH); this->pScene->setActorGroupPairFlags(UserContactReport::COLGROUP_BULLET, UserContactReport::COLGROUP_OTHER, NX_NOTIFY_ON_START_TOUCH); this->pScene->setActorGroupPairFlags(UserContactReport::COLGROUP_BULLET, UserContactReport::COLGROUP_OBSTACLE, NX_NOTIFY_ON_START_TOUCH); this->pScene->setActorGroupPairFlags(UserContactReport::COLGROUP_BULLET, UserContactReport::COLGROUP_ONEPLAYER, NX_NOTIFY_ON_START_TOUCH); this->pScene->setActorGroupPairFlags(UserContactReport::COLGROUP_BULLET, UserContactReport::COLGROUP_MOREPLAYER, NX_NOTIFY_ON_START_TOUCH); //Player Stuff this->pScene->setGroupCollisionFlag(UserContactReport::COLGROUP_PLAYER, UserContactReport::COLGROUP_TERRAIN, false); this->pScene->setActorGroupPairFlags(UserContactReport::COLGROUP_PLAYER, UserContactReport::COLGROUP_BULLET, NX_NOTIFY_ON_START_TOUCH); this->pScene->setActorGroupPairFlags(UserContactReport::COLGROUP_PLAYER, UserContactReport::COLGROUP_GOODIE, NX_NOTIFY_ON_START_TOUCH); this->pScene->setActorGroupPairFlags(UserContactReport::COLGROUP_PLAYER, UserContactReport::COLGROUP_PLAYER, NX_NOTIFY_ON_START_TOUCH | NX_NOTIFY_ON_END_TOUCH); this->pScene->setActorGroupPairFlags(UserContactReport::COLGROUP_PLAYER, UserContactReport::COLGROUP_FIRE, NX_NOTIFY_ON_START_TOUCH); this->pScene->setActorGroupPairFlags(UserContactReport::COLGROUP_PLAYER, UserContactReport::COLGROUP_ICE, NX_NOTIFY_ON_START_TOUCH); this->pScene->setGroupCollisionFlag(UserContactReport::COLGROUP_NOSELFCOL, UserContactReport::COLGROUP_NOSELFCOL, false); this->pScene->setGroupCollisionFlag(UserContactReport::COLGROUP_NOCOL, UserContactReport::COLGROUP_NOSELFCOL, false); //Disable flag for noCol group! this->pScene->setActorGroupPairFlags(UserContactReport::COLGROUP_NOCOL, UserContactReport::COLGROUP_TERRAIN, NX_IGNORE_PAIR); this->pScene->setActorGroupPairFlags(UserContactReport::COLGROUP_NOCOL, UserContactReport::COLGROUP_PLAYER, NX_IGNORE_PAIR); this->pScene->setActorGroupPairFlags(UserContactReport::COLGROUP_NOCOL, UserContactReport::COLGROUP_BULLET, NX_IGNORE_PAIR); this->pScene->setActorGroupPairFlags(UserContactReport::COLGROUP_NOCOL, UserContactReport::COLGROUP_GOODIE, NX_IGNORE_PAIR); this->pScene->setActorGroupPairFlags(UserContactReport::COLGROUP_NOCOL, UserContactReport::COLGROUP_OTHER, NX_IGNORE_PAIR); this->pScene->setActorGroupPairFlags(UserContactReport::COLGROUP_NOCOL, UserContactReport::COLGROUP_NOCOL, NX_IGNORE_PAIR); this->pScene->setGroupCollisionFlag(UserContactReport::COLGROUP_NOCOL, UserContactReport::COLGROUP_TERRAIN, false); this->pScene->setGroupCollisionFlag(UserContactReport::COLGROUP_NOCOL, UserContactReport::COLGROUP_PLAYER, false); this->pScene->setGroupCollisionFlag(UserContactReport::COLGROUP_NOCOL, UserContactReport::COLGROUP_BULLET, false); this->pScene->setGroupCollisionFlag(UserContactReport::COLGROUP_NOCOL, UserContactReport::COLGROUP_GOODIE, false); this->pScene->setGroupCollisionFlag(UserContactReport::COLGROUP_NOCOL, UserContactReport::COLGROUP_OTHER, false); this->pScene->setGroupCollisionFlag(UserContactReport::COLGROUP_NOCOL, UserContactReport::COLGROUP_NOCOL, false); this->pScene->setGroupCollisionFlag(UserContactReport::COLGROUP_NOCOL, UserContactReport::COLGROUP_FIRE, false); this->pScene->setGroupCollisionFlag(UserContactReport::COLGROUP_NOCOL, UserContactReport::COLGROUP_ONEPLAYER, false); this->pScene->setGroupCollisionFlag(UserContactReport::COLGROUP_NOCOL, UserContactReport::COLGROUP_MOREPLAYER, false); this->pScene->setGroupCollisionFlag(UserContactReport::COLGROUP_NOCOL, 0, false); //Disable Fire fire collision this->pScene->setGroupCollisionFlag(UserContactReport::COLGROUP_FIRE, UserContactReport::COLGROUP_FIRE, false); if(!this->happySound) { this->happySound = (SoundNode*) this->createNode(Scene::NODE_SOUND); this->happySound->loadFile("./media/sound/win.mp3", false); } if(!this->sadSound) { this->sadSound = (SoundNode*) this->createNode(Scene::NODE_SOUND); this->sadSound->loadFile("./media/sound/lose.mp3", false); } this->cameraFixedCount=0; } void GameScene::renderScene(float fElapsedTime) { if(this->isVisible()) { if(this->device==0) { this->device = DXUTGetD3DDevice(); this->physxRenderer.setDevice(*this->device); } if(this->preparepaused) { this->currentlypaused = true; } //this->device->SetRenderTarget(0, this->finalImageSurface); //this->manager->printToConsole("renderScene"); //Execute RenderChain /*std::list::iterator chainIt; for(chainIt=this->renderChain.begin(); chainIt!=this->renderChain.end(); chainIt++) { (*this.**chainIt)(); }*/ if(this->firstFrame) { this->playBackgroundSound(); } if(!this->currentlypaused) { this->takeTime(); } //ClearScreen //this->clearRenderTargetAndZBuffer(); //Clear SharedResources this->clearSharedResources(); //Fetch Physic Results if(this->recalcTransformations && !this->currentlypaused) { this->fetchPhysicResults(); } //Fading Stuff if(!this->currentlypaused) { this->doFade(); //FIRST GAME UPDATE this->updateGameFirst(); //Trigger updates this->updateTrigger(); //Update Nodes this->updateNodes(); //Calculate Transformations if(this->recalcTransformations) { this->calculateTransformations(); } //SECOND GAME UPDATE this->updateGameSecond(); } //startRenderPasses this->startRenderPasses(); //Cleanup Memory this->cleanUpScene(); if(!this->currentlypaused) { //Start Physic if(this->recalcTransformations) { this->startPhysic(); } } this->cnt = 0; this->firstFrame = false; } } void GameScene::cleanUpScene() { std::list >::iterator it; std::list >::iterator nit; std::vector >::iterator rit; Node* node; for(it=this->zombieNodeList.begin();it!=this->zombieNodeList.end();it++) { node = (*it).get(); node->getFather()->removeChild(*it); //Delete Renderer if(node->hasRenderer()) { Renderer *r = node->getRenderer().get(); for(rit=this->rendererList.begin();rit!=this->rendererList.end();rit++) { if((*rit).get() == r) { this->rendererList.erase(rit); break; } } } //Delete Physic Actor if(node->getActor()!=NULL) { this->pScene->releaseActor(*node->getActor()); } this->deleteNodeInList(node, this->nodeList); this->deleteNodeInList(node, this->particleList); this->deleteNodeInList(node, this->soundNodeList); this->deleteNodeInList(node, this->playerList); this->deleteNodeInList(node, this->goodieList); this->deleteNodeInList(node, this->bulletList); } this->zombieNodeList.clear(); } Terrain* GameScene::getTerrain() { return this->terrain; } HUD* GameScene::getHUD() { return this->hud; } Node* GameScene::createNode(int type) { return this->createNode(type, this->root, true, false); } Node* GameScene::createNode(int type, Node &father) { return this->createNode(type, father, true, false); } Node* GameScene::createNode(int type, bool addDefaultRenderer) { return this->createNode(type, this->root, addDefaultRenderer, false); } Node* GameScene::createNode(int type, Node &father, bool addDefaultRenderer) { return this->createNode(type, father, addDefaultRenderer, false); } Node* GameScene::createNode(int type, Node &father, bool addDefaultRenderer, bool isReference) { switch(type) { case NODE_TERRAIN: { SPTR node(new Terrain); father.addChild(node); this->nodeList.push_back(node); node->setScene(*this); Node *temp = node.get(); this->terrain = (Terrain *) temp; return temp; } break; case NODE_OCEAN: { SPTR node(new Ocean); father.addChild(node); this->nodeList.push_back(node); node->setScene(*this); Node *temp = node.get(); this->ocean = (Ocean *) temp; return temp; } break; case NODE_HUD: { SPTR node(new HUD); father.addChild(node); this->nodeList.push_back(node); node->setScene(*this); Node *temp = node.get(); this->hud = (HUD *) temp; return temp; } break; case NODE_SKYBOX: { SPTR node(new SkyBox); father.addChild(node); this->nodeList.push_back(node); node->setScene(*this); Node *temp = node.get(); this->skybox = (SkyBox *) temp; return temp; } break; case NODE_USERPLAYER: { SPTR node(new UserPlayer); father.addChild(node); this->nodeList.push_back(node); this->playerList.push_back(node); node->setScene(*this); this->player = (UserPlayer *) node.get(); return node.get(); } break; case NODE_AIPLAYER: { SPTR node(new AIPlayer); father.addChild(node); this->nodeList.push_back(node); this->playerList.push_back(node); node->setScene(*this); return node.get(); } break; case NODE_SIMPLEWEAPON: { SPTR node(new SimpleWeapon); node->setScene(*this); if(!isReference) { father.addChild(node); this->nodeList.push_back(node); } else { this->refWeaponVector.push_back(node); } return node.get(); } break; case NODE_GOODIE: { SPTR node(new Goodie); node->setScene(*this); //if(!isReference) { father.addChild(node); this->nodeList.push_back(node); /*} else { this->refWeaponList.push_back(node); }*/ if(addDefaultRenderer) { SPTR renderer(new SimpleMeshRenderer); renderer->setScene(*this); WPTR wn(node); renderer->setNode(wn); node->setRenderer(renderer); renderer->init(); this->rendererList.push_back(renderer); } return node.get(); } break; case NODE_SIMPLEBULLET: { SPTR node(new SimpleBullet); node->setScene(*this); if(!isReference) { father.addChild(node); this->nodeList.push_back(node); this->bulletList.push_back(node); } else { this->refBulletVector.push_back(node); } return node.get(); } break; case NODE_UNIVERSALWEAPON: { SPTR node(new UniversalWeapon); node->setScene(*this); if(!isReference) { father.addChild(node); this->nodeList.push_back(node); } else { this->refWeaponVector.push_back(node); } return node.get(); } break; default: return Scene::createNode(type, father, addDefaultRenderer, isReference); break; } } void GameScene::loadGame(std::string filename) { GameSceneLoader loader; if(!loader.loadGameScene(*this, filename, this->manager)) {//loadGameScene(*this, filename)) { this->manager->printToConsole("Loading failed!"); //Initialize rest //TODO Object3d preloading, sound preloading usw. } } /*void GameScene::setMaterialId(int desiredId, int realId) { int ids[2]; ids[0] = desiredId; ids[1] = realId; this->desiredToRealMaterialId.push_back(ids); }*/ std::list > * GameScene::getPlayerList() { return &this->playerList; } std::list > * GameScene::getGoodieList() { return &this->goodieList; } /*void GameScene::registerHealthPackage(Goodie* hp, float arrivalTime) { this->setTrigger(this->TRIGGER_UNSETSTANDBY, hp, this->getRandomTime(arrivalTime, timeVariation)); } void GameScene::registerWeaponPackage(Goodie* wp, float arrivalTime) { } void GameScene::registerBulletPackage(Goodie* mp, float arrivalTime) { }*/ float GameScene::getRandomTime(float timeBase, float timeVariation) { return timeBase + ((((float) rand())/RAND_MAX)-0.5f)*timeVariation*2; } void GameScene::executeTrigger(SPTR trigger) { Scene::executeTrigger(trigger); Trigger *t = trigger.get(); Node* node; Node* secondNode; Player* tempPlayer; Vector normal; Vector pos; switch(t->getType()) { case this->TRIGGER_IMPACTTERRAIN: node = t->getNode().get(); //Bullet normal = t->getNormal(); ((Bullet*) node)->impactTerrain(normal); break; case this->TRIGGER_IMPACTPLAYER: node = t->getNode().get(); //Bullet secondNode = t->getSecondNode().get(); //Player normal = t->getNormal(); ((Bullet*) node)->impactPlayer((Player*) secondNode, normal); break; case this->TRIGGER_IMPACTGOODIE: node = t->getNode().get(); secondNode = t->getSecondNode().get(); //Goodie normal = t->getNormal(); ((Bullet*) node)->impactGoodie((Goodie*) secondNode, normal); break; case this->TRIGGER_IMPACTOTHER: node = t->getNode().get(); secondNode = t->getSecondNode().get(); //Object3d normal = t->getNormal(); ((Bullet*) node)->impactOther((Object3d*) secondNode, normal); break; case this->TRIGGER_GOODIECATCH: { node = t->getNode().get(); //Player secondNode = t->getSecondNode().get(); //Goddie Goodie *goodie = (Goodie*) secondNode; Player *p = (Player*) node; this->manager->printToConsole("General Goodie catch!"); switch(goodie->getGoodieType()) { case Goodie::GOODIE_HEALTH: this->manager->printToConsole(" health!"); p->addHealth(goodie->getHealthAmount()); break; case Goodie::GOODIE_WEAPON: //this->manager->printToConsole("GOODIE_WEAPON adding not yet implemented!"); this->manager->printToConsole(" weapon!"); if(goodie->getWeaponType()<=3) { SimpleWeapon *weapon = (SimpleWeapon *) this->createNode(this->NODE_SIMPLEWEAPON, *p->schale, true); weapon->setWeaponType(goodie->getWeaponType()); weapon->addMunition(goodie->getArmorAmount()); weapon->initWeapon(); p->addWeapon(*weapon); } else { p->addWeapon(*this->cloneWeaponFromReference(goodie->getWeaponType())); } break; case Goodie::GOODIE_AMO: this->manager->printToConsole(" amo!"); p->addMunition(goodie->getWeaponType(), goodie->getArmorAmount()); break; } SoundNode* goodiePick = (SoundNode*) this->createNode(GameScene::NODE_SOUND); goodiePick->loadFile("./media/sound/goodiePick.mp3", false); goodiePick->setKillSoundNodeAfterPlayed(true); goodiePick->play(); secondNode->killMe(); } break; case this->TRIGGER_IMPACTFIRE: node = t->getNode().get(); secondNode = t->getSecondNode().get(); if(node->userData != secondNode) { Player* p = (Player*) secondNode; p->setHealth(p->getRealHealth() - 0.1f); p->hitByFire(); if(p->isToasted()) { this->hud->displayToasted(0.5, 0.01f); } } break; case this->TRIGGER_IMPACTICE: node = t->getNode().get(); secondNode = t->getSecondNode().get(); if(node->userData != secondNode) { Player* p = (Player*) secondNode; p->setHealth(p->getRealHealth() - 0.05f); p->hitByIce(); /*if(p->isToasted()) { this->hud->displayToasted(1.0, 0.01f); }*/ } break; case this->TRIGGER_CREATEPLAYER: case this->TRIGGER_CREATEMOREPLAYER: this->manager->printToConsole("Create ONE Player"); if(this->gameMode==1) { node = t->getNode().get(); //Create Trigger Object secondNode = t->getSecondNode().get(); //Bullet tempPlayer = ((Bullet*)secondNode)->myPlayer; //Player of bullet //if(tempPlayer == this->player && this->playerList.size()-1 < this->maxEnemyCount) { if(tempPlayer == this->player && int(this->playerList.size())-1 < this->maxEnemyCount) { pos = node->getAbsolutePosition(); pos.y++; SimpleWeapon* weapon = NULL; Player* p = (Player*) this->createNode(GameScene::NODE_AIPLAYER); p->setAvatareFileName(this->enemyModel); p->setTeam(this->player->getTeam()+1); p->initPlayer(pos.x, pos.y, pos.z); //Add Standard Weapon weapon = (SimpleWeapon *) this->createNode(this->NODE_SIMPLEWEAPON, *p->schale, true); weapon->setWeaponType(0); weapon->addMunition(1000); weapon->initWeapon(); p->addWeapon(*weapon); p->setActiveWeapon(0); if(t->getType()==this->TRIGGER_CREATEPLAYER) { node->killMe(); } } secondNode->killMe(); } break; } } void GameScene::updateGameFirst() { //this->manager->printToConsole("updateGameFirst"); //Send Keys to UserPlayer /*player->accelerate(this->keyDown['W']); player->stop(this->keyDown['S']); player->toLeft(this->keyDown['A']); player->toRight(this->keyDown['D']);*/ /*if(this->keyDown['O']) { this->manager->printToConsole("adding upforce!"); this->player->addUpForce(); }*/ if(this->descSet) { this->descSet = false; this->hud->message(this->description, this->descDuration, 0.01f); } //switch to menue scene: if(this->keyDown[VK_ESCAPE]) { this->keyDown[VK_ESCAPE] = false; manager->switchToMenueScene(); } //fly around cam: /*if(this->keyDown['F']) { this->flyCamEnabled = true; } if(this->keyDown['G']) this->flyCamEnabled = false;*/ //Update Camera int screenWidth = this->manager->screenWidth; //TODO rausnehmen und durch richtigen wert ersetzen int screenHeight = this->manager->screenHeight; /*if(this->flyCamEnabled) { Vector viewPos; Vector lookAtPos; Vector dir; viewPos = this->activeCamera->getAbsolutePosition(); lookAtPos = this->activeCamera->getLookAtTarget(); dir = lookAtPos - viewPos; dir.normalize(); float rX = 0; float rY = 0; float dZ = 0; float dX = 0; float dY = 0; if(this->keyDown[VK_RIGHT]) { rY++; } if(this->keyDown[VK_LEFT]) { rY--; } if(this->keyDown[VK_UP]) { rX++; } if(this->keyDown[VK_DOWN]) { rX--; } if(this->keyDown['W']) { dZ++; } if(this->keyDown['S']) { dZ--; } if(this->keyDown['D']) { dX--; } if(this->keyDown['A']) { dX++; } if(this->keyDown['E']) { dY++; } if(this->keyDown['C']) { dY--; } float rotSpeed = 0.05f; D3DXQUATERNION quat; D3DXMATRIX rotMat; D3DXQuaternionIdentity(&quat); D3DXQuaternionRotationYawPitchRoll(&quat, rY*rotSpeed, rX*rotSpeed, 0); D3DXMatrixRotationQuaternion(&rotMat, &quat); D3DXVec4Transform(&dir, &dir, &rotMat); lookAtPos = viewPos + dir; Vector upVec(0, 1, 0); Vector rightVec; rightVec = dir.crossProd(upVec); float speed = 1; dir = dir*dZ*speed; rightVec = rightVec*dX*speed; upVec = upVec*dY*speed; lookAtPos = lookAtPos+dir+rightVec+upVec; viewPos = viewPos+dir+rightVec+upVec; this->activeCamera->setLookAtTarget(lookAtPos.x, lookAtPos.y, lookAtPos.z); this->activeCamera->setPosition(viewPos.x, viewPos.y, viewPos.z); this->skybox->getBoxObject()->setPosition(viewPos.x, 1, viewPos.z); return; }*/ //Update Player instructions if(!ignoreKeys) { if(this->keyDown['W']) player->accelerate(); if(this->keyDown['S']) player->stop(); if(this->keyDown['A']) player->toLeft(); if(this->keyDown['D']) player->toRight(); } //Set active Weapons if(this->keyDown['1']) player->setActiveWeapon(0); if(this->keyDown['2']) player->setActiveWeapon(1); if(this->keyDown['3']) player->setActiveWeapon(2); if(this->keyDown['4']) player->setActiveWeapon(3); if(this->keyDown['5']) player->setActiveWeapon(4); if(this->keyDown['6']) player->setActiveWeapon(5); if(this->keyDown['7']) player->setActiveWeapon(6); if(this->keyDown['8']) player->setActiveWeapon(7); if(this->keyDown['9']) player->setActiveWeapon(8); /*std::list >::iterator it; if(this->keyDown['Z']) { for(it = this->playerList.begin(); it!=this->playerList.end();it++) { ((Player*) (*it).get())->switchToPublicPhysic(); } } //this->player->switchToPublicPhysic(); if(this->keyDown['H']) { for(it = this->playerList.begin(); it!=this->playerList.end();it++) { ((Player*) (*it).get())->switchToPrivatePhysic(); } }*/ //this->player->switchToPrivatePhysic(); /*if(this->keyDown['J']) this->sObj->rotate(0,0,-0.2); if(this->keyDown['L']) this->sObj->rotate(0,0,0.2); if(this->keyDown['I']) this->sObj->rotate(-0.2,0,0); if(this->keyDown['K']) this->sObj->rotate(0.2,0,0); if(this->keyDown['U']) this->sObj->rotate(0,-0.2,0); if(this->keyDown['M']) this->sObj->rotate(0,0.2,0); if(this->keyDown['Y']) this->sObj->translate(0,0,6); if(this->keyDown['X']) this->sObj->translate(0,0,-6);*/ if(this->cameraFixedCount>5) { /*char temp[100]; sprintf(temp, "1/dt = %f", 1/dt); this->manager->printToConsole(temp);*/ int camFactor = 12; Vector diff; D3DXMATRIX mYaw; D3DXMATRIX mXaw; D3DXMATRIX bla; //dLookAtPoint = oldDLookAtPoint; //dViewPoint = oldDViewPoint; dViewPoint = player->getDesiredViewPoint(); dLookAtPoint = player->getDesiredLookAtPoint(); D3DXMatrixRotationY(&mYaw, (FLOAT)-M_PI/3*(0.5f-((float)this->mousePos[0])/screenWidth)*2); //Yaw berechnen diff = dViewPoint - dLookAtPoint; Vector tDiff; //if (this->flyCamEnabled) { // D3DXVec4Transform(&tDiff, &diff, &bla); //} else { D3DXVec4Transform(&tDiff, &diff, &mYaw); //} dViewPoint = dLookAtPoint + tDiff; //Falls Terrain höher als Cameraposition Vector tempView = dViewPoint; tempView.y += 5; float h= this->getTerrainHeight(tempView); int dHeight = 3; if(h>dViewPoint.y) { dViewPoint.y = h+dHeight; } if(!this->player->gotHit) { lookAtPoint = lookAtPoint + (dLookAtPoint-lookAtPoint)*this->dt*(float)camFactor; viewPoint = viewPoint + (dViewPoint-viewPoint)*this->dt*(float)camFactor; } else { lookAtPoint = lookAtPoint + (dLookAtPoint-lookAtPoint)*this->dt*(float)camFactor; viewPoint = viewPoint + (dViewPoint-viewPoint)*this->dt*(float)camFactor/5; } //Test if ViewPoint eventually collides with objects in scene if(viewPoint.y < h+dHeight/2) { /*if(viewPoint.y-h==0) { h = viewPoint.y-0.5f; } viewPoint.y += (dHeight/2)/(viewPoint.y-h);*/ viewPoint.y = dViewPoint.y; } //lookAtPoint.setXYZ(100, 30, 100); //viewPoint.setXYZ(0, 100, 0); this->activeCamera->setLookAtTarget(lookAtPoint.x, lookAtPoint.y, lookAtPoint.z); this->activeCamera->setPosition(viewPoint.x, viewPoint.y, viewPoint.z); // update Skybox - hier richtig? this->skybox->getBoxObject()->setPosition(viewPoint.x, 1, viewPoint.z); } else { this->activeCamera->setLookAtTarget(this->player->getAbsolutePosition()); this->cameraFixedCount++; } } void GameScene::updateGameSecond() { /*D3DXVECTOR3 * D3DXVec3Unproject( D3DXVECTOR3 * pOut, CONST D3DXVECTOR3 * pV, CONST D3DVIEWPORT9 * pViewport, CONST D3DXMATRIX * pProjection, CONST D3DXMATRIX * pView, CONST D3DXMATRIX * pWorld );*/ if(this->cameraFixedCount>2) { D3DXVECTOR3 mousePosSource; mousePosSource.x = (float)this->mousePos[0]; mousePosSource.y = (float)this->mousePos[1]; mousePosSource.z = 0; D3DXVECTOR3 unprojectedMouseNear, unprojectedMouseFar; D3DVIEWPORT9 pViewport; this->device->GetViewport(&pViewport); D3DXVec3Unproject(&unprojectedMouseNear, &mousePosSource, &pViewport, &this->getProjectionMatrix(), &this->getViewMatrix(), &this->worldMatrix); mousePosSource.z = 1; D3DXVec3Unproject(&unprojectedMouseFar, &mousePosSource, &pViewport, &this->getProjectionMatrix(), &this->getViewMatrix(), &this->worldMatrix); NxVec3 NxNear(unprojectedMouseNear.x, unprojectedMouseNear.y, unprojectedMouseNear.z); NxVec3 NxFar(unprojectedMouseFar.x, unprojectedMouseFar.y, unprojectedMouseFar.z); NxVec3 direction; direction.subtract(NxFar, NxNear); direction.normalize(); NxRay ray(NxNear, direction); NxRaycastHit hit; Vector target; // Get the closest shape NxU32 mask = 0; /*mask |= UserContactReport::COLGROUP_NOCOL; mask |= UserContactReport::COLGROUP_TERRAIN;*/ mask = 0xFFFFFFFF; NxShape* closestShape = this->pScene->raycastClosestShape(ray, NX_ALL_SHAPES, hit, mask); if (closestShape && closestShape->getActor().userData != this->player) { //this->manager->printToConsole("HIT"); //NxVec3& worldImpact = hit.worldImpact; target.setNxVector(hit.worldImpact); //dist = hit.distance; } else { //this->manager->printToConsole("Not HIT"); target.setXYZ(unprojectedMouseFar.x, unprojectedMouseFar.y, unprojectedMouseFar.z); } this->player->getActiveWeapon()->setFireAt(target); if(this->mouseButton[this->MOUSE_LEFT]) { player->getActiveWeapon()->fire(); } } //Set HUD Time int minutes, seconds, intDuration; this->gameDuration-=this->dt; intDuration = (int) this->gameDuration; seconds = intDuration%60; minutes = (intDuration-seconds)/60; this->hud->setTime(minutes, seconds); //Check if Challenge is over! std::list >::iterator it; std::list >::iterator tit; Player* p; Player* tp; if(!this->resultVisible) { if(this->gameDuration>0) { if(this->player->getHealth()<=0) { this->initLose(); } else { for(it = this->playerList.begin();it!=this->playerList.end();it++) { p = (Player*) (*it).get(); if(p != this->player && p->getHealth()<=0) { //Reset activeOpponent from a player if that opponent should be deleted! for(tit = this->playerList.begin();tit!=this->playerList.end();tit++) { tp = (Player*) (*tit).get(); if(p != tp && p->isA(GameScene::NODE_AIPLAYER) && ((AIPlayer*) tp)->activeOpponent == p) { ((AIPlayer*) tp)->activeOpponent = NULL; } } if(!p->getSoftKill()) { p->setSoftKill(true,4); } } } if(this->playerList.size()<=1) { this->initWin(); } } } else { //Time's up float sumHealth = 0; for(it = this->playerList.begin();it!=this->playerList.end();it++) { p = (Player*) (*it).get(); if(p != this->player) { sumHealth += max(0.0f, p->getHealth()); } } if(this->player->getHealth()>sumHealth) { this->initWin(); } else { this->initLose(); } } } else { this->resultShowingTimer-=this->dt; if(!this->won && this->resultShowingTimer<=5.75f) { this->recalcTransformations = false; } if(this->won && this->resultShowingTimer<=5.75f) { this->player->resetValues(); //GLOBAL_player_freezeQ = true; this->ignoreKeys = true; } if(this->resultShowingTimer<=0) { this->manager->switchToMenueScene(); } } if(this->showFPS) { char temp[16]; sprintf(temp, "FPS: %f", DXUTGetFPS()); this->manager->printToConsole(temp); this->hud->message(temp, 1.0f, 1.0f); } this->hud->setAmmo(this->player->getAmo()); } void GameScene::initWin() { this->won=true; this->player->initWin(); this->resultVisible = true; this->hud->displayWin(6, 0.01f); this->resultShowingTimer = 6; if(this->happySound) { this->happySound->play(); } } void GameScene::initLose() { this->player->initLose(); this->won = false; this->resultVisible = true; this->hud->displayLose(6, 0.01f); this->resultShowingTimer = 6; if(this->sadSound) { this->sadSound->play(); } } //void GameScene::setBackgroundSound(std::string filename) { // this->bgMusicStream = FSOUND_Stream_Open(filename.c_str(), FSOUND_LOOP_NORMAL, 0, 0); //} // //void GameScene::setBackgroundSoundVolume(float vol) { // this->bgSoundVolume = vol; // if(this->bgSoundChannel!=-1) { // FSOUND_SetVolume(this->bgSoundChannel, (int)(255*this->bgSoundVolume)); // } //} // //void GameScene::playBackgroundSound() { // if(this->bgMusicStream!=NULL) { // this->bgSoundChannel = FSOUND_Stream_Play(FSOUND_FREE, this->bgMusicStream); // FSOUND_SetVolume(this->bgSoundChannel, (int)(255*this->bgSoundVolume)); // } //} void GameScene::connectMaterialIds(int physicId, int xmlId) { //this->materialConnectVector.push_back(temp); this->materialXMLVector.push_back(xmlId); this->materialPhysicVector.push_back(physicId); } int GameScene::getPhysicMaterialId(int xmlId) { for(UINT i=0;imaterialXMLVector.size();i++) { if(this->materialXMLVector.at(i) == xmlId) { return this->materialPhysicVector.at(i); } } return 0; } Bullet* GameScene::cloneBulletFromReference(int type) { Bullet* temp; for(UINT i=0;irefBulletVector.size();i++) { temp = (Bullet*) this->refBulletVector.at(i).get(); if(type == temp->getBulletType()) { return (Bullet*) temp->clone(); } } return NULL; } Weapon* GameScene::cloneWeaponFromReference(int type) { Weapon* temp; for(UINT i=0;irefWeaponVector.size();i++) { temp = (Weapon*) this->refWeaponVector.at(i).get(); if(type == temp->getWeaponType()) { this->manager->printToConsole("GameScene::cloneWeaponFromReference.....clone in weapon initialized?"); return (Weapon*) temp->clone(); } } return NULL; } void GameScene::reduceHealthOnPlayers(Bullet* bullet) { //this->manager->printToConsole("REDUCING HEALTH"); Vector dist; Vector bulletPos; bulletPos = bullet->getAbsolutePosition(); Player* p; float forceFactor; for(UINT i=0;iplayerList.size();i++) { p = bullet->playerList.at(i); dist = p->getAbsolutePosition() - bulletPos; forceFactor = max(0.0f, (bullet->impactRadius - dist.length())/bullet->impactRadius); p->setHealth(p->getHealth()- forceFactor*bullet->impactDamage); } } /*void GameScene::updateSoundNodeVolume() { Scene::updateSoundNodeVolume(); if(this->bgSoundChannel!=-1) { FSOUND_SetVolume(this->bgSoundChannel, (int)(255*this->bgSoundVolume*this->sceneAlpha)); } }*/ float GameScene::getTerrainHeight(Vector v) { NxVec3 direction(0, -1, 0); NxRay ray(v.getNxVector(), direction); NxRaycastHit hit; Vector hv = v; // Get the closest shape NxShape* closestShape = this->pScene->raycastClosestShape(ray, NX_ALL_SHAPES, hit, 0xFFFFFFFF, NX_MAX_F32);//0xffffff); if (closestShape) { hv.y = hit.worldImpact.y; } else { hv.y = 0; } float h = this->terrain->getHeight(v.x, v.z); hv.y = (hv.y>=h) ? hv.y : h; return hv.y; } void GameScene::setChallengeDescription(std::string _description, float _descDuration) { this->descSet = true; this->description = _description; this->descDuration = _descDuration; } void GameScene::setMaxEnemyCount(int maxEnemyCount) { this->maxEnemyCount = maxEnemyCount; } void GameScene::hasWon() { std::list >::iterator it; Player* p; for(it = this->playerList.begin();it!=this->playerList.end();it++) { p = (Player*) (*it).get(); if(p != this->player) { //this->manager->printToConsole("setting health = 0"); p->setHealth(0); } } }