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