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