Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

Ignore:
Timestamp:
Apr 7, 2005, 3:54:49 PM (19 years ago)
Author:
chris
Message:

orxonox/branches/levelloader: Merged trunk into branch… still not working though…

File:
1 edited

Legend:

Unmodified
Added
Removed
  • orxonox/branches/levelloader/src/world_entities/player.cc

    r3605 r3746  
    2020#include "player.h"
    2121
     22#include "track_manager.h"
     23#include "objModel.h"
     24#include "resource_manager.h"
     25#include "weapon.h"
     26#include "test_gun.h"
     27#include "world.h"
     28
     29#include "list.h"
    2230#include "stdincl.h"
    23 //#include "collision.h"
    24 #include "objModel.h"
    25 #include "list.h"
    26 #include "weapon.h"
    27 #include "track_manager.h"
    2831
    2932using namespace std;
     
    3538   \param isFree if the player is free
    3639*/
    37 Player::Player(bool isFree) : WorldEntity(isFree)
    38 {
    39   this->model = new OBJModel("../data/models/reaplow.obj");
     40Player::Player() : WorldEntity()
     41{
    4042  this->weapons = new tList<Weapon>();
    4143  this->activeWeapon = NULL;
    42 
     44  /*
     45    this is the debug player - actualy we would have to make a new
     46     class derivated from Player for each player. for now, we just use
     47     the player.cc for debug also
     48  */
     49  this->model = (Model*)ResourceManager::getInstance()->load("models/reaplow.obj", OBJ, RP_CAMPAIGN);
    4350  travelSpeed = 15.0;
    44   velocity = Vector();
     51  velocity = new Vector();
    4552  bUp = bDown = bLeft = bRight = bAscend = bDescend = false;
    4653  bFire = false;
    4754  acceleration = 10.0;
     55  //weapons:
     56  Weapon* wp = new TestGun(this, new Vector(-1.1, 0.0, 2.6), new Quaternion());
     57  this->weapons->add(wp);
     58  this->activeWeapon = wp; 
    4859}
    4960
     
    5364Player::~Player ()
    5465{
    55   Weapon* w = this->weapons->enumerate();
    56   while( w != NULL)
    57     {
    58       delete w;
    59       w = this->weapons->nextElement();
    60     }
     66  /* do not delete the weapons, they are contained in the pnode tree
     67     and will be deleted there.
     68     this only frees the memory allocated to save the list.
     69  */
    6170  delete this->weapons;
    62  
    63   //delete this->velocity;
    6471}
    6572
     
    94101        string = grabParameter( root, "model");
    95102        if( string != NULL)
    96                 this->model = new OBJModel( string);
     103        this->model = (Model*)ResourceManager::getInstance()->load(string, OBJ, RP_CAMPAIGN);
    97104        else
    98105        {
    99106                PRINTF0("Player is missing a proper 'model'\n");
    100                 this->model = new OBJModel( "../data/models/reaplow.obj");
     107        this->model = (Model*)ResourceManager::getInstance()->load("models/reaplow.obj", OBJ, RP_CAMPAIGN);
    101108        }
    102109        if( this->model == NULL)
     
    104111                PRINTF0("Player model '%s' could not be loaded\n", string);
    105112        }
     113       
     114        this->weapons = new tList<Weapon>();
     115  this->activeWeapon = NULL;
     116  /*
     117    this is the debug player - actualy we would have to make a new
     118     class derivated from Player for each player. for now, we just use
     119     the player.cc for debug also
     120  */
     121  travelSpeed = 15.0;
     122  velocity = new Vector();
     123  bUp = bDown = bLeft = bRight = bAscend = bDescend = false;
     124  bFire = false;
     125  acceleration = 10.0;
     126  //weapons:
     127  Weapon* wp = new TestGun(this, new Vector(-1.1, 0.0, 2.6), new Quaternion());
     128  this->weapons->add(wp);
     129  this->activeWeapon = wp;
    106130}
    107131
     
    192216void Player::tick (float time)
    193217{
     218  /* link tick to weapon */
     219  this->activeWeapon->tick(time);
    194220  // player controlled movement
    195   this->move (time);
     221  this->move(time);
    196222  // weapon system manipulation
    197   this->fire();
     223  this->weapon();
    198224}
    199225
     
    214240  //orthDirection = orthDirection.cross (direction);
    215241
    216   if( this->bUp && this->getRelCoor().x < 20)
     242  if( this->bUp && this->getRelCoor()->x < 20)
    217243    accel = accel+(direction*acceleration);
    218   if( this->bDown && this->getRelCoor().x > -5)
     244  if( this->bDown && this->getRelCoor()->x > -5)
    219245    accel = accel-(direction*acceleration);
    220   if( this->bLeft &&  TrackManager::getInstance()->getWidth() > -this->getRelCoor().z*2)
     246  if( this->bLeft &&  TrackManager::getInstance()->getWidth() > -this->getRelCoor()->z*2)
    221247    accel = accel - (orthDirection*acceleration);
    222   if( this->bRight &&  TrackManager::getInstance()->getWidth() > this->getRelCoor().z*2)
     248  if( this->bRight &&  TrackManager::getInstance()->getWidth() > this->getRelCoor()->z*2)
    223249    accel = accel + (orthDirection*acceleration);
    224250  if( this->bAscend )
     
    233259   \brief weapon manipulation by the player
    234260*/
    235 void Player::fire()
    236 {
    237   if(this->bFire)
     261void Player::weapon()
     262{
     263  if( this->bFire)
    238264    {
    239265      if(this->activeWeapon != NULL)
    240266        this->activeWeapon->fire();
    241267    }
    242   if(this->bWeaponChange)
     268  if( this->bWeaponChange && this->weapons->getSize() > 1)
    243269    {
    244       Weapon* w = this->weapons->enumerate();
     270      PRINTF(1)("changing the weapon of the player: deactivate old, activate new\n");
     271      this->activeWeapon->deactivate();
     272      //this->weapons->enumerate();  FIX: strang weapon change...
    245273      this->activeWeapon = this->weapons->nextElement(this->activeWeapon);
     274      this->activeWeapon->activate();
    246275    }
    247276}
Note: See TracChangeset for help on using the changeset viewer.