#include "dxstdafx.h" #include ".\simplebullet.h" #include "Object3d.h" #include "GameScene.h" #include "Player.h" #include "Goodie.h" #include "GameManager.h" #include "UserContactReport.h" #include "Terrain.h" #include "ParticleEmitter.h" #include "ParticleGroup.h" #include "Sprite.h" #include "Box.h" #include "UserContactReport.h" SimpleBullet::SimpleBullet(void) : Bullet() { this->filename = ""; this->speed = -1; this->impactForce = -1; this->spriteTimer = 0; this->nodeType |= GameScene::NODE_SIMPLEBULLET; this->bulletObj = NULL; } SimpleBullet::~SimpleBullet(void) { } void SimpleBullet::initBullet() { Vector tempPos; tempPos = this->myPosition + this->dir*2; this->bulletObj = (Object3d*) ((GameScene*) this->myScene)->createNode(((GameScene*) this->myScene)->NODE_OBJECT3D, *this); switch(this->bulletType) { case this->TYPE_MG: if(this->filename.compare("")==0) { this->bulletObj->loadMeshFromFile("./media/models/munition1.x"); } else { this->bulletObj->loadMeshFromFile(this->filename); } this->setExplodeAtDeath(false); this->setTimeToLive(5); if(this->speed==-1) this->speed = 100; if(this->impactForce==-1) this->impactForce = 3; this->impactRadius = 15; this->impactDamage = 20; this->createPActor(); this->orientAndMove(this->dir, Vector(0, 1, 0), tempPos, false); this->setImpactSound("./media/sound/bomb.wav"); this->setFlySound("./media/sound/mgFly.wav"); this->flySound->play(); break; case this->TYPE_BOMB: if(this->filename.compare("")==0) { this->bulletObj->loadMeshFromFile("./media/models/munition2.x"); } else { this->bulletObj->loadMeshFromFile(this->filename); } this->setExplodeAtDeath(true); this->setTimeToLive(5); if(this->speed==-1) this->speed = 30; if(this->impactForce==-1) this->impactForce = 8; this->impactRadius = 15; this->setImpactSound("./media/sound/bigboom.wav"); this->createPActor(); break; case this->TYPE_ALIEN: if(this->filename.compare("")==0) { this->bulletObj->loadMeshFromFile("./media/models/munition3.x"); } else { this->bulletObj->loadMeshFromFile(this->filename); } this->setExplodeAtDeath(false); this->setTimeToLive(10); if(this->speed==-1) this->speed = 200; if(this->impactForce==-1) this->impactForce = 2; this->impactRadius = 15; this->setImpactSound("./media/sound/bomb.wav"); this->setFlySound("./media/sound/alienFly.wav"); this->flySound->play(); this->createPActor(); this->orientAndMove(this->dir, Vector(0, 1, 0), tempPos, false); break; } this->createParticleEffect(); } void SimpleBullet::impactTimeOut() { if(this->bulletType==this->TYPE_BOMB) { this->collectEnvironmentInformation(); this->setStandardExplosionForces(); this->impactSound->play(); if(this->terrainHit) { Vector p = this->getAbsolutePosition(); ((GameScene*) this->myScene)->getTerrain()->impact(p.x, p.z, (int)this->impactForce); ((GameScene* )this->myScene)->reduceHealthOnPlayers(this); } } this->killMe(); } void SimpleBullet::impactPlayer(Player* player, Vector normal) { if(player!=this->myPlayer && this->bulletType!=this->TYPE_BOMB) { Vector p; p = this->getAbsolutePosition(); this->exploded = true; player->setPlayerHit(p, *this); if(this->impactSound) { this->impactSound->play(); } this->collectEnvironmentInformation(); this->setStandardExplosionForces(); ((GameScene* )this->myScene)->reduceHealthOnPlayers(this); this->killMe(); } } void SimpleBullet::impactTerrain(Vector normal) { Vector p; p = this->getAbsolutePosition(); switch(this->bulletType) { case this->TYPE_MG: case this->TYPE_ALIEN: this->exploded = true; ((GameScene*) this->myScene)->getTerrain()->impact(p.x, p.z, (int)this->impactForce); p.y = ((GameScene*)this->myScene)->getTerrain()->getHeight(p.x, p.z) - 1; if(this->impactSound) { this->impactSound->play(); } this->impactNormal = normal; this->collectEnvironmentInformation(); this->setStandardExplosionForces(); ((GameScene* )this->myScene)->reduceHealthOnPlayers(this); this->killMe(); break; } } void SimpleBullet::impactGoodie(Goodie* goodie, Vector normal) { this->myScene->manager->printToConsole("impactGoodie!!!"); } void SimpleBullet::impactOther(Object3d* other, Vector normal) { Vector p; p = this->getAbsolutePosition(); switch(this->bulletType) { case this->TYPE_MG: this->exploded = true; this->impactSound->play(); this->collectEnvironmentInformation(); this->setStandardExplosionForces(); ((GameScene* )this->myScene)->reduceHealthOnPlayers(this); this->killMe(); break; case this->TYPE_BOMB: break; case this->TYPE_ALIEN: this->exploded = true; if(this->impactSound) { this->impactSound->play(); } this->collectEnvironmentInformation(); this->setStandardExplosionForces(); ((GameScene* )this->myScene)->reduceHealthOnPlayers(this); this->killMe(); break; } } void SimpleBullet::createPActor() { Vector temp; temp = dir; temp.normalize(); if(temp.length()<0.99 || temp.length()>1.1) { temp.setXYZ(0, 0, 1); } if(this->filename.compare("")!=0) { this->bulletObj->generatePhysicMesh(Object3d::COL_CONVEX); this->pActorDesc = *this->bulletObj->getActorDescriptor(); this->setBehaveAs(this->RIGIDBODY); temp = temp*this->speed; this->pActor->setLinearVelocity(temp.getNxVector()); this->setColDetGroup(UserContactReport::COLGROUP_BULLET); return; } NxCapsuleShapeDesc capsuleDesc; NxSphereShapeDesc sphereDesc; Vector rotV(D3DX_PI/2,0,0); NxMat34 pose(NxMat33(rotV.getNxQuatRotation()), NxVec3(0, 0, 0)); switch(this->bulletType) { case this->TYPE_MG: capsuleDesc.height = (NxReal)3.5; capsuleDesc.radius = (NxReal)0.1; capsuleDesc.localPose = pose; this->pActorDesc.shapes.pushBack(&capsuleDesc); this->pActorDesc.density = 10; this->setBehaveAs(this->RIGIDBODY); temp = temp*this->speed; if(this->pActor) { this->pActor->setLinearVelocity(temp.getNxVector()); this->setColDetGroup(UserContactReport::COLGROUP_BULLET); } break; case this->TYPE_BOMB: sphereDesc.radius = 0.5f; this->pActorDesc.shapes.pushBack(&sphereDesc); this->pActorDesc.density = 50; this->setBehaveAs(this->RIGIDBODY); temp = temp*this->speed; if(this->pActor) { this->pActor->setLinearVelocity(temp.getNxVector()); this->setColDetGroup(UserContactReport::COLGROUP_BULLET); } break; case this->TYPE_ALIEN: capsuleDesc.height = 2.5f; capsuleDesc.radius = 0.2f; capsuleDesc.localPose = pose; this->pActorDesc.shapes.pushBack(&capsuleDesc); this->pActorDesc.density = 0.5; this->setBehaveAs(this->RIGIDBODY); temp = temp*this->speed; if(this->pActor) { this->pActor->setLinearVelocity(temp.getNxVector()); this->setColDetGroup(UserContactReport::COLGROUP_BULLET); this->pActor->raiseBodyFlag(NX_BF_DISABLE_GRAVITY); } break; } } void SimpleBullet::update(float dt) { this->spriteTimer+=dt; if(this->spriteTimer>0.08f) { this->spriteTimer = 0; Sprite *rauch; rauch = (Sprite*) this->myScene->createNode(Scene::NODE_SPRITE); rauch->setDimension(3, 3); rauch->setTexture("./media/textures/explosion.png"); rauch->setFPS(64); rauch->setTimeToLive(1); rauch->setRowColumnCount(8, 8); rauch->setFrameCount(64); rauch->setLoopAnimation(true); rauch->setLookAtCamera(true); rauch->setAlpha(0.5f); rauch->setPosition(this->getAbsolutePosition()); } Bullet::update(dt); } Node* SimpleBullet::clone() { SimpleBullet* sb = (SimpleBullet*) this->myScene->createNode(GameScene::NODE_SIMPLEBULLET, *this->father, true); sb->setBulletType(this->bulletType); sb->initBullet(); return sb; } void SimpleBullet::setXFile(std::string _filename) { this->filename = _filename; } void SimpleBullet::setSpeed(float _speed) { this->speed = _speed; } void SimpleBullet::createParticleEffect() { //Particle impact stuff ParticleGroup* pg = (ParticleGroup*) this->myScene->createNode(Scene::NODE_PARTICLEGROUP, true); ParticleEmitter* spPE = (ParticleEmitter*) this->myScene->createNode(Scene::NODE_PARTICLEEMITTER); SPTR sn = this->myScene->getSmartPointer(spPE); pg->addParticleEmitter(sn); spPE->setPosition(this->getAbsolutePosition()); spPE->setEMEmissionDuration(0.2f); spPE->setEMRotationalDegree(0, 0, 150); spPE->setDimensions(this->impactForce, this->impactForce, 0); spPE->setEMParticleVelocity(this->impactForce*6); spPE->setEMHorizontalDegree(0.3f); spPE->setEMVerticalDegree(0.3f); spPE->setEMBirthRate(25); spPE->setEMParticleLifeTime(1.5f); spPE->setRotation(-D3DX_PI/2, 0, 0); spPE->setColDetGroup(UserContactReport::COLGROUP_NOCOL); spPE->setDeleteMeAfterEmission(true); spPE->setStandBy(true); Sprite *fire; fire = (Sprite*) this->myScene->createNode(Scene::NODE_SPRITE); fire->setDimension(4, 4); fire->setTexture("./media/textures/rauch.bmp"); fire->setLookAtCamera(true); fire->setAlpha(0.5f); fire->generatePhysicMesh(); fire->setKeyFrame(Sprite::KEY_START, 1, 1, 0, 0, 4, 4, 0); fire->setKeyFrame(Sprite::KEY_MIDDLE, 1, 1, 0.5, 0.5, 8, 8, 0.5); fire->setKeyFrame(Sprite::KEY_END, 0, 1, 1, 1, 10, 10, 1); Sprite *fire3; fire3 = (Sprite*) this->myScene->createNode(Scene::NODE_SPRITE); fire3->setDimension(2, 2); fire3->setTexture("./media/textures/explosion.png"); fire3->setLookAtCamera(true); fire3->setAlpha(0.5f); fire3->generatePhysicMesh(); fire3->setFPS(43); fire3->setRowColumnCount(8, 8); fire3->setFrameCount(64); fire3->setLoopAnimation(true); fire3->setKeyFrame(Sprite::KEY_START, 1, 1, 0, 0, 4, 4, 0); fire3->setKeyFrame(Sprite::KEY_MIDDLE, 1, 1, 0.5, 0.5, 8, 8, 0.5); fire3->setKeyFrame(Sprite::KEY_END, 0, 1, 1, 1, 10, 10, 1); spPE->addRefNode(*fire); spPE->addRefNode(*fire); spPE->addRefNode(*fire3); spPE->addRefNode(*fire); spPE->addRefNode(*fire3); this->addParticleEmitter(spPE); } void SimpleBullet::killMe() { if(this->bulletObj) { this->bulletObj->killMe(); } Bullet::killMe(); }