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