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