Changeset 2190 in orxonox.OLD for orxonox/trunk/src/player.cc
- Timestamp:
- Jul 17, 2004, 12:11:20 PM (20 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
orxonox/trunk/src/player.cc
r2036 r2190 13 13 ### File Specific: 14 14 main-programmer: Patrick Boenzli 15 co-programmer: 15 co-programmer: Christian Meyer 16 16 */ 17 17 18 #include <iostream>19 #include <stdlib.h>20 #include <GL/glut.h>21 22 #include "shoot_laser.h"23 #include "shoot_rocket.h"24 #include "data_tank.h"25 26 18 #include "player.h" 19 #include "stdincl.h" 20 #include "collision.h" 27 21 28 22 using namespace std; 29 23 30 24 31 Player::Player() 32 : WorldEntity() { 33 //cout << "Player::Player" << endl; 34 xCor = yCor = zCor = 0; 35 shootLaser = new ShootLaser; 36 shootRocket = new ShootRocket; 25 Player::Player(bool isFree) : WorldEntity(isFree) 26 { 37 27 } 38 28 39 29 Player::~Player () 40 30 { 41 //delete shootLaser;42 31 } 43 32 44 45 void Player::setPosition( float x, float y, float z) 33 void Player::post_spawn () 46 34 { 47 xCor = x; yCor = y; zCor = z; 35 travel_speed = 10.0; 36 velocity = Vector(); 37 bUp = bDown = bLeft = bRight = bAscend = bDescend = false; 38 bFire = false; 39 acceleration = 10.0; 40 set_collision (new CollisionCluster (1.0, Vector(0,0,0))); 48 41 } 49 42 50 51 void Player::getPosition(float* x, float* y, float* z) 43 void Player::tick (float time) 52 44 { 53 *x = xCor; *y = yCor; *z = zCor; 45 // movement 46 move (time); 54 47 } 55 48 56 57 void Player::setCollisionRadius(float radius) 49 void Player::hit (WorldEntity* weapon, Vector loc) 58 50 { 59 collisionRadius = radius;60 51 } 61 52 62 63 void Player::goX(float x) 53 void Player::destroy () 64 54 { 65 xCor += x;66 55 } 67 56 68 69 void Player::goY(float y) 57 void Player::collide (WorldEntity* other, Uint32 ownhitflags, Uint32 otherhitflags) 70 58 { 71 yCor += y;72 59 } 73 60 74 void Player:: goZ(float z)61 void Player::command (Command* cmd) 75 62 { 76 zCor += z; 63 printf("Player|recieved command [%s]\n", cmd->cmd); 64 if( !strcmp( cmd->cmd, "up")) bUp = !cmd->bUp; 65 else if( !strcmp( cmd->cmd, "down")) bDown = !cmd->bUp; 66 else if( !strcmp( cmd->cmd, "left")) bLeft = !cmd->bUp; 67 else if( !strcmp( cmd->cmd, "right")) bRight = !cmd->bUp; 68 else if( !strcmp( cmd->cmd, "fire")) bFire = !cmd->bUp; 77 69 } 78 70 71 void Player::draw () 72 { 73 glMatrixMode(GL_MODELVIEW); 74 glLoadIdentity(); 75 float matrix[4][4]; 79 76 80 81 void Player::shoot(int n) 82 { 83 84 // if (shootLaser->inhibitor++ <= 100) 85 shootLaser->addShoot(xCor, yCor, zCor); 86 // else if (shootLaser->inhibitor++ <= 200) 87 shootLaser->addShootExt(xCor, yCor, zCor, .1, .4, .0); 88 // else if (shootLaser->inhibitor++ <= 300) 89 shootLaser->addShootExt(xCor, yCor, zCor, -0.1, .4, .0); 90 // else 91 shootLaser->inhibitor =0; 92 93 // if (shootRocket->inhibitor++ >=80) 94 { 95 shootRocket->addBackParable(xCor, yCor, zCor); 96 shootRocket->addSideAcc(xCor, yCor, zCor, RIGHT); 97 shootRocket->addSideAcc(xCor, yCor, zCor, LEFT); 98 shootRocket->addRotater(xCor, yCor, zCor); 99 // if (shootRocket->inhibitor >=90) 100 // shootRocket->inhibitor =0; 101 } 102 //cout << "Player::shoot" << endl; 103 104 /* 105 shootLaser->addShoot(xCor, yCor, zCor); 106 shootLaser->addShootExt(xCor, yCor, zCor, .1, .4, .0); 107 shootLaser->addShootExt(xCor, yCor, zCor, -0.1, .4, .0); 108 //shootRocket->addShoot(xCor, yCor, zCor); 109 //cout << "Player::shoot" << endl; 110 */ 77 glTranslatef(get_placement()->r.x,get_placement()->r.y,get_placement()->r.z); 78 get_placement()->w.matrix (matrix); 79 glMultMatrixf ((float*)matrix); 80 81 glBegin(GL_TRIANGLES); 82 glColor3f(1,0,0); 83 glVertex3f(0,0,0.5); 84 glColor3f(0,1,0); 85 glVertex3f(-0.5,0,-1); 86 glColor3f(0,0,1); 87 glVertex3f(0.5,0,-1); 88 glEnd(); 89 90 printf("Player@%f/%f/%f\n", get_placement()->r.x, get_placement()->r.y, get_placement()->r.z); 111 91 } 112 92 93 void Player::get_lookat (Location* locbuf) 94 { 95 *locbuf = *get_location(); 96 //locbuf->dist += 5.0; 97 } 113 98 114 //void Player::addIO(InputOutput *io) {} 99 void Player::left_world () 100 { 101 } 115 102 116 117 void Player::paint() 103 void Player::move (float time) 118 104 { 119 //cout << "Player::drawPlayer" << endl; 120 glPushMatrix(); 121 glTranslatef(xCor, yCor, 3.0); 122 glScalef(1.0, 3.0, 1.0); 123 glutWireCube(1.0); 124 glPopMatrix(); 125 /* draw all the shoots additionaly */ 126 shootLaser->drawShoot(); 127 shootRocket->drawShoot(); 128 //cout << "Player::drawPlayer, end" << endl; 105 float xAccel, yAccel, zAccel; 106 xAccel = yAccel = zAccel = 0; 107 if( bUp) xAccel += acceleration; 108 if( bDown) xAccel -= acceleration; 109 if( bLeft) yAccel += acceleration; 110 if( bRight) yAccel -= acceleration; 111 if( bAscend) zAccel += acceleration; 112 if( bDescend) zAccel -= acceleration; 113 114 Vector accel( xAccel, yAccel, zAccel); 115 116 Location* l = get_location(); 117 118 // r(t) = r(0) + v(0)*t + 1/2*a*t^2 119 // r = position 120 // v = velocity 121 // a = acceleration 122 123 l->pos = l->pos + velocity*time + (accel*(0.5*time*time)); 124 l->dist += travel_speed * time; 125 126 velocity = velocity + (accel * time); 127 printf("Player|velocity %f/%f/%f\n", velocity.x, velocity.y, velocity.z); 129 128 } 130 129 … … 146 145 147 146 148 149 150 151 152 153 154 155
Note: See TracChangeset
for help on using the changeset viewer.