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: Christian Meyer |
---|
16 | */ |
---|
17 | |
---|
18 | #define DEBUG_SPECIAL_MODULE DEBUG_MODULE_PLAYER |
---|
19 | |
---|
20 | #include "player.h" |
---|
21 | |
---|
22 | #include "track_manager.h" |
---|
23 | #include "objModel.h" |
---|
24 | #include "resource_manager.h" |
---|
25 | #include "weapon.h" |
---|
26 | #include "test_gun.h" |
---|
27 | #include "world.h" |
---|
28 | |
---|
29 | #include "list.h" |
---|
30 | #include "stdincl.h" |
---|
31 | |
---|
32 | using namespace std; |
---|
33 | |
---|
34 | /** |
---|
35 | \brief creates a new Player |
---|
36 | \param isFree if the player is free |
---|
37 | */ |
---|
38 | Player::Player() : WorldEntity() |
---|
39 | { |
---|
40 | this->weapons = new tList<Weapon>(); |
---|
41 | this->activeWeapon = NULL; |
---|
42 | /* |
---|
43 | this is the debug player - actualy we would have to make a new |
---|
44 | class derivated from Player for each player. for now, we just use |
---|
45 | the player.cc for debug also |
---|
46 | */ |
---|
47 | this->model = (Model*)ResourceManager::getInstance()->load("models/reaplow.obj", OBJ, RP_CAMPAIGN); |
---|
48 | //this->model = (Model*)ResourceManager::getInstance()->load("models/weapon_packet.obj", OBJ, RP_CAMPAIGN); |
---|
49 | travelSpeed = 15.0; |
---|
50 | velocity = new Vector(); |
---|
51 | bUp = bDown = bLeft = bRight = bAscend = bDescend = false; |
---|
52 | bFire = false; |
---|
53 | acceleration = 10.0; |
---|
54 | //weapons: |
---|
55 | Weapon* wpRight = new TestGun(this, new Vector(-2.6, 0.1, 3.0), new Quaternion(), 0); |
---|
56 | Weapon* wpLeft = new TestGun(this, new Vector(-2.6, 0.1, -3.0), new Quaternion(), 1); |
---|
57 | this->weapons->add(wpRight); |
---|
58 | this->activeWeapon = wpRight; |
---|
59 | this->activeWeaponL = wpLeft; |
---|
60 | } |
---|
61 | |
---|
62 | /** |
---|
63 | \brief destructs the player, deletes alocated memory |
---|
64 | */ |
---|
65 | Player::~Player () |
---|
66 | { |
---|
67 | /* do not delete the weapons, they are contained in the pnode tree |
---|
68 | and will be deleted there. |
---|
69 | this only frees the memory allocated to save the list. |
---|
70 | */ |
---|
71 | delete this->weapons; |
---|
72 | } |
---|
73 | |
---|
74 | |
---|
75 | /** |
---|
76 | \brief adds a weapon to the weapon list of player |
---|
77 | \param weapon to add |
---|
78 | */ |
---|
79 | void Player::addWeapon(Weapon* weapon) |
---|
80 | { |
---|
81 | this->weapons->add(weapon); |
---|
82 | } |
---|
83 | |
---|
84 | |
---|
85 | /** |
---|
86 | \brief removes a weapon from the player |
---|
87 | \param weapon to remove |
---|
88 | */ |
---|
89 | void Player::removeWeapon(Weapon* weapon) |
---|
90 | { |
---|
91 | this->weapons->remove(weapon); |
---|
92 | } |
---|
93 | |
---|
94 | |
---|
95 | /** |
---|
96 | \brief effect that occurs after the player is spawned |
---|
97 | */ |
---|
98 | void Player::postSpawn () |
---|
99 | { |
---|
100 | //setCollision(new CollisionCluster(1.0, Vector(0,0,0))); |
---|
101 | } |
---|
102 | |
---|
103 | |
---|
104 | /** |
---|
105 | \brief the action occuring if the player left the game |
---|
106 | */ |
---|
107 | void Player::leftWorld () |
---|
108 | {} |
---|
109 | |
---|
110 | |
---|
111 | |
---|
112 | /** |
---|
113 | \brief if the player is hit, call this function |
---|
114 | \param weapon hit by this weapon |
---|
115 | \param loc ?? |
---|
116 | */ |
---|
117 | void Player::hit (WorldEntity* weapon, Vector* loc) |
---|
118 | { |
---|
119 | } |
---|
120 | |
---|
121 | |
---|
122 | /** |
---|
123 | \brief Collision with another Entity has this effect |
---|
124 | \param other the other colider |
---|
125 | \param ownhitflags ?? |
---|
126 | \param otherhitflags ?? |
---|
127 | */ |
---|
128 | void Player::collide (WorldEntity* other, Uint32 ownhitflags, Uint32 otherhitflags) |
---|
129 | { |
---|
130 | } |
---|
131 | |
---|
132 | |
---|
133 | /** |
---|
134 | \brief draws the player after transforming him. |
---|
135 | */ |
---|
136 | void Player::draw () |
---|
137 | { |
---|
138 | glMatrixMode(GL_MODELVIEW); |
---|
139 | glPushMatrix(); |
---|
140 | float matrix[4][4]; |
---|
141 | |
---|
142 | /* translate */ |
---|
143 | glTranslatef (this->getAbsCoor ().x, |
---|
144 | this->getAbsCoor ().y, |
---|
145 | this->getAbsCoor ().z); |
---|
146 | /* rotate */ |
---|
147 | this->getAbsDir ().matrix (matrix); |
---|
148 | glMultMatrixf((float*)matrix); |
---|
149 | |
---|
150 | this->model->draw(); |
---|
151 | glPopMatrix(); |
---|
152 | |
---|
153 | this->activeWeapon->draw(); |
---|
154 | this->activeWeaponL->draw(); |
---|
155 | } |
---|
156 | |
---|
157 | |
---|
158 | /** |
---|
159 | \brief the function called for each passing timeSnap |
---|
160 | \param time The timespan passed since last update |
---|
161 | */ |
---|
162 | void Player::tick (float time) |
---|
163 | { |
---|
164 | /* link tick to weapon */ |
---|
165 | this->activeWeapon->tick(time); |
---|
166 | this->activeWeaponL->tick(time); //FIX FIX DELETE REMOVE |
---|
167 | // player controlled movement |
---|
168 | this->move(time); |
---|
169 | // weapon system manipulation |
---|
170 | this->weapon(); |
---|
171 | } |
---|
172 | |
---|
173 | |
---|
174 | /** |
---|
175 | \brief action if player moves |
---|
176 | \param time the timeslice since the last frame |
---|
177 | */ |
---|
178 | void Player::move (float time) |
---|
179 | { |
---|
180 | Vector accel(0.0, 0.0, 0.0); |
---|
181 | /* FIXME: calculating the direction and orthDirection every timeSlice is redundant! save it somewhere */ |
---|
182 | |
---|
183 | /* calculate the direction in which the craft is heading */ |
---|
184 | Vector direction (1.0, 0.0, 0.0); |
---|
185 | //direction = this->absDirection.apply (direction); |
---|
186 | Vector orthDirection (0.0, 0.0, 1.0); |
---|
187 | //orthDirection = orthDirection.cross (direction); |
---|
188 | |
---|
189 | if( this->bUp && this->getRelCoor()->x < 20) |
---|
190 | accel = accel+(direction*acceleration); |
---|
191 | if( this->bDown && this->getRelCoor()->x > -5) |
---|
192 | accel = accel-(direction*acceleration); |
---|
193 | if( this->bLeft && TrackManager::getInstance()->getWidth() > -this->getRelCoor()->z*2) |
---|
194 | accel = accel - (orthDirection*acceleration); |
---|
195 | if( this->bRight && TrackManager::getInstance()->getWidth() > this->getRelCoor()->z*2) |
---|
196 | accel = accel + (orthDirection*acceleration); |
---|
197 | if( this->bAscend ) |
---|
198 | if( this->bDescend) {/* FIXME */} /* \todo up and down player movement */ |
---|
199 | |
---|
200 | Vector move = accel * time; |
---|
201 | this->shiftCoor (&move); |
---|
202 | } |
---|
203 | |
---|
204 | |
---|
205 | /** |
---|
206 | \brief weapon manipulation by the player |
---|
207 | */ |
---|
208 | void Player::weapon() |
---|
209 | { |
---|
210 | if( this->bFire) |
---|
211 | { |
---|
212 | //if(this->activeWeapon != NULL) |
---|
213 | this->activeWeapon->fire(); |
---|
214 | //FIX THIS FIX FIIIIIIIIIIIX |
---|
215 | this->activeWeaponL->fire(); |
---|
216 | } |
---|
217 | if( this->bWeaponChange && this->weapons->getSize() > 1) |
---|
218 | { |
---|
219 | PRINTF(1)("changing the weapon of the player: deactivate old, activate new\n"); |
---|
220 | this->activeWeapon->deactivate(); |
---|
221 | //this->weapons->enumerate(); FIX: strang weapon change... |
---|
222 | this->activeWeapon = this->weapons->nextElement(this->activeWeapon); |
---|
223 | this->activeWeapon->activate(); |
---|
224 | } |
---|
225 | } |
---|
226 | |
---|
227 | |
---|
228 | /** |
---|
229 | \brief The connection to the command node |
---|
230 | \param cmd the Command unit from witch to map |
---|
231 | |
---|
232 | here the commands are mapped to the players movement/weaponary |
---|
233 | */ |
---|
234 | void Player::command (Command* cmd) |
---|
235 | { |
---|
236 | PRINTF(3)("recieved command [%s]\n", cmd->cmd); |
---|
237 | if( !strcmp( cmd->cmd, "up")) this->bUp = !cmd->bUp; |
---|
238 | if( !strcmp( cmd->cmd, "down")) this->bDown = !cmd->bUp; |
---|
239 | if( !strcmp( cmd->cmd, "left")) this->bLeft = !cmd->bUp; |
---|
240 | if( !strcmp( cmd->cmd, "right")) this->bRight = !cmd->bUp; |
---|
241 | if( !strcmp( cmd->cmd, "fire")) this->bFire = !cmd->bUp; |
---|
242 | if( !strcmp( cmd->cmd, "mode")) this->bWeaponChange = !cmd->bUp; |
---|
243 | } |
---|