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