[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 | |
---|
| 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 "stdincl.h" |
---|
| 26 | #include "world_entity.h" |
---|
[3677] | 27 | #include "model.h" |
---|
[3710] | 28 | #include "test_bullet.h" |
---|
[3618] | 29 | |
---|
| 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 | /** |
---|
| 41 | \brief standard constructor |
---|
| 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); |
---|
[3685] | 52 | this->idleTime = 0.2f; |
---|
[3755] | 53 | this->leftRight = leftRight; |
---|
[3752] | 54 | |
---|
[3886] | 55 | this->objectComponent1 = new PNode(); |
---|
| 56 | this->animation1 = new Animation3D(this->objectComponent1); |
---|
[3993] | 57 | this->animation2 = new Animation3D(this); |
---|
| 58 | this->animation3 = new Animation3D(this); |
---|
[3986] | 59 | //parent->addChild(this->objectComponent1, PNODE_ALL); |
---|
| 60 | this->addChild(this->objectComponent1, PNODE_ALL); |
---|
[3755] | 61 | |
---|
[3886] | 62 | this->animation1->setInfinity(ANIM_INF_CONSTANT); |
---|
[3993] | 63 | this->animation2->setInfinity(ANIM_INF_CONSTANT); |
---|
| 64 | this->animation3->setInfinity(ANIM_INF_CONSTANT); |
---|
[3886] | 65 | if( this->leftRight == W_LEFT) |
---|
[3755] | 66 | { |
---|
[3888] | 67 | this->projectileOffset = Vector(1.0, 0.0, -0.35); |
---|
| 68 | |
---|
[4592] | 69 | this->animation1->addKeyFrame(Vector(0, 0, 0), Quaternion(), 0.1, ANIM_LINEAR, ANIM_CONSTANT); |
---|
[3986] | 70 | this->animation1->addKeyFrame(Vector(-0.4, 0, 0), Quaternion(), 0.1, ANIM_LINEAR, ANIM_CONSTANT); |
---|
| 71 | this->animation1->addKeyFrame(Vector(0, 0, 0), Quaternion(), 0.0, ANIM_LINEAR, ANIM_CONSTANT); |
---|
| 72 | |
---|
[4592] | 73 | this->animation2->addKeyFrame(Vector(-2.6, 0.1, 2.0), Quaternion(), 0.1, ANIM_LINEAR, ANIM_CONSTANT); |
---|
[3993] | 74 | this->animation2->addKeyFrame(Vector(-2.6, 0.1, 3.0), Quaternion(), 0.1, ANIM_LINEAR, ANIM_CONSTANT); |
---|
[3986] | 75 | |
---|
[3993] | 76 | this->animation3->addKeyFrame(Vector(-2.6, 0.1, 3.0), Quaternion(), 0.1, ANIM_LINEAR, ANIM_CONSTANT); |
---|
[4592] | 77 | this->animation3->addKeyFrame(Vector(-2.6, 0.1, 2.0), Quaternion(), 0.1, ANIM_LINEAR, ANIM_CONSTANT); |
---|
[3755] | 78 | } |
---|
[3886] | 79 | else if( this->leftRight == W_RIGHT) |
---|
[3755] | 80 | { |
---|
[3888] | 81 | this->projectileOffset = Vector(1.0, 0.0, 0.5); |
---|
| 82 | |
---|
[3987] | 83 | this->objectComponent1->setRelCoor(Vector(0,0,0.35)); |
---|
[4592] | 84 | this->animation1->addKeyFrame(Vector(0, 0, .5), Quaternion(), 0.1, ANIM_LINEAR, ANIM_CONSTANT); |
---|
[4006] | 85 | this->animation1->addKeyFrame(Vector(-0.4, 0, .5), Quaternion(), 0.1, ANIM_LINEAR, ANIM_CONSTANT); |
---|
| 86 | this->animation1->addKeyFrame(Vector(0, 0, .5), Quaternion(), 0.0, ANIM_LINEAR, ANIM_CONSTANT); |
---|
[3986] | 87 | |
---|
[4592] | 88 | this->animation2->addKeyFrame(Vector(-2.6, 0.1, -2.0), Quaternion(), 0.1, ANIM_LINEAR, ANIM_CONSTANT); |
---|
[3993] | 89 | this->animation2->addKeyFrame(Vector(-2.6, 0.1, -3.0), Quaternion(), 0.1, ANIM_LINEAR, ANIM_CONSTANT); |
---|
| 90 | |
---|
| 91 | this->animation3->addKeyFrame(Vector(-2.6, 0.1, -3.0), Quaternion(), 0.1, ANIM_LINEAR, ANIM_CONSTANT); |
---|
[4592] | 92 | this->animation3->addKeyFrame(Vector(-2.6, 0.1, -2.0), Quaternion(), 0.1, ANIM_LINEAR, ANIM_CONSTANT); |
---|
[3755] | 93 | } |
---|
[4592] | 94 | |
---|
[4504] | 95 | this->fireSound = (SoundBuffer*)ResourceManager::getInstance()->load("sound/shot1.wav", WAV); |
---|
| 96 | this->weaponSource = new SoundSource(this->fireSound, this); |
---|
| 97 | this->weaponSource->setRolloffFactor(.1); |
---|
[4311] | 98 | Projectile* p = new TestBullet(this); |
---|
| 99 | ObjectManager::getInstance()->cache(CL_TEST_BULLET, 100, p); |
---|
[4389] | 100 | //ObjectManager::getInstance()->debug(); |
---|
[3683] | 101 | } |
---|
[3618] | 102 | |
---|
| 103 | |
---|
| 104 | /** |
---|
| 105 | \brief standard deconstructor |
---|
| 106 | */ |
---|
[4592] | 107 | TestGun::~TestGun () |
---|
[3618] | 108 | { |
---|
| 109 | // model will be deleted from WorldEntity-destructor |
---|
| 110 | } |
---|
| 111 | |
---|
| 112 | |
---|
| 113 | /** |
---|
| 114 | \brief this activates the weapon |
---|
| 115 | |
---|
[4592] | 116 | This is needed, since there can be more than one weapon on a ship. the |
---|
| 117 | activation can be connected with an animation. for example the weapon is |
---|
| 118 | been armed out. |
---|
[3618] | 119 | */ |
---|
| 120 | void TestGun::activate() |
---|
[3980] | 121 | { |
---|
[3993] | 122 | this->animation2->replay(); |
---|
[3980] | 123 | } |
---|
[3618] | 124 | |
---|
| 125 | |
---|
| 126 | /** |
---|
| 127 | \brief this deactivates the weapon |
---|
| 128 | |
---|
[4592] | 129 | This is needed, since there can be more than one weapon on a ship. the |
---|
| 130 | activation can be connected with an animation. for example the weapon is |
---|
[3618] | 131 | been armed out. |
---|
| 132 | */ |
---|
| 133 | void TestGun::deactivate() |
---|
[3980] | 134 | { |
---|
[3993] | 135 | this->animation3->replay(); |
---|
[3980] | 136 | } |
---|
[3618] | 137 | |
---|
| 138 | |
---|
| 139 | /** |
---|
| 140 | \brief fires the weapon |
---|
[4592] | 141 | |
---|
[3618] | 142 | this is called from the player.cc, when fire-button is been pushed |
---|
[4467] | 143 | \todo: the ObjectManager deliveres Projectiles not TestBullets! this should be diffrent |
---|
[3618] | 144 | */ |
---|
| 145 | void TestGun::fire() |
---|
[3620] | 146 | { |
---|
[3881] | 147 | if( !this->hasWeaponIdleTimeElapsed()) |
---|
[3708] | 148 | { |
---|
| 149 | this->weaponIdle(); |
---|
| 150 | return; |
---|
| 151 | } |
---|
[3888] | 152 | |
---|
[4592] | 153 | Projectile* pj = dynamic_cast<Projectile*>(ObjectManager::getInstance()->getFromDeadList(CL_TEST_BULLET & CL_MASK_LOWLEVEL_CLASS)); |
---|
[4504] | 154 | weaponSource->play(); |
---|
| 155 | |
---|
[3888] | 156 | pj->setAbsCoor(this->getAbsCoor() + this->projectileOffset); |
---|
[3708] | 157 | pj->setAbsDir(this->getAbsDir()); |
---|
[4464] | 158 | pj->setVelocity(this->getVelocity()); |
---|
[3631] | 159 | this->worldEntities->add(pj); |
---|
[3685] | 160 | this->localTime = 0; |
---|
[4592] | 161 | |
---|
[3886] | 162 | this->animation1->replay(); |
---|
[3620] | 163 | } |
---|
[3618] | 164 | |
---|
| 165 | |
---|
| 166 | /** |
---|
| 167 | \brief is called, when the weapon gets hit (=collide with something) |
---|
| 168 | \param from which entity it is been hit |
---|
| 169 | \param where it is been hit |
---|
| 170 | |
---|
| 171 | this may not be used, since it would make the game relay complicated when one |
---|
| 172 | can destroy the weapons of enemies or vice versa. |
---|
| 173 | */ |
---|
[4592] | 174 | void TestGun::hit (WorldEntity* entity, Vector* position) |
---|
[3618] | 175 | {} |
---|
| 176 | |
---|
| 177 | |
---|
| 178 | /** |
---|
| 179 | \brief is called, when the weapon is destroyed |
---|
| 180 | |
---|
| 181 | this is in conjunction with the hit function, so when a weapon is able to get |
---|
| 182 | hit, it can also be destoryed. |
---|
| 183 | */ |
---|
[4592] | 184 | void TestGun::destroy () |
---|
[3618] | 185 | {} |
---|
| 186 | |
---|
| 187 | |
---|
| 188 | /** |
---|
| 189 | \brief tick signal for time dependent/driven stuff |
---|
| 190 | */ |
---|
[4592] | 191 | void TestGun::tick (float time) |
---|
[3685] | 192 | { |
---|
| 193 | this->localTime += time; |
---|
| 194 | } |
---|
[3618] | 195 | |
---|
| 196 | |
---|
| 197 | /** |
---|
| 198 | \brief is called, when there is no fire button pressed |
---|
| 199 | */ |
---|
| 200 | void TestGun::weaponIdle() |
---|
| 201 | {} |
---|
| 202 | |
---|
| 203 | |
---|
| 204 | /** |
---|
| 205 | \brief this will draw the weapon |
---|
| 206 | */ |
---|
[4592] | 207 | void TestGun::draw () |
---|
[3750] | 208 | { |
---|
[3886] | 209 | /* draw gun body */ |
---|
[3750] | 210 | glMatrixMode(GL_MODELVIEW); |
---|
| 211 | glPushMatrix(); |
---|
| 212 | float matrix[4][4]; |
---|
[4592] | 213 | glTranslatef (this->getAbsCoor ().x, |
---|
| 214 | this->getAbsCoor ().y, |
---|
| 215 | this->getAbsCoor ().z); |
---|
[3886] | 216 | this->getAbsDir ().matrix (matrix); |
---|
| 217 | glMultMatrixf((float*)matrix); |
---|
| 218 | if( this->leftRight == W_RIGHT) |
---|
| 219 | glScalef(1.0, 1.0, -1.0); |
---|
| 220 | this->model->draw(1); |
---|
[3752] | 221 | glPopMatrix(); |
---|
| 222 | |
---|
[3886] | 223 | /* draw objectComponent1: gun coil - animated stuff */ |
---|
[3752] | 224 | glMatrixMode(GL_MODELVIEW); |
---|
| 225 | glPushMatrix(); |
---|
[4592] | 226 | glTranslatef (this->objectComponent1->getAbsCoor ().x, |
---|
| 227 | this->objectComponent1->getAbsCoor ().y, |
---|
| 228 | this->objectComponent1->getAbsCoor ().z); |
---|
[3886] | 229 | this->objectComponent1->getAbsDir ().matrix (matrix); |
---|
[3752] | 230 | glMultMatrixf((float*)matrix); |
---|
| 231 | this->model->draw(0); |
---|
[3750] | 232 | glPopMatrix(); |
---|
| 233 | } |
---|
[3618] | 234 | |
---|