[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 | */ |
---|
[5357] | 21 | #define DEBUG_SPECIAL_MODULE DEBUG_MODULE_WEAPON |
---|
[3618] | 22 | |
---|
| 23 | #include "test_gun.h" |
---|
| 24 | |
---|
| 25 | #include "world_entity.h" |
---|
[3677] | 26 | #include "model.h" |
---|
[3710] | 27 | #include "test_bullet.h" |
---|
[4955] | 28 | #include "weapon_manager.h" |
---|
[5355] | 29 | #include "factory.h" |
---|
[3618] | 30 | |
---|
| 31 | #include "vector.h" |
---|
[3629] | 32 | #include "list.h" |
---|
[3851] | 33 | #include "animation3d.h" |
---|
[4504] | 34 | #include "sound_engine.h" |
---|
[3618] | 35 | |
---|
[4979] | 36 | #include "null_parent.h" |
---|
| 37 | |
---|
[4940] | 38 | #include "fast_factory.h" |
---|
[4287] | 39 | |
---|
[4931] | 40 | |
---|
[3618] | 41 | using namespace std; |
---|
| 42 | |
---|
[5750] | 43 | CREATE_FACTORY(TestGun, CL_TEST_GUN); |
---|
[3618] | 44 | |
---|
| 45 | /** |
---|
[4836] | 46 | * standard constructor |
---|
[3618] | 47 | |
---|
| 48 | creates a new weapon |
---|
| 49 | */ |
---|
[5750] | 50 | TestGun::TestGun ( int leftRight) |
---|
| 51 | : Weapon() |
---|
[3683] | 52 | { |
---|
[4974] | 53 | this->init(); |
---|
| 54 | |
---|
| 55 | |
---|
[3755] | 56 | this->leftRight = leftRight; |
---|
[3752] | 57 | |
---|
[3886] | 58 | this->objectComponent1 = new PNode(); |
---|
[4895] | 59 | Animation3D* animation1 = this->getAnimation(WS_SHOOTING, this->objectComponent1); |
---|
| 60 | Animation3D* animation2 = this->getAnimation(WS_ACTIVATING, this); |
---|
| 61 | Animation3D* animation3 = this->getAnimation(WS_DEACTIVATING, this); |
---|
[3986] | 62 | //parent->addChild(this->objectComponent1, PNODE_ALL); |
---|
[5382] | 63 | this->addChild(this->objectComponent1); |
---|
[3755] | 64 | |
---|
[4893] | 65 | animation1->setInfinity(ANIM_INF_CONSTANT); |
---|
| 66 | animation2->setInfinity(ANIM_INF_CONSTANT); |
---|
| 67 | animation3->setInfinity(ANIM_INF_CONSTANT); |
---|
[4972] | 68 | |
---|
[3886] | 69 | if( this->leftRight == W_LEFT) |
---|
[4972] | 70 | { |
---|
[5459] | 71 | this->setEmissionPoint(1.0, -0.6, -0.2); |
---|
[3888] | 72 | |
---|
[5062] | 73 | animation1->addKeyFrame(Vector(0, 0, 0), Quaternion(), 0.1, ANIM_LINEAR, ANIM_NULL); |
---|
| 74 | animation1->addKeyFrame(Vector(-0.4, 0, 0), Quaternion(), 0.1, ANIM_LINEAR, ANIM_NULL); |
---|
| 75 | animation1->addKeyFrame(Vector(0, 0, 0), Quaternion(), 0.0, ANIM_LINEAR, ANIM_NULL); |
---|
[3986] | 76 | |
---|
[5062] | 77 | animation2->addKeyFrame(Vector(0.0, 0.0, -1.0), Quaternion(), 0.3, ANIM_LINEAR, ANIM_NULL); |
---|
| 78 | animation2->addKeyFrame(Vector(0.0, 0.0, 0.0), Quaternion(), 0.3, ANIM_LINEAR, ANIM_NULL); |
---|
[3986] | 79 | |
---|
[5062] | 80 | animation3->addKeyFrame(Vector(0.0, 0.0, 0.0), Quaternion(), 0.3, ANIM_LINEAR, ANIM_NULL); |
---|
| 81 | animation3->addKeyFrame(Vector(0.0, 0.0, -1.0), Quaternion(), 0.3, ANIM_LINEAR, ANIM_NULL); |
---|
[4972] | 82 | } |
---|
[3886] | 83 | else if( this->leftRight == W_RIGHT) |
---|
[4972] | 84 | { |
---|
[5459] | 85 | this->setEmissionPoint(1.0, -0.6, 0.3); |
---|
[3888] | 86 | |
---|
[4972] | 87 | this->objectComponent1->setRelCoor(Vector(0,0,0.35)); |
---|
[5062] | 88 | animation1->addKeyFrame(Vector(0, 0, .5), Quaternion(), 0.1, ANIM_LINEAR, ANIM_NULL); |
---|
| 89 | animation1->addKeyFrame(Vector(-0.4, 0, .5), Quaternion(), 0.1, ANIM_LINEAR, ANIM_NULL); |
---|
| 90 | animation1->addKeyFrame(Vector(0, 0, .5), Quaternion(), 0.0, ANIM_LINEAR, ANIM_NULL); |
---|
[3986] | 91 | |
---|
[5062] | 92 | animation2->addKeyFrame(Vector(.0, .0, 1.0), Quaternion(), 0.3, ANIM_LINEAR, ANIM_NULL); |
---|
| 93 | animation2->addKeyFrame(Vector(.0, .0, .0), Quaternion(), 0.3, ANIM_LINEAR, ANIM_NULL); |
---|
[3993] | 94 | |
---|
[5062] | 95 | animation3->addKeyFrame(Vector(.0, .0, 0.0), Quaternion(), 0.3, ANIM_LINEAR, ANIM_NULL); |
---|
| 96 | animation3->addKeyFrame(Vector(.0, .0, 1.0), Quaternion(), 0.3, ANIM_LINEAR, ANIM_NULL); |
---|
[4972] | 97 | } |
---|
| 98 | } |
---|
[4885] | 99 | |
---|
| 100 | |
---|
[4972] | 101 | TestGun::TestGun(const TiXmlElement* root) |
---|
| 102 | { |
---|
| 103 | this->init(); |
---|
| 104 | this->loadParams(root); |
---|
| 105 | } |
---|
| 106 | |
---|
| 107 | /** |
---|
| 108 | * standard deconstructor |
---|
| 109 | */ |
---|
| 110 | TestGun::~TestGun () |
---|
| 111 | { |
---|
| 112 | // model will be deleted from WorldEntity-destructor |
---|
| 113 | } |
---|
| 114 | |
---|
| 115 | |
---|
| 116 | void TestGun::init() |
---|
| 117 | { |
---|
| 118 | this->setClassID(CL_TEST_GUN, "TestGun"); |
---|
| 119 | |
---|
[5053] | 120 | // this->model = (Model*)ResourceManager::getInstance()->load("models/guns/test_gun.obj", OBJ, RP_CAMPAIGN); |
---|
[4972] | 121 | |
---|
[5053] | 122 | this->loadModel("models/guns/test_gun.obj"); |
---|
| 123 | |
---|
[5457] | 124 | this->setStateDuration(WS_SHOOTING, .1); |
---|
| 125 | this->setStateDuration(WS_RELOADING, .1); |
---|
[4910] | 126 | this->setStateDuration(WS_ACTIVATING, .4); |
---|
| 127 | this->setStateDuration(WS_DEACTIVATING, .4); |
---|
[4885] | 128 | |
---|
[5048] | 129 | this->setMaximumEnergy(1000, 100); |
---|
| 130 | this->increaseEnergy(1000); |
---|
[4927] | 131 | //this->minCharge = 2; |
---|
[4885] | 132 | |
---|
[5819] | 133 | this->setActionSound(WA_SHOOT, "sound/laser.wav"); |
---|
| 134 | this->setActionSound(WA_ACTIVATE, "sound/voices/lasers.wav"); |
---|
[4934] | 135 | |
---|
[5819] | 136 | |
---|
[5441] | 137 | this->setCapability(WTYPE_ALLDIRS | WTYPE_DIRECTIONAL); |
---|
[5456] | 138 | this->setProjectileType(CL_LASER); |
---|
[5356] | 139 | this->prepareProjectiles(20); |
---|
[5457] | 140 | |
---|
[3683] | 141 | } |
---|
[3618] | 142 | |
---|
| 143 | |
---|
[4972] | 144 | void TestGun::loadParams(const TiXmlElement* root) |
---|
[3618] | 145 | { |
---|
[4972] | 146 | |
---|
| 147 | |
---|
[3618] | 148 | } |
---|
| 149 | |
---|
| 150 | |
---|
| 151 | /** |
---|
[4836] | 152 | * this activates the weapon |
---|
[3618] | 153 | |
---|
[4592] | 154 | This is needed, since there can be more than one weapon on a ship. the |
---|
| 155 | activation can be connected with an animation. for example the weapon is |
---|
| 156 | been armed out. |
---|
[3618] | 157 | */ |
---|
| 158 | void TestGun::activate() |
---|
[3980] | 159 | { |
---|
| 160 | } |
---|
[3618] | 161 | |
---|
| 162 | |
---|
| 163 | /** |
---|
[4836] | 164 | * this deactivates the weapon |
---|
[3618] | 165 | |
---|
[4592] | 166 | This is needed, since there can be more than one weapon on a ship. the |
---|
| 167 | activation can be connected with an animation. for example the weapon is |
---|
[3618] | 168 | been armed out. |
---|
| 169 | */ |
---|
| 170 | void TestGun::deactivate() |
---|
[3980] | 171 | { |
---|
| 172 | } |
---|
[3618] | 173 | |
---|
| 174 | |
---|
| 175 | /** |
---|
[4836] | 176 | * fires the weapon |
---|
[4592] | 177 | |
---|
[3618] | 178 | this is called from the player.cc, when fire-button is been pushed |
---|
[4836] | 179 | @todo: the ObjectManager deliveres Projectiles not TestBullets! this should be diffrent |
---|
[3618] | 180 | */ |
---|
| 181 | void TestGun::fire() |
---|
[3620] | 182 | { |
---|
[5356] | 183 | Projectile* pj = this->getProjectile(); |
---|
| 184 | if (pj == NULL) |
---|
| 185 | return; |
---|
[3888] | 186 | |
---|
[4979] | 187 | pj->setParent(NullParent::getInstance()); |
---|
[5000] | 188 | |
---|
[5462] | 189 | pj->setVelocity(this->getVelocity() + this->getAbsDir().apply(Vector(1,0,0))*50+VECTOR_RAND(5)); |
---|
[4955] | 190 | |
---|
[4927] | 191 | pj->setAbsCoor(this->getEmissionPoint()); |
---|
[3708] | 192 | pj->setAbsDir(this->getAbsDir()); |
---|
[5443] | 193 | pj->activate(); |
---|
[3620] | 194 | } |
---|
[3618] | 195 | |
---|
| 196 | /** |
---|
[4836] | 197 | * is called, when the weapon is destroyed |
---|
[5498] | 198 | * |
---|
| 199 | * this is in conjunction with the hit function, so when a weapon is able to get |
---|
| 200 | * hit, it can also be destoryed. |
---|
[3618] | 201 | */ |
---|
[4592] | 202 | void TestGun::destroy () |
---|
[3618] | 203 | {} |
---|
| 204 | |
---|
| 205 | /** |
---|
[4836] | 206 | * this will draw the weapon |
---|
[3618] | 207 | */ |
---|
[5500] | 208 | void TestGun::draw () const |
---|
[3750] | 209 | { |
---|
[3886] | 210 | /* draw gun body */ |
---|
[3750] | 211 | glMatrixMode(GL_MODELVIEW); |
---|
| 212 | glPushMatrix(); |
---|
[4592] | 213 | glTranslatef (this->getAbsCoor ().x, |
---|
| 214 | this->getAbsCoor ().y, |
---|
| 215 | this->getAbsCoor ().z); |
---|
[5000] | 216 | |
---|
| 217 | Vector tmpRot = this->getAbsDir().getSpacialAxis(); |
---|
| 218 | glRotatef (this->getAbsDir().getSpacialAxisAngle(), tmpRot.x, tmpRot.y, tmpRot.z ); |
---|
| 219 | |
---|
[3886] | 220 | if( this->leftRight == W_RIGHT) |
---|
| 221 | glScalef(1.0, 1.0, -1.0); |
---|
| 222 | this->model->draw(1); |
---|
[3752] | 223 | glPopMatrix(); |
---|
| 224 | |
---|
[3886] | 225 | /* draw objectComponent1: gun coil - animated stuff */ |
---|
[3752] | 226 | glMatrixMode(GL_MODELVIEW); |
---|
| 227 | glPushMatrix(); |
---|
[4592] | 228 | glTranslatef (this->objectComponent1->getAbsCoor ().x, |
---|
| 229 | this->objectComponent1->getAbsCoor ().y, |
---|
| 230 | this->objectComponent1->getAbsCoor ().z); |
---|
[5000] | 231 | tmpRot = this->objectComponent1->getAbsDir().getSpacialAxis(); |
---|
| 232 | glRotatef (this->objectComponent1->getAbsDir().getSpacialAxisAngle(), tmpRot.x, tmpRot.y, tmpRot.z ); |
---|
[3752] | 233 | this->model->draw(0); |
---|
[3750] | 234 | glPopMatrix(); |
---|
| 235 | } |
---|
[3618] | 236 | |
---|