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