| 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 "simple_animation.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, Vector* coordinate, 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 | if( this->leftRight == 0) |
|---|
| 50 | this->projOffset = new Vector(1.0, 0.0, -0.35); |
|---|
| 51 | else if( this->leftRight == 1) |
|---|
| 52 | this->projOffset = new Vector(1.0, 0.0, 0.5); |
|---|
| 53 | |
|---|
| 54 | this->animator = SimpleAnimation::getInstance(); |
|---|
| 55 | this->dummy1 = new WorldEntity(); /* a world entity that is not drawed: use this for the weapon */ |
|---|
| 56 | parent->addChild(this->dummy1, PNODE_ALL); |
|---|
| 57 | |
|---|
| 58 | |
|---|
| 59 | this->animator->animatorBegin(); |
|---|
| 60 | this->animator->selectObject(this->dummy1); |
|---|
| 61 | this->animator->setAnimationMode(SINGLE); |
|---|
| 62 | if( this->leftRight == 0) |
|---|
| 63 | { |
|---|
| 64 | this->animator->addKeyFrame(new Vector(-2.6, 0.1, 3.0), new Quaternion(), 0.0, NEG_EXP); |
|---|
| 65 | this->animator->addKeyFrame(new Vector(-3.0, 0.1, 3.0), new Quaternion(), 0.1, NEG_EXP); |
|---|
| 66 | this->animator->addKeyFrame(new Vector(-2.6, 0.1, 3.0), new Quaternion(), 0.5, NEG_EXP); |
|---|
| 67 | } |
|---|
| 68 | else if( this->leftRight == 1) |
|---|
| 69 | { |
|---|
| 70 | this->animator->addKeyFrame(new Vector(-2.6, 0.1, -2.5), new Quaternion(), 0.0, NEG_EXP); |
|---|
| 71 | this->animator->addKeyFrame(new Vector(-3.0, 0.1, -2.5), new Quaternion(), 0.1, NEG_EXP); |
|---|
| 72 | this->animator->addKeyFrame(new Vector(-2.6, 0.1, -2.5), new Quaternion(), 0.5, NEG_EXP); |
|---|
| 73 | } |
|---|
| 74 | this->animator->animatorEnd(); |
|---|
| 75 | |
|---|
| 76 | } |
|---|
| 77 | |
|---|
| 78 | |
|---|
| 79 | /** |
|---|
| 80 | \brief standard deconstructor |
|---|
| 81 | */ |
|---|
| 82 | TestGun::~TestGun () |
|---|
| 83 | { |
|---|
| 84 | // model will be deleted from WorldEntity-destructor |
|---|
| 85 | } |
|---|
| 86 | |
|---|
| 87 | |
|---|
| 88 | /** |
|---|
| 89 | \brief this activates the weapon |
|---|
| 90 | |
|---|
| 91 | This is needed, since there can be more than one weapon on a ship. the |
|---|
| 92 | activation can be connected with an animation. for example the weapon is |
|---|
| 93 | been armed out. |
|---|
| 94 | */ |
|---|
| 95 | void TestGun::activate() |
|---|
| 96 | {} |
|---|
| 97 | |
|---|
| 98 | |
|---|
| 99 | /** |
|---|
| 100 | \brief this deactivates the weapon |
|---|
| 101 | |
|---|
| 102 | This is needed, since there can be more than one weapon on a ship. the |
|---|
| 103 | activation can be connected with an animation. for example the weapon is |
|---|
| 104 | been armed out. |
|---|
| 105 | */ |
|---|
| 106 | void TestGun::deactivate() |
|---|
| 107 | {} |
|---|
| 108 | |
|---|
| 109 | |
|---|
| 110 | /** |
|---|
| 111 | \brief fires the weapon |
|---|
| 112 | |
|---|
| 113 | this is called from the player.cc, when fire-button is been pushed |
|---|
| 114 | */ |
|---|
| 115 | void TestGun::fire() |
|---|
| 116 | { |
|---|
| 117 | if( this->localTime < this->idleTime) |
|---|
| 118 | { |
|---|
| 119 | this->weaponIdle(); |
|---|
| 120 | return; |
|---|
| 121 | } |
|---|
| 122 | Projectile* pj = new TestBullet(this); |
|---|
| 123 | |
|---|
| 124 | pj->setAbsCoor(this->getAbsCoor() + *this->projOffset); |
|---|
| 125 | pj->setAbsDir(this->getAbsDir()); |
|---|
| 126 | |
|---|
| 127 | pj->setFlightDirection(this->getAbsDir()); |
|---|
| 128 | pj->setSpeed(this->getSpeed()); |
|---|
| 129 | |
|---|
| 130 | this->worldEntities->add(pj); |
|---|
| 131 | this->localTime = 0; |
|---|
| 132 | |
|---|
| 133 | this->animator->animatorBegin(); |
|---|
| 134 | this->animator->selectObject(this->dummy1); |
|---|
| 135 | this->animator->start(); |
|---|
| 136 | this->animator->animatorEnd(); |
|---|
| 137 | } |
|---|
| 138 | |
|---|
| 139 | |
|---|
| 140 | /** |
|---|
| 141 | \brief is called, when the weapon gets hit (=collide with something) |
|---|
| 142 | \param from which entity it is been hit |
|---|
| 143 | \param where it is been hit |
|---|
| 144 | |
|---|
| 145 | this may not be used, since it would make the game relay complicated when one |
|---|
| 146 | can destroy the weapons of enemies or vice versa. |
|---|
| 147 | */ |
|---|
| 148 | void TestGun::hit (WorldEntity* entity, Vector* position) |
|---|
| 149 | {} |
|---|
| 150 | |
|---|
| 151 | |
|---|
| 152 | /** |
|---|
| 153 | \brief is called, when the weapon is destroyed |
|---|
| 154 | |
|---|
| 155 | this is in conjunction with the hit function, so when a weapon is able to get |
|---|
| 156 | hit, it can also be destoryed. |
|---|
| 157 | */ |
|---|
| 158 | void TestGun::destroy () |
|---|
| 159 | {} |
|---|
| 160 | |
|---|
| 161 | |
|---|
| 162 | /** |
|---|
| 163 | \brief tick signal for time dependent/driven stuff |
|---|
| 164 | */ |
|---|
| 165 | void TestGun::tick (float time) |
|---|
| 166 | { |
|---|
| 167 | this->localTime += time; |
|---|
| 168 | } |
|---|
| 169 | |
|---|
| 170 | |
|---|
| 171 | /** |
|---|
| 172 | \brief is called, when there is no fire button pressed |
|---|
| 173 | */ |
|---|
| 174 | void TestGun::weaponIdle() |
|---|
| 175 | {} |
|---|
| 176 | |
|---|
| 177 | |
|---|
| 178 | /** |
|---|
| 179 | \brief this will draw the weapon |
|---|
| 180 | */ |
|---|
| 181 | void TestGun::draw () |
|---|
| 182 | { |
|---|
| 183 | |
|---|
| 184 | /* draw gun body 1 */ |
|---|
| 185 | glMatrixMode(GL_MODELVIEW); |
|---|
| 186 | glPushMatrix(); |
|---|
| 187 | float matrix[4][4]; |
|---|
| 188 | |
|---|
| 189 | if( this->leftRight == 0) |
|---|
| 190 | { |
|---|
| 191 | glTranslatef (this->getAbsCoor ().x, |
|---|
| 192 | this->getAbsCoor ().y, |
|---|
| 193 | this->getAbsCoor ().z); |
|---|
| 194 | |
|---|
| 195 | this->getAbsDir ().matrix (matrix); |
|---|
| 196 | glMultMatrixf((float*)matrix); |
|---|
| 197 | this->model->draw(1); |
|---|
| 198 | } |
|---|
| 199 | else if( this->leftRight == 1) |
|---|
| 200 | { |
|---|
| 201 | glTranslatef (this->getAbsCoor ().x, |
|---|
| 202 | this->getAbsCoor ().y, |
|---|
| 203 | this->getAbsCoor ().z); |
|---|
| 204 | |
|---|
| 205 | this->getAbsDir ().matrix (matrix); |
|---|
| 206 | glMultMatrixf((float*)matrix); |
|---|
| 207 | glScalef(1.0, 1.0, -1.0); |
|---|
| 208 | this->model->draw(1); |
|---|
| 209 | } |
|---|
| 210 | |
|---|
| 211 | glPopMatrix(); |
|---|
| 212 | |
|---|
| 213 | |
|---|
| 214 | /* draw gun coil 1 */ |
|---|
| 215 | glMatrixMode(GL_MODELVIEW); |
|---|
| 216 | glPushMatrix(); |
|---|
| 217 | |
|---|
| 218 | glTranslatef (this->dummy1->getAbsCoor ().x, |
|---|
| 219 | this->dummy1->getAbsCoor ().y, |
|---|
| 220 | this->dummy1->getAbsCoor ().z); |
|---|
| 221 | |
|---|
| 222 | this->dummy1->getAbsDir ().matrix (matrix); |
|---|
| 223 | glMultMatrixf((float*)matrix); |
|---|
| 224 | this->model->draw(0); |
|---|
| 225 | glPopMatrix(); |
|---|
| 226 | } |
|---|
| 227 | |
|---|