Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

Changeset 2096 in orxonox.OLD for orxonox/branches/chris/src/player.cc


Ignore:
Timestamp:
Jul 9, 2004, 11:14:42 AM (21 years ago)
Author:
chris
Message:

orxonox/branches/chris: Messed with the Player class, added stuff here and there, debug world now creates a player and bind IO to it. Added some doxygen tags.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • orxonox/branches/chris/src/player.cc

    r2058 r2096  
    1313   ### File Specific:
    1414   main-programmer: Patrick Boenzli
    15    co-programmer:
     15   co-programmer: Christian Meyer
    1616*/
    1717
     
    2020#include <GL/glut.h>
    2121
    22 #include "shoot_laser.h"
    23 #include "shoot_rocket.h"
    24 #include "data_tank.h"
    25 
    2622#include "player.h"
    2723
     
    2925
    3026
    31 Player::Player()
    32    : WorldEntity() {
    33   //cout << "Player::Player" << endl;
    34   xCor = yCor = zCor = 0;
    35   shootLaser = new ShootLaser;
    36   shootRocket = new ShootRocket;
     27Player::Player(bool isFree) : WorldEntity(isFree)
     28{
    3729}
    3830
    3931Player::~Player ()
    4032{
    41   //delete shootLaser;
    4233}
    4334
    44 
    45 void Player::setPosition( float x, float y, float z)
     35void Player::post_spawn ()
    4636{
    47   xCor = x; yCor = y; zCor = z;
     37        travel_speed = 1.0;
     38        velocity = Vector();
     39        bUp = bDown = bLeft = bRight = bAscend = bDescend = false;
     40        bFire = false;
     41        acceleration = 10.0;
     42        set_collision (new CollisionCluster (1.0, Vector(0,0,0));
    4843}
    4944
    50 
    51 void Player::getPosition(float* x, float* y, float* z)
     45void Player::tick (float time)
    5246{
    53   *x = xCor; *y = yCor; *z = zCor;
     47        // movement
     48        move (float time);
    5449}
    5550
    56 
    57 void Player::setCollisionRadius(float radius)
     51void Player::hit (WorldEntity* weapon, Vector loc)
    5852{
    59   collisionRadius = radius;
    6053}
    6154
    62 
    63 void Player::goX(float x)
     55void Player::destroy ()
    6456{
    65   xCor += x;
    6657}
    6758
    68 
    69 void Player::goY(float y)
     59void Player::collide (WorldEntity* other,  Uint32 ownhitflags, Uint32 otherhitflags)
    7060{
    71   yCor += y;
    7261}
    7362
    74 void Player::goZ(float z)
     63void Player::command (Command* cmd)
    7564{
    76   zCor += z;
     65        if( strcmp( cmd->cmd, "up")) bUp = !cmd->bUp;
     66        else if( strcmp( cmd->cmd, "down")) bDown = !cmd->bUp;
     67        else if( strcmp( cmd->cmd, "left")) bLeft = !cmd->bUp;
     68        else if( strcmp( cmd->cmd, "right")) bRight = !cmd->bUp;
     69        else if( strcmp( cmd->cmd, "fire")) bFire = !cmd->bUp;
    7770}
    7871
    79 
    80 
    81 void Player::shoot(int n)
     72void Player::draw ()
    8273{
    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   */
    11174}
    11275
     76void Player::get_lookat (Location* locbuf)
     77{
     78        *locbuf = *get_location();
     79        locbuf->dist += 5.0;
     80}
    11381
    114 //void Player::addIO(InputOutput *io) {}
     82void Player::left_world ()
     83{
     84}
    11585
    116 
    117 void Player::paint()
     86void Player::move (float time)
    11887{
    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;
     88        float xAccel, yAccel, zAccel;
     89        xAccel = yAccel = zAccel = 0;
     90        if( bUp) xAccel += acceleration;
     91        if( bDown) xAccel -= acceleration;
     92        if( bLeft) yAccel += acceleration;
     93        if( bRight) yAccel -= acceleration;
     94        if( bAscend) zAccel += acceleration;
     95        if( bDescend) zAccel -= acceleration;
     96       
     97        Vector accel( xAccel, yAccel, zAccel);
     98       
     99        Location* l = get_location();
     100       
     101        // r(t) = r(0) + v(0)*t + 1/2*a*t^2
     102        // r = position
     103        // v = velocity
     104        // a = acceleration
     105       
     106        l->pos = l->pos + velocity*time + (accel*(0.5*t*t)));
     107        l->dist += travel_speed * time;
     108       
     109        velocity += accel * time;
    129110}
    130111
     
    146127
    147128
    148 
    149 
    150 
    151 
    152 
    153 
    154 
    155 
Note: See TracChangeset for help on using the changeset viewer.