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