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