Changeset 3605 in orxonox.OLD for orxonox/branches/levelloader/src/world_entities/player.cc
- Timestamp:
- Mar 18, 2005, 11:52:15 AM (20 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
orxonox/branches/levelloader/src/world_entities/player.cc
r3604 r3605 16 16 */ 17 17 18 #define DEBUG_SPECIAL_MODULE DEBUG_MODULE_PLAYER 19 18 20 #include "player.h" 21 19 22 #include "stdincl.h" 20 23 //#include "collision.h" 21 24 #include "objModel.h" 25 #include "list.h" 26 #include "weapon.h" 27 #include "track_manager.h" 22 28 23 29 using namespace std; … … 31 37 Player::Player(bool isFree) : WorldEntity(isFree) 32 38 { 33 34 39 this->model = new OBJModel("../data/models/reaplow.obj"); 35 /*36 objectList = glGenLists(1);37 glNewList (objectList, GL_COMPILE); 38 39 glBegin(GL_TRIANGLES);40 glColor3f(1,1,1);41 glVertex3f(0,0,0.5);42 glVertex3f(-0.5,0,-1);43 glVertex3f(0.5,0,-1); 44 45 glVertex3f(0,0,0.5); 46 glVertex3f(0,0.5,-1);47 glVertex3f(0,-0.5,-1); 48 glEnd(); 49 50 glBegin(GL_QUADS);51 glColor3f(0,0,1);52 glVertex3f(0.5,0.5,-1);53 glVertex3f(0.5,-0.5,-1);54 glVertex3f(-0.5,-0.5,-1);55 glVertex3f(-0.5,0.5,-1);56 glEnd();57 58 glEndList ();59 */ 60 } 40 this->weapons = new tList<Weapon>(); 41 this->activeWeapon = NULL; 42 43 travelSpeed = 15.0; 44 velocity = Vector(); 45 bUp = bDown = bLeft = bRight = bAscend = bDescend = false; 46 bFire = false; 47 acceleration = 10.0; 48 } 49 50 /** 51 \brief destructs the player, deletes alocated memory 52 */ 53 Player::~Player () 54 { 55 Weapon* w = this->weapons->enumerate(); 56 while( w != NULL) 57 { 58 delete w; 59 w = this->weapons->nextElement(); 60 } 61 delete this->weapons; 62 63 //delete this->velocity; 64 } 65 61 66 62 67 /** … … 102 107 103 108 /** 104 \brief destructs the player 105 */ 106 Player::~Player () 107 { 108 delete this->model; 109 } 109 \brief adds a weapon to the weapon list of player 110 \param weapon to add 111 */ 112 void Player::addWeapon(Weapon* weapon) 113 { 114 this->weapons->add(weapon); 115 } 116 117 118 /** 119 \brief removes a weapon from the player 120 \param weapon to remove 121 */ 122 void Player::removeWeapon(Weapon* weapon) 123 { 124 this->weapons->remove(weapon); 125 } 126 110 127 111 128 /** … … 114 131 void Player::postSpawn () 115 132 { 116 travelSpeed = 15.0;117 velocity = Vector();118 bUp = bDown = bLeft = bRight = bAscend = bDescend = false;119 bFire = false;120 acceleration = 10.0;121 133 //setCollision(new CollisionCluster(1.0, Vector(0,0,0))); 122 134 } 123 135 124 /** 125 \brief the function called for each passing timeSnap 126 \param time The timespan passed since last update 127 */ 128 void Player::tick (float time) 129 { 130 // movement 131 this->move (time); 132 } 136 137 /** 138 \brief the action occuring if the player left the game 139 */ 140 void Player::leftWorld () 141 {} 142 143 133 144 134 145 /** … … 137 148 \param loc ?? 138 149 */ 139 void Player::hit (WorldEntity* weapon, Vector loc) 140 { 141 } 142 143 /** 144 \brief action that happens when the player is destroyed. 145 */ 146 void Player::destroy () 147 { 148 } 150 void Player::hit (WorldEntity* weapon, Vector* loc) 151 { 152 } 153 149 154 150 155 /** … … 158 163 } 159 164 160 /**161 \brief The connection to the command node162 \param cmd the Command unit from witch to map163 164 here the commands are mapped to the players movement/weaponary165 */166 void Player::command (Command* cmd)167 {168 //printf("Player|recieved command [%s]\n", cmd->cmd);169 if( !strcmp( cmd->cmd, "up")) bUp = !cmd->bUp;170 else if( !strcmp( cmd->cmd, "down")) bDown = !cmd->bUp;171 else if( !strcmp( cmd->cmd, "left")) bLeft = !cmd->bUp;172 else if( !strcmp( cmd->cmd, "right")) bRight = !cmd->bUp;173 else if( !strcmp( cmd->cmd, "fire")) bFire = !cmd->bUp;174 }175 165 176 166 /** … … 180 170 { 181 171 glMatrixMode(GL_MODELVIEW); 182 gl LoadIdentity();172 glPushMatrix(); 183 173 float matrix[4][4]; 184 174 … … 191 181 glMultMatrixf((float*)matrix); 192 182 193 glMatrixMode(GL_MODELVIEW);194 183 this->model->draw(); 195 // glCallList(objectList); 196 } 197 198 199 /*PN 200 void Player::getLookat(Location* locbuf) 201 { 202 *locbuf = *getLocation(); 203 //locbuf->dist += 5.0; 204 } 205 */ 206 207 /** 208 \brief the action occuring if the player left the game 209 */ 210 void Player::leftWorld () 211 { 212 } 184 glPopMatrix(); 185 } 186 187 188 /** 189 \brief the function called for each passing timeSnap 190 \param time The timespan passed since last update 191 */ 192 void Player::tick (float time) 193 { 194 // player controlled movement 195 this->move (time); 196 // weapon system manipulation 197 this->fire(); 198 } 199 213 200 214 201 /** … … 220 207 Vector accel(0.0, 0.0, 0.0); 221 208 /* FIXME: calculating the direction and orthDirection every timeSlice is redundant! save it somewhere */ 222 //Placement *pos = getPlacement();223 209 224 210 /* calculate the direction in which the craft is heading */ … … 228 214 //orthDirection = orthDirection.cross (direction); 229 215 230 if( bUp) { accel = accel+(direction*acceleration); } 231 if( bDown) { accel = accel-(direction*acceleration); } 232 if( bLeft ) { accel = accel - (orthDirection*acceleration); } 233 if( bRight ) { accel = accel + (orthDirection*acceleration); } 234 if( bAscend ) { /* not yet implemented but just: (0,0,1)*acceleration */} 235 if( bDescend) {/* FIXME */} /* \todo up and down player movement */ 236 237 //Location* l = getLocation(); 238 239 // r(t) = r(0) + v(0)*t + 1/2*a*t^2 240 // r = position 241 // v = velocity 242 // a = acceleration 243 244 /* this the base-speed of the player: determines how fast and how the player follows the track*/ 245 //l->dist = l->dist + travelSpeed * time; 246 247 Vector* shift = new Vector (this->travelSpeed * time, 0, 0); 248 this->shiftCoor (shift); 249 250 /* this updates the player position on the track - user interaction */ 251 //l->pos = l->pos + accel*time; 216 if( this->bUp && this->getRelCoor().x < 20) 217 accel = accel+(direction*acceleration); 218 if( this->bDown && this->getRelCoor().x > -5) 219 accel = accel-(direction*acceleration); 220 if( this->bLeft && TrackManager::getInstance()->getWidth() > -this->getRelCoor().z*2) 221 accel = accel - (orthDirection*acceleration); 222 if( this->bRight && TrackManager::getInstance()->getWidth() > this->getRelCoor().z*2) 223 accel = accel + (orthDirection*acceleration); 224 if( this->bAscend ) 225 if( this->bDescend) {/* FIXME */} /* \todo up and down player movement */ 226 252 227 Vector move = accel * time; 253 228 this->shiftCoor (&move); 254 229 } 230 231 232 /** 233 \brief weapon manipulation by the player 234 */ 235 void Player::fire() 236 { 237 if(this->bFire) 238 { 239 if(this->activeWeapon != NULL) 240 this->activeWeapon->fire(); 241 } 242 if(this->bWeaponChange) 243 { 244 Weapon* w = this->weapons->enumerate(); 245 this->activeWeapon = this->weapons->nextElement(this->activeWeapon); 246 } 247 } 248 249 250 /** 251 \brief The connection to the command node 252 \param cmd the Command unit from witch to map 253 254 here the commands are mapped to the players movement/weaponary 255 */ 256 void Player::command (Command* cmd) 257 { 258 PRINTF(3)("recieved command [%s]\n", cmd->cmd); 259 if( !strcmp( cmd->cmd, "up")) this->bUp = !cmd->bUp; 260 else if( !strcmp( cmd->cmd, "down")) this->bDown = !cmd->bUp; 261 else if( !strcmp( cmd->cmd, "left")) this->bLeft = !cmd->bUp; 262 else if( !strcmp( cmd->cmd, "right")) this->bRight = !cmd->bUp; 263 else if( !strcmp( cmd->cmd, "fire")) this->bFire = !cmd->bUp; 264 else if( !strcmp( cmd->cmd, "mode")) this->bWeaponChange = !cmd->bUp; 265 }
Note: See TracChangeset
for help on using the changeset viewer.