[3618] | 1 | |
---|
| 2 | |
---|
[4592] | 3 | /* |
---|
[3618] | 4 | orxonox - the future of 3D-vertical-scrollers |
---|
| 5 | |
---|
| 6 | Copyright (C) 2004 orx |
---|
| 7 | |
---|
| 8 | This program is free software; you can redistribute it and/or modify |
---|
| 9 | it under the terms of the GNU General Public License as published by |
---|
| 10 | the Free Software Foundation; either version 2, or (at your option) |
---|
| 11 | any later version. |
---|
| 12 | |
---|
| 13 | ### File Specific |
---|
| 14 | main-programmer: Patrick Boenzli |
---|
[4592] | 15 | co-programmer: |
---|
[3631] | 16 | |
---|
| 17 | |
---|
[4836] | 18 | @todo: direction in which the projectile flights |
---|
| 19 | @todo: a target to set/hit |
---|
[3618] | 20 | */ |
---|
| 21 | |
---|
| 22 | |
---|
| 23 | #include "test_gun.h" |
---|
| 24 | |
---|
| 25 | #include "world_entity.h" |
---|
[3677] | 26 | #include "model.h" |
---|
[3710] | 27 | #include "test_bullet.h" |
---|
[3618] | 28 | |
---|
[4829] | 29 | #include "state.h" |
---|
[3618] | 30 | #include "vector.h" |
---|
[3629] | 31 | #include "list.h" |
---|
[3851] | 32 | #include "animation3d.h" |
---|
[4504] | 33 | #include "sound_engine.h" |
---|
[3618] | 34 | |
---|
[4289] | 35 | #include "object_manager.h" |
---|
[4287] | 36 | |
---|
[3618] | 37 | using namespace std; |
---|
| 38 | |
---|
| 39 | |
---|
| 40 | /** |
---|
[4836] | 41 | * standard constructor |
---|
[3618] | 42 | |
---|
| 43 | creates a new weapon |
---|
| 44 | */ |
---|
[4597] | 45 | TestGun::TestGun (PNode* parent, const Vector& coordinate, |
---|
| 46 | const Quaternion& direction, int leftRight) |
---|
[4592] | 47 | : Weapon (parent, coordinate, direction) |
---|
[3683] | 48 | { |
---|
[4320] | 49 | this->setClassID(CL_TEST_GUN, "TestGun"); |
---|
[4597] | 50 | |
---|
[3752] | 51 | this->model = (Model*)ResourceManager::getInstance()->load("models/test_gun.obj", OBJ, RP_CAMPAIGN); |
---|
[3755] | 52 | this->leftRight = leftRight; |
---|
[3752] | 53 | |
---|
[3886] | 54 | this->objectComponent1 = new PNode(); |
---|
[4895] | 55 | Animation3D* animation1 = this->getAnimation(WS_SHOOTING, this->objectComponent1); |
---|
| 56 | Animation3D* animation2 = this->getAnimation(WS_ACTIVATING, this); |
---|
| 57 | Animation3D* animation3 = this->getAnimation(WS_DEACTIVATING, this); |
---|
[3986] | 58 | //parent->addChild(this->objectComponent1, PNODE_ALL); |
---|
| 59 | this->addChild(this->objectComponent1, PNODE_ALL); |
---|
[3755] | 60 | |
---|
[4893] | 61 | animation1->setInfinity(ANIM_INF_CONSTANT); |
---|
| 62 | animation2->setInfinity(ANIM_INF_CONSTANT); |
---|
| 63 | animation3->setInfinity(ANIM_INF_CONSTANT); |
---|
[3886] | 64 | if( this->leftRight == W_LEFT) |
---|
[3755] | 65 | { |
---|
[3888] | 66 | this->projectileOffset = Vector(1.0, 0.0, -0.35); |
---|
| 67 | |
---|
[4893] | 68 | animation1->addKeyFrame(Vector(0, 0, 0), Quaternion(), 0.1, ANIM_LINEAR, ANIM_CONSTANT); |
---|
| 69 | animation1->addKeyFrame(Vector(-0.4, 0, 0), Quaternion(), 0.1, ANIM_LINEAR, ANIM_CONSTANT); |
---|
| 70 | animation1->addKeyFrame(Vector(0, 0, 0), Quaternion(), 0.0, ANIM_LINEAR, ANIM_CONSTANT); |
---|
[3986] | 71 | |
---|
[4906] | 72 | animation2->addKeyFrame(Vector(-2.6, 0.1, 2.0), Quaternion(), 0.3, ANIM_LINEAR, ANIM_CONSTANT); |
---|
| 73 | animation2->addKeyFrame(Vector(-2.6, 0.1, 3.0), Quaternion(), 0.3, ANIM_LINEAR, ANIM_CONSTANT); |
---|
[3986] | 74 | |
---|
[4906] | 75 | animation3->addKeyFrame(Vector(-2.6, 0.1, 3.0), Quaternion(), 0.3, ANIM_LINEAR, ANIM_CONSTANT); |
---|
| 76 | animation3->addKeyFrame(Vector(-2.6, 0.1, 2.0), Quaternion(), 0.3, ANIM_LINEAR, ANIM_CONSTANT); |
---|
[3755] | 77 | } |
---|
[3886] | 78 | else if( this->leftRight == W_RIGHT) |
---|
[3755] | 79 | { |
---|
[3888] | 80 | this->projectileOffset = Vector(1.0, 0.0, 0.5); |
---|
| 81 | |
---|
[3987] | 82 | this->objectComponent1->setRelCoor(Vector(0,0,0.35)); |
---|
[4893] | 83 | animation1->addKeyFrame(Vector(0, 0, .5), Quaternion(), 0.1, ANIM_LINEAR, ANIM_CONSTANT); |
---|
| 84 | animation1->addKeyFrame(Vector(-0.4, 0, .5), Quaternion(), 0.1, ANIM_LINEAR, ANIM_CONSTANT); |
---|
| 85 | animation1->addKeyFrame(Vector(0, 0, .5), Quaternion(), 0.0, ANIM_LINEAR, ANIM_CONSTANT); |
---|
[3986] | 86 | |
---|
[4895] | 87 | animation2->addKeyFrame(Vector(-2.6, 0.1, -2.0), Quaternion(), 0.3, ANIM_LINEAR, ANIM_CONSTANT); |
---|
| 88 | animation2->addKeyFrame(Vector(-2.6, 0.1, -3.0), Quaternion(), 0.3, ANIM_LINEAR, ANIM_CONSTANT); |
---|
[3993] | 89 | |
---|
[4895] | 90 | animation3->addKeyFrame(Vector(-2.6, 0.1, -3.0), Quaternion(), 0.3, ANIM_LINEAR, ANIM_CONSTANT); |
---|
| 91 | animation3->addKeyFrame(Vector(-2.6, 0.1, -2.0), Quaternion(), 0.3, ANIM_LINEAR, ANIM_CONSTANT); |
---|
[3755] | 92 | } |
---|
[4885] | 93 | /* |
---|
[4504] | 94 | this->fireSound = (SoundBuffer*)ResourceManager::getInstance()->load("sound/shot1.wav", WAV); |
---|
| 95 | this->weaponSource = new SoundSource(this->fireSound, this); |
---|
[4885] | 96 | this->weaponSource->setRolloffFactor(.1);*/ |
---|
[4311] | 97 | Projectile* p = new TestBullet(this); |
---|
[4885] | 98 | |
---|
| 99 | // ObjectManager::getInstance()->cache(CL_TEST_BULLET, 100, p); |
---|
[4389] | 100 | //ObjectManager::getInstance()->debug(); |
---|
[4885] | 101 | |
---|
[4906] | 102 | this->setStateDuration(WS_SHOOTING, .4); |
---|
| 103 | this->setStateDuration(WS_RELOADING, 1); |
---|
[4895] | 104 | //this->setStateDuration(WS_ACTIVATING, .4); |
---|
| 105 | //this->setStateDuration(WS_DEACTIVATING, .4); |
---|
[4885] | 106 | |
---|
| 107 | this->energy = 100; |
---|
| 108 | this->minCharge = 2; |
---|
| 109 | |
---|
| 110 | this->setActionSound(WA_SHOOT, "sound/shot1.wav"); |
---|
[3683] | 111 | } |
---|
[3618] | 112 | |
---|
| 113 | |
---|
| 114 | /** |
---|
[4836] | 115 | * standard deconstructor |
---|
[3618] | 116 | */ |
---|
[4592] | 117 | TestGun::~TestGun () |
---|
[3618] | 118 | { |
---|
| 119 | // model will be deleted from WorldEntity-destructor |
---|
| 120 | } |
---|
| 121 | |
---|
| 122 | |
---|
| 123 | /** |
---|
[4836] | 124 | * this activates the weapon |
---|
[3618] | 125 | |
---|
[4592] | 126 | This is needed, since there can be more than one weapon on a ship. the |
---|
| 127 | activation can be connected with an animation. for example the weapon is |
---|
| 128 | been armed out. |
---|
[3618] | 129 | */ |
---|
| 130 | void TestGun::activate() |
---|
[3980] | 131 | { |
---|
| 132 | } |
---|
[3618] | 133 | |
---|
| 134 | |
---|
| 135 | /** |
---|
[4836] | 136 | * this deactivates the weapon |
---|
[3618] | 137 | |
---|
[4592] | 138 | This is needed, since there can be more than one weapon on a ship. the |
---|
| 139 | activation can be connected with an animation. for example the weapon is |
---|
[3618] | 140 | been armed out. |
---|
| 141 | */ |
---|
| 142 | void TestGun::deactivate() |
---|
[3980] | 143 | { |
---|
| 144 | } |
---|
[3618] | 145 | |
---|
| 146 | |
---|
| 147 | /** |
---|
[4836] | 148 | * fires the weapon |
---|
[4592] | 149 | |
---|
[3618] | 150 | this is called from the player.cc, when fire-button is been pushed |
---|
[4836] | 151 | @todo: the ObjectManager deliveres Projectiles not TestBullets! this should be diffrent |
---|
[3618] | 152 | */ |
---|
| 153 | void TestGun::fire() |
---|
[3620] | 154 | { |
---|
[4885] | 155 | Projectile* pj = new TestBullet(this);//dynamic_cast<Projectile*>(ObjectManager::getInstance()->getFromDeadList(CL_TEST_BULLET & CL_MASK_LOWLEVEL_CLASS)); |
---|
| 156 | // weaponSource->play(); |
---|
[3888] | 157 | |
---|
| 158 | pj->setAbsCoor(this->getAbsCoor() + this->projectileOffset); |
---|
[3708] | 159 | pj->setAbsDir(this->getAbsDir()); |
---|
[4464] | 160 | pj->setVelocity(this->getVelocity()); |
---|
[4829] | 161 | State::getWorldEntityList()->add(pj); |
---|
[3620] | 162 | } |
---|
[3618] | 163 | |
---|
| 164 | |
---|
| 165 | /** |
---|
[4836] | 166 | * is called, when the weapon gets hit (=collide with something) |
---|
| 167 | * @param from which entity it is been hit |
---|
| 168 | * @param where it is been hit |
---|
[3618] | 169 | |
---|
| 170 | this may not be used, since it would make the game relay complicated when one |
---|
| 171 | can destroy the weapons of enemies or vice versa. |
---|
| 172 | */ |
---|
[4592] | 173 | void TestGun::hit (WorldEntity* entity, Vector* position) |
---|
[3618] | 174 | {} |
---|
| 175 | |
---|
| 176 | |
---|
| 177 | /** |
---|
[4836] | 178 | * is called, when the weapon is destroyed |
---|
[3618] | 179 | |
---|
| 180 | this is in conjunction with the hit function, so when a weapon is able to get |
---|
| 181 | hit, it can also be destoryed. |
---|
| 182 | */ |
---|
[4592] | 183 | void TestGun::destroy () |
---|
[3618] | 184 | {} |
---|
| 185 | |
---|
| 186 | /** |
---|
[4836] | 187 | * this will draw the weapon |
---|
[3618] | 188 | */ |
---|
[4592] | 189 | void TestGun::draw () |
---|
[3750] | 190 | { |
---|
[3886] | 191 | /* draw gun body */ |
---|
[3750] | 192 | glMatrixMode(GL_MODELVIEW); |
---|
| 193 | glPushMatrix(); |
---|
| 194 | float matrix[4][4]; |
---|
[4592] | 195 | glTranslatef (this->getAbsCoor ().x, |
---|
| 196 | this->getAbsCoor ().y, |
---|
| 197 | this->getAbsCoor ().z); |
---|
[3886] | 198 | this->getAbsDir ().matrix (matrix); |
---|
| 199 | glMultMatrixf((float*)matrix); |
---|
| 200 | if( this->leftRight == W_RIGHT) |
---|
| 201 | glScalef(1.0, 1.0, -1.0); |
---|
| 202 | this->model->draw(1); |
---|
[3752] | 203 | glPopMatrix(); |
---|
| 204 | |
---|
[3886] | 205 | /* draw objectComponent1: gun coil - animated stuff */ |
---|
[3752] | 206 | glMatrixMode(GL_MODELVIEW); |
---|
| 207 | glPushMatrix(); |
---|
[4592] | 208 | glTranslatef (this->objectComponent1->getAbsCoor ().x, |
---|
| 209 | this->objectComponent1->getAbsCoor ().y, |
---|
| 210 | this->objectComponent1->getAbsCoor ().z); |
---|
[3886] | 211 | this->objectComponent1->getAbsDir ().matrix (matrix); |
---|
[3752] | 212 | glMultMatrixf((float*)matrix); |
---|
| 213 | this->model->draw(0); |
---|
[3750] | 214 | glPopMatrix(); |
---|
| 215 | } |
---|
[3618] | 216 | |
---|