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