[1378] | 1 | #include "dxstdafx.h"
|
---|
| 2 | #include ".\simplebullet.h"
|
---|
| 3 | #include "Object3d.h"
|
---|
| 4 | #include "GameScene.h"
|
---|
| 5 | #include "Player.h"
|
---|
| 6 | #include "Goodie.h"
|
---|
| 7 | #include "GameManager.h"
|
---|
| 8 | #include "UserContactReport.h"
|
---|
| 9 | #include "Terrain.h"
|
---|
| 10 | #include "ParticleEmitter.h"
|
---|
| 11 | #include "ParticleGroup.h"
|
---|
| 12 | #include "Sprite.h"
|
---|
| 13 | #include "Box.h"
|
---|
| 14 | #include "UserContactReport.h"
|
---|
| 15 |
|
---|
| 16 | SimpleBullet::SimpleBullet(void) : Bullet()
|
---|
| 17 | {
|
---|
| 18 | this->filename = "";
|
---|
| 19 | this->speed = -1;
|
---|
| 20 | this->impactForce = -1;
|
---|
| 21 | this->spriteTimer = 0;
|
---|
| 22 | this->nodeType |= GameScene::NODE_SIMPLEBULLET;
|
---|
| 23 | this->bulletObj = NULL;
|
---|
| 24 | }
|
---|
| 25 |
|
---|
| 26 | SimpleBullet::~SimpleBullet(void)
|
---|
| 27 | {
|
---|
| 28 | }
|
---|
| 29 |
|
---|
| 30 | void SimpleBullet::initBullet()
|
---|
| 31 | {
|
---|
| 32 | Vector tempPos;
|
---|
| 33 | tempPos = this->myPosition + this->dir*2;
|
---|
| 34 | this->bulletObj = (Object3d*) ((GameScene*) this->myScene)->createNode(((GameScene*) this->myScene)->NODE_OBJECT3D, *this);
|
---|
| 35 | switch(this->bulletType) {
|
---|
| 36 | case this->TYPE_MG:
|
---|
| 37 | if(this->filename.compare("")==0) {
|
---|
| 38 | this->bulletObj->loadMeshFromFile("./media/models/munition1.x");
|
---|
| 39 | } else {
|
---|
| 40 | this->bulletObj->loadMeshFromFile(this->filename);
|
---|
| 41 | }
|
---|
| 42 | this->setExplodeAtDeath(false);
|
---|
| 43 | this->setTimeToLive(5);
|
---|
| 44 | if(this->speed==-1)
|
---|
| 45 | this->speed = 100;
|
---|
| 46 | if(this->impactForce==-1)
|
---|
| 47 | this->impactForce = 3;
|
---|
| 48 | this->impactRadius = 15;
|
---|
| 49 | this->impactDamage = 20;
|
---|
| 50 | this->createPActor();
|
---|
| 51 |
|
---|
| 52 | this->orientAndMove(this->dir, Vector(0, 1, 0), tempPos, false);
|
---|
| 53 | this->setImpactSound("./media/sound/bomb.wav");
|
---|
| 54 | this->setFlySound("./media/sound/mgFly.wav");
|
---|
| 55 | this->flySound->play();
|
---|
| 56 | break;
|
---|
| 57 | case this->TYPE_BOMB:
|
---|
| 58 | if(this->filename.compare("")==0) {
|
---|
| 59 | this->bulletObj->loadMeshFromFile("./media/models/munition2.x");
|
---|
| 60 | } else {
|
---|
| 61 | this->bulletObj->loadMeshFromFile(this->filename);
|
---|
| 62 | }
|
---|
| 63 | this->setExplodeAtDeath(true);
|
---|
| 64 | this->setTimeToLive(5);
|
---|
| 65 | if(this->speed==-1)
|
---|
| 66 | this->speed = 30;
|
---|
| 67 | if(this->impactForce==-1)
|
---|
| 68 | this->impactForce = 8;
|
---|
| 69 | this->impactRadius = 15;
|
---|
| 70 | this->setImpactSound("./media/sound/bigboom.wav");
|
---|
| 71 | this->createPActor();
|
---|
| 72 | break;
|
---|
| 73 | case this->TYPE_ALIEN:
|
---|
| 74 | if(this->filename.compare("")==0) {
|
---|
| 75 | this->bulletObj->loadMeshFromFile("./media/models/munition3.x");
|
---|
| 76 | } else {
|
---|
| 77 | this->bulletObj->loadMeshFromFile(this->filename);
|
---|
| 78 | }
|
---|
| 79 | this->setExplodeAtDeath(false);
|
---|
| 80 | this->setTimeToLive(10);
|
---|
| 81 | if(this->speed==-1)
|
---|
| 82 | this->speed = 200;
|
---|
| 83 | if(this->impactForce==-1)
|
---|
| 84 | this->impactForce = 2;
|
---|
| 85 | this->impactRadius = 15;
|
---|
| 86 | this->setImpactSound("./media/sound/bomb.wav");
|
---|
| 87 | this->setFlySound("./media/sound/alienFly.wav");
|
---|
| 88 | this->flySound->play();
|
---|
| 89 | this->createPActor();
|
---|
| 90 | this->orientAndMove(this->dir, Vector(0, 1, 0), tempPos, false);
|
---|
| 91 | break;
|
---|
| 92 | }
|
---|
| 93 | this->createParticleEffect();
|
---|
| 94 | }
|
---|
| 95 |
|
---|
| 96 | void SimpleBullet::impactTimeOut()
|
---|
| 97 | {
|
---|
| 98 | if(this->bulletType==this->TYPE_BOMB) {
|
---|
| 99 | this->collectEnvironmentInformation();
|
---|
| 100 | this->setStandardExplosionForces();
|
---|
| 101 | this->impactSound->play();
|
---|
| 102 | if(this->terrainHit) {
|
---|
| 103 | Vector p = this->getAbsolutePosition();
|
---|
| 104 | ((GameScene*) this->myScene)->getTerrain()->impact(p.x, p.z, (int)this->impactForce);
|
---|
| 105 | ((GameScene* )this->myScene)->reduceHealthOnPlayers(this);
|
---|
| 106 | }
|
---|
| 107 | }
|
---|
| 108 | this->killMe();
|
---|
| 109 | }
|
---|
| 110 |
|
---|
| 111 | void SimpleBullet::impactPlayer(Player* player, Vector normal)
|
---|
| 112 | {
|
---|
| 113 | if(player!=this->myPlayer && this->bulletType!=this->TYPE_BOMB) {
|
---|
| 114 | Vector p;
|
---|
| 115 | p = this->getAbsolutePosition();
|
---|
| 116 | this->exploded = true;
|
---|
| 117 | player->setPlayerHit(p, *this);
|
---|
| 118 | if(this->impactSound) {
|
---|
| 119 | this->impactSound->play();
|
---|
| 120 | }
|
---|
| 121 | this->collectEnvironmentInformation();
|
---|
| 122 | this->setStandardExplosionForces();
|
---|
| 123 | ((GameScene* )this->myScene)->reduceHealthOnPlayers(this);
|
---|
| 124 | this->killMe();
|
---|
| 125 | }
|
---|
| 126 | }
|
---|
| 127 |
|
---|
| 128 | void SimpleBullet::impactTerrain(Vector normal)
|
---|
| 129 | {
|
---|
| 130 | Vector p;
|
---|
| 131 | p = this->getAbsolutePosition();
|
---|
| 132 | switch(this->bulletType) {
|
---|
| 133 | case this->TYPE_MG:
|
---|
| 134 | case this->TYPE_ALIEN:
|
---|
| 135 | this->exploded = true;
|
---|
| 136 | ((GameScene*) this->myScene)->getTerrain()->impact(p.x, p.z, (int)this->impactForce);
|
---|
| 137 | p.y = ((GameScene*)this->myScene)->getTerrain()->getHeight(p.x, p.z) - 1;
|
---|
| 138 | if(this->impactSound) {
|
---|
| 139 | this->impactSound->play();
|
---|
| 140 | }
|
---|
| 141 | this->impactNormal = normal;
|
---|
| 142 | this->collectEnvironmentInformation();
|
---|
| 143 | this->setStandardExplosionForces();
|
---|
| 144 | ((GameScene* )this->myScene)->reduceHealthOnPlayers(this);
|
---|
| 145 | this->killMe();
|
---|
| 146 | break;
|
---|
| 147 | }
|
---|
| 148 | }
|
---|
| 149 |
|
---|
| 150 | void SimpleBullet::impactGoodie(Goodie* goodie, Vector normal)
|
---|
| 151 | {
|
---|
| 152 | this->myScene->manager->printToConsole("impactGoodie!!!");
|
---|
| 153 | }
|
---|
| 154 |
|
---|
| 155 | void SimpleBullet::impactOther(Object3d* other, Vector normal)
|
---|
| 156 | {
|
---|
| 157 | Vector p;
|
---|
| 158 | p = this->getAbsolutePosition();
|
---|
| 159 | switch(this->bulletType) {
|
---|
| 160 | case this->TYPE_MG:
|
---|
| 161 | this->exploded = true;
|
---|
| 162 | this->impactSound->play();
|
---|
| 163 | this->collectEnvironmentInformation();
|
---|
| 164 | this->setStandardExplosionForces();
|
---|
| 165 | ((GameScene* )this->myScene)->reduceHealthOnPlayers(this);
|
---|
| 166 | this->killMe();
|
---|
| 167 | break;
|
---|
| 168 | case this->TYPE_BOMB:
|
---|
| 169 | break;
|
---|
| 170 | case this->TYPE_ALIEN:
|
---|
| 171 | this->exploded = true;
|
---|
| 172 | if(this->impactSound) {
|
---|
| 173 | this->impactSound->play();
|
---|
| 174 | }
|
---|
| 175 | this->collectEnvironmentInformation();
|
---|
| 176 | this->setStandardExplosionForces();
|
---|
| 177 | ((GameScene* )this->myScene)->reduceHealthOnPlayers(this);
|
---|
| 178 | this->killMe();
|
---|
| 179 | break;
|
---|
| 180 | }
|
---|
| 181 | }
|
---|
| 182 |
|
---|
| 183 | void SimpleBullet::createPActor()
|
---|
| 184 | {
|
---|
| 185 | Vector temp;
|
---|
| 186 | temp = dir;
|
---|
| 187 | temp.normalize();
|
---|
| 188 | if(temp.length()<0.99 || temp.length()>1.1) {
|
---|
| 189 | temp.setXYZ(0, 0, 1);
|
---|
| 190 | }
|
---|
| 191 | if(this->filename.compare("")!=0) {
|
---|
| 192 | this->bulletObj->generatePhysicMesh(Object3d::COL_CONVEX);
|
---|
| 193 | this->pActorDesc = *this->bulletObj->getActorDescriptor();
|
---|
| 194 | this->setBehaveAs(this->RIGIDBODY);
|
---|
| 195 | temp = temp*this->speed;
|
---|
| 196 | this->pActor->setLinearVelocity(temp.getNxVector());
|
---|
| 197 | this->setColDetGroup(UserContactReport::COLGROUP_BULLET);
|
---|
| 198 | return;
|
---|
| 199 | }
|
---|
| 200 | NxCapsuleShapeDesc capsuleDesc;
|
---|
| 201 | NxSphereShapeDesc sphereDesc;
|
---|
| 202 | Vector rotV(D3DX_PI/2,0,0);
|
---|
| 203 | NxMat34 pose(NxMat33(rotV.getNxQuatRotation()), NxVec3(0, 0, 0));
|
---|
| 204 | switch(this->bulletType) {
|
---|
| 205 | case this->TYPE_MG:
|
---|
| 206 | capsuleDesc.height = (NxReal)3.5;
|
---|
| 207 | capsuleDesc.radius = (NxReal)0.1;
|
---|
| 208 | capsuleDesc.localPose = pose;
|
---|
| 209 | this->pActorDesc.shapes.pushBack(&capsuleDesc);
|
---|
| 210 | this->pActorDesc.density = 10;
|
---|
| 211 | this->setBehaveAs(this->RIGIDBODY);
|
---|
| 212 | temp = temp*this->speed;
|
---|
| 213 | if(this->pActor) {
|
---|
| 214 | this->pActor->setLinearVelocity(temp.getNxVector());
|
---|
| 215 | this->setColDetGroup(UserContactReport::COLGROUP_BULLET);
|
---|
| 216 | }
|
---|
| 217 | break;
|
---|
| 218 | case this->TYPE_BOMB:
|
---|
| 219 | sphereDesc.radius = 0.5f;
|
---|
| 220 | this->pActorDesc.shapes.pushBack(&sphereDesc);
|
---|
| 221 | this->pActorDesc.density = 50;
|
---|
| 222 | this->setBehaveAs(this->RIGIDBODY);
|
---|
| 223 | temp = temp*this->speed;
|
---|
| 224 | if(this->pActor) {
|
---|
| 225 | this->pActor->setLinearVelocity(temp.getNxVector());
|
---|
| 226 | this->setColDetGroup(UserContactReport::COLGROUP_BULLET);
|
---|
| 227 | }
|
---|
| 228 | break;
|
---|
| 229 | case this->TYPE_ALIEN:
|
---|
| 230 | capsuleDesc.height = 2.5f;
|
---|
| 231 | capsuleDesc.radius = 0.2f;
|
---|
| 232 | capsuleDesc.localPose = pose;
|
---|
| 233 | this->pActorDesc.shapes.pushBack(&capsuleDesc);
|
---|
| 234 | this->pActorDesc.density = 0.5;
|
---|
| 235 | this->setBehaveAs(this->RIGIDBODY);
|
---|
| 236 | temp = temp*this->speed;
|
---|
| 237 | if(this->pActor) {
|
---|
| 238 | this->pActor->setLinearVelocity(temp.getNxVector());
|
---|
| 239 | this->setColDetGroup(UserContactReport::COLGROUP_BULLET);
|
---|
| 240 | this->pActor->raiseBodyFlag(NX_BF_DISABLE_GRAVITY);
|
---|
| 241 | }
|
---|
| 242 | break;
|
---|
| 243 | }
|
---|
| 244 | }
|
---|
| 245 |
|
---|
| 246 | void SimpleBullet::update(float dt)
|
---|
| 247 | {
|
---|
| 248 |
|
---|
| 249 | this->spriteTimer+=dt;
|
---|
| 250 | if(this->spriteTimer>0.08f) {
|
---|
| 251 | this->spriteTimer = 0;
|
---|
| 252 | Sprite *rauch;
|
---|
| 253 | rauch = (Sprite*) this->myScene->createNode(Scene::NODE_SPRITE);
|
---|
| 254 | rauch->setDimension(3, 3);
|
---|
| 255 | rauch->setTexture("./media/textures/explosion.png");
|
---|
| 256 | rauch->setFPS(64);
|
---|
| 257 | rauch->setTimeToLive(1);
|
---|
| 258 | rauch->setRowColumnCount(8, 8);
|
---|
| 259 | rauch->setFrameCount(64);
|
---|
| 260 | rauch->setLoopAnimation(true);
|
---|
| 261 | rauch->setLookAtCamera(true);
|
---|
| 262 | rauch->setAlpha(0.5f);
|
---|
| 263 | rauch->setPosition(this->getAbsolutePosition());
|
---|
| 264 | }
|
---|
| 265 | Bullet::update(dt);
|
---|
| 266 | }
|
---|
| 267 |
|
---|
| 268 | Node* SimpleBullet::clone()
|
---|
| 269 | {
|
---|
| 270 | SimpleBullet* sb = (SimpleBullet*) this->myScene->createNode(GameScene::NODE_SIMPLEBULLET, *this->father, true);
|
---|
| 271 | sb->setBulletType(this->bulletType);
|
---|
| 272 | sb->initBullet();
|
---|
| 273 | return sb;
|
---|
| 274 | }
|
---|
| 275 |
|
---|
| 276 | void SimpleBullet::setXFile(std::string _filename)
|
---|
| 277 | {
|
---|
| 278 | this->filename = _filename;
|
---|
| 279 | }
|
---|
| 280 |
|
---|
| 281 | void SimpleBullet::setSpeed(float _speed)
|
---|
| 282 | {
|
---|
| 283 | this->speed = _speed;
|
---|
| 284 | }
|
---|
| 285 |
|
---|
| 286 | void SimpleBullet::createParticleEffect()
|
---|
| 287 | {
|
---|
| 288 | //Particle impact stuff
|
---|
| 289 | ParticleGroup* pg = (ParticleGroup*) this->myScene->createNode(Scene::NODE_PARTICLEGROUP, true);
|
---|
| 290 | ParticleEmitter* spPE = (ParticleEmitter*) this->myScene->createNode(Scene::NODE_PARTICLEEMITTER);
|
---|
| 291 | SPTR<Node> sn = this->myScene->getSmartPointer(spPE);
|
---|
| 292 | pg->addParticleEmitter(sn);
|
---|
| 293 | spPE->setPosition(this->getAbsolutePosition());
|
---|
| 294 | spPE->setEMEmissionDuration(0.2f);
|
---|
| 295 | spPE->setEMRotationalDegree(0, 0, 150);
|
---|
| 296 | spPE->setDimensions(this->impactForce, this->impactForce, 0);
|
---|
| 297 | spPE->setEMParticleVelocity(this->impactForce*6);
|
---|
| 298 | spPE->setEMHorizontalDegree(0.3f);
|
---|
| 299 | spPE->setEMVerticalDegree(0.3f);
|
---|
| 300 | spPE->setEMBirthRate(25);
|
---|
| 301 | spPE->setEMParticleLifeTime(1.5f);
|
---|
| 302 | spPE->setRotation(-D3DX_PI/2, 0, 0);
|
---|
| 303 | spPE->setColDetGroup(UserContactReport::COLGROUP_NOCOL);
|
---|
| 304 | spPE->setDeleteMeAfterEmission(true);
|
---|
| 305 | spPE->setStandBy(true);
|
---|
| 306 |
|
---|
| 307 | Sprite *fire;
|
---|
| 308 | fire = (Sprite*) this->myScene->createNode(Scene::NODE_SPRITE);
|
---|
| 309 | fire->setDimension(4, 4);
|
---|
| 310 | fire->setTexture("./media/textures/rauch.bmp");
|
---|
| 311 | fire->setLookAtCamera(true);
|
---|
| 312 | fire->setAlpha(0.5f);
|
---|
| 313 | fire->generatePhysicMesh();
|
---|
| 314 | fire->setKeyFrame(Sprite::KEY_START, 1, 1, 0, 0, 4, 4, 0);
|
---|
| 315 | fire->setKeyFrame(Sprite::KEY_MIDDLE, 1, 1, 0.5, 0.5, 8, 8, 0.5);
|
---|
| 316 | fire->setKeyFrame(Sprite::KEY_END, 0, 1, 1, 1, 10, 10, 1);
|
---|
| 317 |
|
---|
| 318 | Sprite *fire3;
|
---|
| 319 | fire3 = (Sprite*) this->myScene->createNode(Scene::NODE_SPRITE);
|
---|
| 320 | fire3->setDimension(2, 2);
|
---|
| 321 | fire3->setTexture("./media/textures/explosion.png");
|
---|
| 322 | fire3->setLookAtCamera(true);
|
---|
| 323 | fire3->setAlpha(0.5f);
|
---|
| 324 | fire3->generatePhysicMesh();
|
---|
| 325 | fire3->setFPS(43);
|
---|
| 326 | fire3->setRowColumnCount(8, 8);
|
---|
| 327 | fire3->setFrameCount(64);
|
---|
| 328 | fire3->setLoopAnimation(true);
|
---|
| 329 | fire3->setKeyFrame(Sprite::KEY_START, 1, 1, 0, 0, 4, 4, 0);
|
---|
| 330 | fire3->setKeyFrame(Sprite::KEY_MIDDLE, 1, 1, 0.5, 0.5, 8, 8, 0.5);
|
---|
| 331 | fire3->setKeyFrame(Sprite::KEY_END, 0, 1, 1, 1, 10, 10, 1);
|
---|
| 332 |
|
---|
| 333 | spPE->addRefNode(*fire);
|
---|
| 334 | spPE->addRefNode(*fire);
|
---|
| 335 | spPE->addRefNode(*fire3);
|
---|
| 336 | spPE->addRefNode(*fire);
|
---|
| 337 | spPE->addRefNode(*fire3);
|
---|
| 338 |
|
---|
| 339 | this->addParticleEmitter(spPE);
|
---|
| 340 | }
|
---|
| 341 |
|
---|
| 342 | void SimpleBullet::killMe()
|
---|
| 343 | {
|
---|
| 344 | if(this->bulletObj) {
|
---|
| 345 | this->bulletObj->killMe();
|
---|
| 346 | }
|
---|
| 347 | Bullet::killMe();
|
---|
| 348 | } |
---|