source: GTP/trunk/App/Games/Jungle_Rumble/src/SimpleWeapon.cpp @ 1378

Revision 1378, 8.0 KB checked in by giegl, 18 years ago (diff)

GTPD - Jungle Rumble - integrate into GTP SVN structure

Line 
1#include "dxstdafx.h"
2#include ".\simpleweapon.h"
3#include "GameManager.h"
4#include "SimpleBullet.h"
5#include "GameScene.h"
6#include "ParticleEmitter.h"
7#include "ParticleGroup.h"
8#include "Sprite.h"
9#include "Box.h"
10
11SimpleWeapon::SimpleWeapon(void) : Weapon()
12{
13        this->nodeType |= GameScene::NODE_SIMPLEWEAPON;
14        this->fire[0] = NULL;
15        this->fire[1] = NULL;
16        this->ice[0] = NULL;
17        this->ice[1] = NULL;
18        this->leftFire = NULL;
19        this->rightFire = NULL;
20        this->leftIce = NULL;
21        this->rightIce = NULL;
22}
23
24SimpleWeapon::~SimpleWeapon(void)
25{
26}
27
28void SimpleWeapon::initWeapon()
29{
30        this->leftWeapon  = (Object3d*) this->myScene->createNode(this->myScene->NODE_OBJECT3D, *this);
31        this->rightWeapon = (Object3d*) this->myScene->createNode(this->myScene->NODE_OBJECT3D, *this);
32        this->leftWeapon->setPosition(this->leftPos);
33        this->rightWeapon->setPosition(this->rightPos);
34        switch(this->weaponType) {
35                case this->TYPE_MG:
36                        this->leftWeapon->loadMeshFromFile("./media/models/waffe1.x");
37                        this->rightWeapon->loadMeshFromFile("./media/models/waffe1.x");
38                        this->setStateSound(this->STATE_EMPTY, "./media/sound/emptyGun.wav");
39                        this->timeForState[this->STATE_FIRE] = 0.1f;
40                        break;
41                case this->TYPE_BOMB:
42                        this->leftWeapon->loadMeshFromFile("./media/models/waffe2.x");
43                        this->rightWeapon->loadMeshFromFile("./media/models/waffe2.x");
44                        this->timeForState[this->STATE_FIRE] = 0.05f;
45                        this->timeForState[this->STATE_POSTLOAD] = 0.5f;
46                        break;
47                case this->TYPE_ALIEN:
48                        this->leftWeapon->loadMeshFromFile("./media/models/waffe3.x");
49                        this->rightWeapon->loadMeshFromFile("./media/models/waffe3.x");
50                        this->timeForState[this->STATE_FIRE] = 0.05f;
51                        break;
52                case this->TYPE_FIRE:
53                        this->leftWeapon->loadMeshFromFile("./media/models/Flammenwerfer_big.x");
54                        this->rightWeapon->loadMeshFromFile("./media/models/Flammenwerfer_big.x");
55                        this->timeForState[this->STATE_FIRE] = 0.0f;
56                        this->attachFlameEmitter(this->leftWeapon);
57                        this->attachFlameEmitter(this->rightWeapon);
58                        break;
59                case this->TYPE_ICE:
60                        this->leftWeapon->loadMeshFromFile("./media/models/schneekanone.x");
61                        this->rightWeapon->loadMeshFromFile("./media/models/schneekanone.x");
62                        this->timeForState[this->STATE_FIRE] = 0.0f;
63                        this->attachFlameEmitter(this->leftWeapon, false);
64                        this->attachFlameEmitter(this->rightWeapon, false);
65                        break;
66        }
67}
68
69void SimpleWeapon::doFire()
70{
71        //this->myScene->manager->printToConsole("do Fire!!!");
72        if(this->weaponType<this->TYPE_FIRE) {
73                SimpleBullet *leftBullet;
74                SimpleBullet *rightBullet;
75
76                leftBullet = (SimpleBullet *) this->myScene->createNode(((GameScene*)this->myScene)->NODE_SIMPLEBULLET, true);
77                rightBullet = (SimpleBullet *) this->myScene->createNode(((GameScene*)this->myScene)->NODE_SIMPLEBULLET, true);
78                leftBullet->setBulletType(this->weaponType);
79                rightBullet->setBulletType(this->weaponType);
80
81                Vector leftDir;
82                Vector rightDir;
83                Vector zDir(0, 0, 1);
84                this->leftWeapon->getAbsoluteDirectionVector(leftDir, zDir);
85                this->rightWeapon->getAbsoluteDirectionVector(rightDir, zDir);
86                leftDir.normalize();
87                rightDir.normalize();
88               
89                if(leftDir.length()<0.99 || leftDir.length()>1.01)
90                        leftDir.setXYZ(0, 0, 1);
91                if(rightDir.length()<0.99 || rightDir.length()>1.01)
92                        rightDir.setXYZ(0, 0, 1);
93
94                leftBullet->setWeaponDirection(leftDir);
95                rightBullet->setWeaponDirection(rightDir);
96
97                leftBullet->setPlayer(this->player);
98                rightBullet->setPlayer(this->player);
99
100                leftBullet->setTimeToLive(0.2f);
101                rightBullet->setTimeToLive(0.3f);
102
103                Vector temp;
104                this->leftWeapon->getAbsoluteVector(temp, zDir*2);
105                leftBullet->setPosition(temp);
106                this->rightWeapon->getAbsoluteVector(temp, zDir*2);
107                rightBullet->setPosition(temp);
108
109                leftBullet->initBullet();
110                rightBullet->initBullet();
111        } else if(this->weaponType == this->TYPE_FIRE) {
112                if(!this->leftFire->isEmitting()) {
113                        this->leftFire->restartEmitting();
114                        this->rightFire->restartEmitting();
115                }
116        } else if(this->weaponType == this->TYPE_ICE) {
117                if(!this->leftIce->isEmitting()) {
118                        this->leftIce->restartEmitting();
119                        this->rightIce->restartEmitting();
120                }
121        }
122}
123
124Node* SimpleWeapon::clone()
125{
126        SimpleWeapon* sw = (SimpleWeapon*) this->myScene->createNode(GameScene::NODE_SIMPLEWEAPON, *this->father, true);
127        sw->setWeaponType(this->weaponType);
128        sw->initWeapon();
129        return sw;
130}
131
132void SimpleWeapon::calcWorldMatrix(D3DXMATRIX &pMatWorld)
133{
134        Weapon::calcWorldMatrix(pMatWorld);
135        if(this->weaponType==this->TYPE_FIRE || this->TYPE_ICE) {
136                D3DXMATRIXA16 mat;
137                D3DXMATRIXA16 transMat;
138                D3DXMatrixTranslation(&transMat, 0, 0, 3);
139                mat = *this->leftWeapon->getWorldMatrix();
140                D3DXMatrixMultiply(&mat, &transMat, &mat);
141                if(this->leftFire) this->leftFire->setWorldMatrix(mat);
142                if(this->leftIce)
143                        this->leftIce->setWorldMatrix(mat);
144                mat = *this->rightWeapon->getWorldMatrix();
145                D3DXMatrixMultiply(&mat, &transMat, &mat);
146                if(this->rightFire) this->rightFire->setWorldMatrix(mat);
147                if(this->rightIce)
148                        this->rightIce->setWorldMatrix(mat);
149        }
150        this->getAbsoluteVector(this->myAbsPos, Vector(0, 0, 0));
151}
152
153void SimpleWeapon::attachFlameEmitter(Node* node, bool fireEmitter)
154{
155        //Particle impact stuff
156        ParticleGroup* pg = (ParticleGroup*) this->myScene->createNode(Scene::NODE_PARTICLEGROUP, true);
157        if(fireEmitter) {
158                pg->setUseHeatHaze(true);       //Enables HeatHaze for FireParticles!!!
159        }
160       
161        ParticleEmitter* spPE = (ParticleEmitter*) this->myScene->createNode(Scene::NODE_PARTICLEEMITTER);
162        SPTR<Node> sn = this->myScene->getSmartPointer(spPE);
163        pg->useGravity(false);
164        pg->addParticleEmitter(sn);
165        spPE->setPosition(0, 0, 10);
166        spPE->setEMParticleVelocity(50);
167        spPE->setDimensions(0.1f, 0.1f, 0.0f);
168        spPE->setEMHorizontalDegree(0.1f);
169        spPE->setEMVerticalDegree(0.1f);
170        spPE->setEMEmissionDuration(1.0f);
171        spPE->setEMRotationalDegree(0, 0, 150);
172        spPE->setEMBirthRate(100);
173        spPE->setEMParticleLifeTime(0.5);
174        if(fireEmitter) {
175                SoundNode* sn = (SoundNode*) this->myScene->createNode(Scene::NODE_SOUND, spPE);
176                sn->loadFile("./media/sound/flame.wav", true);
177                spPE->addEmittingSound(sn);
178                spPE->setColDetGroup(UserContactReport::COLGROUP_FIRE);
179        } else {
180                spPE->setColDetGroup(UserContactReport::COLGROUP_ICE);
181        }
182        spPE->setDeleteMeAfterEmission(false);
183        spPE->setStandBy(true);
184
185        Sprite *rauch;
186        rauch = (Sprite*) this->myScene->createNode(Scene::NODE_SPRITE, false);
187        rauch->setDimension(3, 3);
188        if(fireEmitter) {
189                rauch->setTexture("./media/textures/particle.png");
190        } else {
191                rauch->setTexture("./media/textures/iceparticle.png");
192        }
193        rauch->setLookAtCamera(true);
194        rauch->setAlpha(0.5f);
195        rauch->getActorDescriptor()->density = 0;
196        rauch->getBodyDescriptor()->mass = 0.001f;
197        rauch->setSphereSizeFactor(0.1f);
198        rauch->generatePhysicMesh();
199        if(fireEmitter) {
200                rauch->setKeyFrame(Sprite::KEY_START, 0.7f, 1, 0.5f, 0.0, 1, 1, 0);
201                rauch->setKeyFrame(Sprite::KEY_MIDDLE, 0.8f, 1, 0.6f, 0.0f, 5, 5, 0.5f);
202                rauch->setKeyFrame(Sprite::KEY_END, 0, 0.5f, 0.5f, 0.5f, 10, 10, 1);
203        } else {
204                rauch->setKeyFrame(Sprite::KEY_START, 0.7f, 0.0, 0.5f, 1.0f, 1, 1, 0);
205                rauch->setKeyFrame(Sprite::KEY_MIDDLE, 0.8f, 0.0, 0.6f, 1.0f, 5, 5, 0.5f);
206                rauch->setKeyFrame(Sprite::KEY_END, 0, 0.5f, 0.5, 0.5f, 10, 10, 1);
207        }
208        rauch->userData = this->player;
209
210        spPE->addRefNode(*rauch);
211        spPE->addRefNode(*rauch);
212        spPE->addRefNode(*rauch);
213
214        if(fireEmitter) {
215                if(!this->fire[0]) {
216                        this->fire[0] = rauch;
217                } else {
218                        this->fire[1] = rauch;
219                }
220                if(node == this->leftWeapon) {
221                        this->leftFire = spPE;
222                } else {
223                        this->rightFire = spPE;
224                }
225        } else {
226                if(!this->ice[0]) {
227                        this->ice[0] = rauch;
228                } else {
229                        this->ice[1] = rauch;
230                }
231                if(node == this->leftWeapon) {
232                        this->leftIce = spPE;
233                } else {
234                        this->rightIce = spPE;
235                }
236        }
237}
238
239void SimpleWeapon::setPlayer(Player &_player)
240{
241        this->player = &_player;
242        for(int i=0;i<2;i++) {
243                if(this->fire[i])
244                        this->fire[i]->userData = this->player;
245                if(this->ice[i])
246                        this->ice[i]->userData = this->player;
247        }
248
249}
Note: See TracBrowser for help on using the repository browser.