[9972] | 1 | #include "light_blaster.h" |
---|
| 2 | #include "world_entities/projectiles/projectile.h" |
---|
| 3 | |
---|
| 4 | #include "world_entity.h" |
---|
| 5 | #include "static_model.h" |
---|
| 6 | #include "weapon_manager.h" |
---|
| 7 | #include "util/loading/factory.h" |
---|
| 8 | |
---|
| 9 | #include "animation3d.h" |
---|
| 10 | |
---|
| 11 | #include "loading/fast_factory.h" |
---|
| 12 | |
---|
[10516] | 13 | #include "elements/glgui_energywidgetvertical.h" |
---|
| 14 | |
---|
[9972] | 15 | CREATE_FACTORY(LightBlaster); |
---|
| 16 | /** |
---|
| 17 | * Standard constructor |
---|
| 18 | */ |
---|
| 19 | LightBlaster::LightBlaster () |
---|
| 20 | : Weapon() |
---|
| 21 | { |
---|
| 22 | this->init(); |
---|
| 23 | } |
---|
| 24 | |
---|
| 25 | LightBlaster::LightBlaster (const TiXmlElement* root = NULL) |
---|
| 26 | : Weapon() |
---|
| 27 | { |
---|
| 28 | this->init(); |
---|
| 29 | if (root != NULL) |
---|
| 30 | this->loadParams(root); |
---|
| 31 | } |
---|
| 32 | |
---|
| 33 | /** |
---|
| 34 | * Default destructor |
---|
| 35 | */ |
---|
| 36 | LightBlaster::~LightBlaster() |
---|
| 37 | { |
---|
[10261] | 38 | |
---|
[10170] | 39 | for (int i = 0; i < this->getBarrels(); i++) |
---|
| 40 | { |
---|
[10261] | 41 | delete [] this->shootAnim[i]; |
---|
| 42 | delete [] this->objComp[i]; |
---|
| 43 | } |
---|
| 44 | delete [] this->emissionPoint; |
---|
| 45 | delete [] this->shootAnim; |
---|
| 46 | delete [] this->objComp; |
---|
[10170] | 47 | |
---|
[9972] | 48 | } |
---|
| 49 | |
---|
| 50 | void LightBlaster::loadParams(const TiXmlElement* root) |
---|
| 51 | { |
---|
| 52 | Weapon::loadParams(root); |
---|
| 53 | } |
---|
| 54 | |
---|
| 55 | void LightBlaster::init() |
---|
| 56 | { |
---|
| 57 | |
---|
[10471] | 58 | this->loadModel("models/guns/gatling.obj", 0.333); |
---|
[9972] | 59 | |
---|
[10415] | 60 | |
---|
[9998] | 61 | this->setStateDuration(WS_SHOOTING, 0.05); // 20 Schuss pro Sekunde |
---|
[9972] | 62 | this->setStateDuration(WS_RELOADING, 0); |
---|
| 63 | this->setStateDuration(WS_ACTIVATING, .5); |
---|
| 64 | this->setStateDuration(WS_DEACTIVATING, 1); |
---|
| 65 | |
---|
[9998] | 66 | this->setEnergyMax(500); |
---|
| 67 | this->increaseEnergy(500); |
---|
[9972] | 68 | //this->minCharge = 2; |
---|
| 69 | |
---|
[10415] | 70 | this->setActionSound(WA_SHOOT, "sounds/guns/laser.wav"); |
---|
[10516] | 71 | // this->setActionSound(WA_ACTIVATE, "sounds/voices/lasers.wav"); |
---|
[10415] | 72 | this->setActionSound(WA_RELOAD, "sounds/spawn/alien_generator.wav"); |
---|
[9972] | 73 | |
---|
| 74 | this->setCapability(WTYPE_ALLDIRS | WTYPE_DIRECTIONAL | WTYPE_LIGHT); |
---|
[10516] | 75 | this->setProjectileTypeC("LBolt"); |
---|
[9972] | 76 | this->prepareProjectiles(100); |
---|
| 77 | |
---|
[10152] | 78 | this->setBarrels(3); |
---|
| 79 | this->setSegs(1); |
---|
| 80 | this->activeBarrel = 0; |
---|
| 81 | |
---|
| 82 | this->objComp = new PNode**[this->getBarrels()]; |
---|
| 83 | this->emissionPoint = new PNode*[this->getBarrels()]; |
---|
| 84 | this->shootAnim = new Animation3D**[this->getBarrels()]; |
---|
| 85 | for (int i = 0; i < this->getBarrels(); i++) |
---|
| 86 | { |
---|
| 87 | this->objComp[i] = new PNode* [this->getSegs()]; |
---|
| 88 | this->emissionPoint[i] = new PNode; |
---|
| 89 | this->emissionPoint[i]->setParent(this); //< One EmissionPoint, that is a PNode connected to the weapon. You can set this to the exitting point of the Projectiles |
---|
| 90 | this->emissionPoint[i]->setName("EmissionPoint"); |
---|
| 91 | this->emissionPoint[i]->addNodeFlags(PNODE_PROHIBIT_DELETE_WITH_PARENT); |
---|
| 92 | this->shootAnim[i] = new Animation3D* [this->getSegs()]; |
---|
| 93 | for(int j = 0; j < this->getSegs(); j++) |
---|
| 94 | { |
---|
| 95 | this->objComp[i][j] = new PNode; |
---|
| 96 | this->shootAnim[i][j] = new Animation3D(this->objComp[i][j]); |
---|
| 97 | this->shootAnim[i][j]->setInfinity(ANIM_INF_CONSTANT); |
---|
| 98 | } |
---|
| 99 | } |
---|
| 100 | |
---|
| 101 | for (int i = 0; i < this->getBarrels(); i++ ) |
---|
| 102 | this->emissionPoint[i]->setRelCoor(Vector(1.19, 0.0, 0.1)); |
---|
| 103 | |
---|
| 104 | // Animation3D* animation1 = this->getAnimation(WS_SHOOTING, this); |
---|
[9972] | 105 | Animation3D* animation2 = this->getAnimation(WS_ACTIVATING, this); |
---|
| 106 | Animation3D* animation3 = this->getAnimation(WS_DEACTIVATING, this); |
---|
| 107 | |
---|
[10152] | 108 | // animation1->setInfinity(ANIM_INF_CONSTANT); |
---|
[9972] | 109 | animation2->setInfinity(ANIM_INF_CONSTANT); |
---|
| 110 | animation3->setInfinity(ANIM_INF_CONSTANT); |
---|
| 111 | |
---|
[10152] | 112 | // this->setEmissionPoint(3.8, 1.2, 0); |
---|
[9972] | 113 | |
---|
[10152] | 114 | for (int i = 0; i < this->getBarrels(); i++){ |
---|
[10170] | 115 | this->shootAnim[i][0]->addKeyFrame(Vector(), Quaternion(i * 120, Vector(1.0, 0.0, 0.0)), 0.049, ANIM_NULL, ANIM_LINEAR); |
---|
| 116 | this->shootAnim[i][0]->addKeyFrame(Vector(), Quaternion((i+1)*120, Vector(1.0, 0.0, 0.0)), 0.001, ANIM_NULL, ANIM_LINEAR); |
---|
[10152] | 117 | } |
---|
| 118 | |
---|
| 119 | |
---|
[9972] | 120 | animation2->addKeyFrame(Vector(0.0, -1.0, 0.0), Quaternion(), 0.3, ANIM_LINEAR, ANIM_NULL); |
---|
| 121 | animation2->addKeyFrame(Vector(0.0, 0.0, 0.0), Quaternion(), 0.5, ANIM_LINEAR, ANIM_NULL); |
---|
| 122 | |
---|
| 123 | animation3->addKeyFrame(Vector(0.0, 0.0, 0.0), Quaternion(), 0.5, ANIM_LINEAR, ANIM_NULL); |
---|
| 124 | animation3->addKeyFrame(Vector(0.0, -1.0, 0.0), Quaternion(), 0.3, ANIM_LINEAR, ANIM_NULL); |
---|
| 125 | } |
---|
| 126 | |
---|
| 127 | void LightBlaster::fire() |
---|
| 128 | { |
---|
| 129 | Projectile* pj = this->getProjectile(); |
---|
| 130 | if (pj == NULL) |
---|
| 131 | return; |
---|
| 132 | |
---|
[9975] | 133 | // set the owner |
---|
| 134 | pj->setOwner(this->getOwner()); |
---|
| 135 | |
---|
[9972] | 136 | pj->setParent(PNode::getNullParent()); |
---|
| 137 | |
---|
[10044] | 138 | // pj->setVelocity(this->getAbsDir().apply(Vector(1,0,0))*250 + VECTOR_RAND(5)); |
---|
[10046] | 139 | pj->setVelocity(this->getAbsDir().apply(Vector(1,0,0))*180); |
---|
[9972] | 140 | |
---|
[10152] | 141 | pj->setAbsCoor(this->emissionPoint[this->activeBarrel]->getAbsCoor()); |
---|
[9972] | 142 | pj->setAbsDir(this->getAbsDir()); |
---|
[10152] | 143 | // pj->toList(OM_GROUP_01_PROJ); |
---|
[9972] | 144 | pj->activate(); |
---|
[10152] | 145 | |
---|
| 146 | for (int i = 0; i < this->getSegs(); i++) |
---|
| 147 | this->shootAnim[this->activeBarrel][i]->replay(); |
---|
| 148 | |
---|
| 149 | // switch barrel |
---|
| 150 | this->activeBarrel = (this->activeBarrel + 1) % this->getBarrels(); |
---|
[9972] | 151 | } |
---|
| 152 | |
---|
| 153 | /** |
---|
| 154 | * this activates the weapon |
---|
| 155 | */ |
---|
| 156 | void LightBlaster::activate() |
---|
| 157 | { |
---|
| 158 | } |
---|
| 159 | |
---|
| 160 | /** |
---|
| 161 | * this deactivates the weapon |
---|
| 162 | */ |
---|
| 163 | void LightBlaster::deactivate() |
---|
| 164 | { |
---|
[9975] | 165 | } |
---|
| 166 | |
---|
| 167 | void LightBlaster::draw() const |
---|
| 168 | { |
---|
[10152] | 169 | glMatrixMode(GL_MODELVIEW); |
---|
| 170 | glPushMatrix(); |
---|
| 171 | glTranslatef (this->getAbsCoor ().x, this->getAbsCoor ().y, this->getAbsCoor ().z); |
---|
| 172 | Vector tmpRot = this->getAbsDir().getSpacialAxis(); |
---|
| 173 | glRotatef (this->getAbsDir().getSpacialAxisAngle(), tmpRot.x, tmpRot.y, tmpRot.z ); |
---|
| 174 | static_cast<StaticModel*>(this->getModel())->draw(); |
---|
| 175 | glPopMatrix(); |
---|
[10516] | 176 | |
---|
[9975] | 177 | } |
---|
[10516] | 178 | |
---|
| 179 | void LightBlaster::tick(float dt) |
---|
| 180 | { |
---|
| 181 | if (this->energyWidget != NULL && !this->isEnergyWidgetInitialized) |
---|
| 182 | { |
---|
| 183 | this->energyWidget->setDisplayedImage("textures/gui/gui_light_bolt.png"); |
---|
| 184 | this->setEnergyWidgetInitialized(true); |
---|
| 185 | } |
---|
| 186 | } |
---|