Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

Changeset 4780 in orxonox.OLD for orxonox/trunk/src/world_entities


Ignore:
Timestamp:
Jul 2, 2005, 10:55:47 PM (19 years ago)
Author:
bensch
Message:

orxonox/trunk: 1. the crosshair is registered, @patrick: i thought it was a little bit harder… worked myself through the EventSystem, it is quite cool :)

  1. Player now knows a loadParams and init routine

also testing the Crosshair inside of the Player

Location:
orxonox/trunk/src/world_entities
Files:
3 edited

Legend:

Unmodified
Added
Removed
  • orxonox/trunk/src/world_entities/player.cc

    r4762 r4780  
    3333#include "event.h"
    3434
     35#include "crosshair.h"
     36
    3537using namespace std;
    3638
     
    4850     the player.cc for debug also
    4951  */
     52  this->init();
     53
     54  //weapons:
     55  this->weaponMan = new WeaponManager();
     56  Weapon* wpRight = new TestGun(this, Vector(-2.6, 0.1, 3.0), Quaternion(), 0);
     57  Weapon* wpLeft = new TestGun(this, Vector(-2.6, 0.1, -3.0), Quaternion(), 1);
     58
     59  this->weaponMan->addWeapon(wpRight, W_CONFIG0, W_SLOT0);
     60  this->weaponMan->addWeapon(wpLeft, W_CONFIG1, W_SLOT1);
     61  this->weaponMan->addWeapon(wpRight, W_CONFIG2);
     62  this->weaponMan->addWeapon(wpLeft, W_CONFIG2);
     63
     64}
     65
     66
     67/**
     68   \brief destructs the player, deletes alocated memory
     69*/
     70Player::~Player ()
     71{
     72  /* do not delete the weapons, they are contained in the pnode tree
     73     and will be deleted there.
     74     this only frees the memory allocated to save the list.
     75  */
     76  delete this->weaponMan;
     77}
     78
     79
     80/**
     81   \brief creates a new Player from Xml Data
     82   \param root the xml element containing player data
     83
     84   \todo add more parameters to load
     85*/
     86Player::Player(const TiXmlElement* root)
     87{
     88  this->init();
     89  this->loadParams(root);
     90
     91  //weapons:
     92  this->weaponMan = new WeaponManager();
     93  Weapon* wpRight = new TestGun(this, Vector(-2.6, 0.1, 3.0), Quaternion(), 0);
     94  Weapon* wpLeft = new TestGun(this, Vector(-2.6, 0.1, -3.0), Quaternion(), 1);
     95
     96  this->weaponMan->addWeapon(wpRight, W_CONFIG0, W_SLOT0);
     97  this->weaponMan->addWeapon(wpLeft, W_CONFIG1, W_SLOT1);
     98  this->weaponMan->addWeapon(wpRight, W_CONFIG2);
     99  this->weaponMan->addWeapon(wpLeft, W_CONFIG2);
     100
     101
     102  new Crosshair();
     103}
     104
     105/**
     106 * initializes a Player
     107 */
     108void Player::init()
     109{
    50110  this->setClassID(CL_PLAYER, "Player");
    51111
     
    57117  this->bWeaponChange = false;
    58118  acceleration = 10.0;
    59   //weapons:
    60   this->weaponMan = new WeaponManager();
    61   Weapon* wpRight = new TestGun(this, Vector(-2.6, 0.1, 3.0), Quaternion(), 0);
    62   Weapon* wpLeft = new TestGun(this, Vector(-2.6, 0.1, -3.0), Quaternion(), 1);
    63 
    64   this->weaponMan->addWeapon(wpRight, W_CONFIG0, W_SLOT0);
    65   this->weaponMan->addWeapon(wpLeft, W_CONFIG1, W_SLOT1);
    66   this->weaponMan->addWeapon(wpRight, W_CONFIG2);
    67   this->weaponMan->addWeapon(wpLeft, W_CONFIG2);
    68 }
    69 
    70 
    71 /**
    72    \brief destructs the player, deletes alocated memory
    73 */
    74 Player::~Player ()
    75 {
    76   /* do not delete the weapons, they are contained in the pnode tree
    77      and will be deleted there.
    78      this only frees the memory allocated to save the list.
    79   */
    80   delete this->weaponMan;
    81 }
    82 
    83 
    84 /**
    85    \brief creates a new Player from Xml Data
    86    \param root the xml element containing player data
    87 
    88    \todo add more parameters to load
    89 */
    90 Player::Player(const TiXmlElement* root) : WorldEntity(root)
    91 {
    92   this->setClassID(CL_PLAYER, "Player");
    93 
    94   this->weapons = new tList<Weapon>();
    95   this->activeWeapon = NULL;
    96   /*
    97     this is the debug player - actualy we would have to make a new
    98      class derivated from Player for each player. for now, we just use
    99      the player.cc for debug also
    100   */
    101   travelSpeed = 15.0;
    102   velocity = new Vector();
    103   bUp = bDown = bLeft = bRight = bAscend = bDescend = false;
    104   bFire = false;
    105   this->bWeaponChange = false;
    106   acceleration = 10.0;
    107   //weapons:
    108   this->weaponMan = new WeaponManager();
    109   Weapon* wpRight = new TestGun(this, Vector(-2.6, 0.1, 3.0), Quaternion(), 0);
    110   Weapon* wpLeft = new TestGun(this, Vector(-2.6, 0.1, -3.0), Quaternion(), 1);
    111 
    112   this->weaponMan->addWeapon(wpRight, W_CONFIG0, W_SLOT0);
    113   this->weaponMan->addWeapon(wpLeft, W_CONFIG1, W_SLOT1);
    114   this->weaponMan->addWeapon(wpRight, W_CONFIG2);
    115   this->weaponMan->addWeapon(wpLeft, W_CONFIG2);
     119}
     120
     121
     122/**
     123 *
     124 * @param root the XML-element to load the Player's properties from
     125 */
     126void Player::loadParams(const TiXmlElement* root)
     127{
     128  static_cast<WorldEntity*>(this)->loadParams(root);
     129
     130
     131
    116132}
    117133
  • orxonox/trunk/src/world_entities/player.h

    r4746 r4780  
    1 /*! 
     1/*!
    22    \file player.h
    33    \brief Implements a basic controllable WorldEntity
     
    2222{
    2323  friend class World;
    24  
     24
    2525 public:
    2626  Player();
     
    2828  virtual ~Player();
    2929
     30  void init();
     31  void loadParams(const TiXmlElement* root);
     32
    3033  void addWeapon(Weapon* weapon);
    3134  void removeWeapon(Weapon* weapon);
    32  
     35
    3336  virtual void postSpawn();
    3437  virtual void leftWorld();
     
    3639  virtual void collide(WorldEntity* other, Uint32 ownhitflags, Uint32 otherhitflags);
    3740
    38   virtual void tick(float time); 
     41  virtual void tick(float time);
    3942  virtual void draw();
    4043
     
    4245
    4346  virtual void process(const Event &event);
    44  
     47
    4548 private:
    4649  bool bUp;              //!< up button pressed.
     
    6366  float travelSpeed;     //!< the current speed of the player (to make soft movement)
    6467  float acceleration;    //!< the acceleration of the player.
    65  
     68
    6669  void move(float time);
    6770  void weapon();
    68  
     71
    6972};
    7073
  • orxonox/trunk/src/world_entities/weapons/crosshair.cc

    r4779 r4780  
    1717
    1818#include "crosshair.h"
    19 
     19#include "event_handler.h"
    2020using namespace std;
    2121
     
    2323/**
    2424   \brief standard constructor
    25    \todo this constructor is not jet implemented - do it
    2625*/
    2726Crosshair::Crosshair ()
     
    3029  this->setName("Crosshair");
    3130
     31  EventHandler::getInstance()->subscribe(this, ES_GAME, EV_MOUSE_MOTION);
     32
    3233}
    3334
     
    3536/**
    3637   \brief standard deconstructor
    37 
    3838*/
    3939Crosshair::~Crosshair ()
     
    4444void Crosshair::process(const Event &event)
    4545{
    46 
     46  printf("wow\n");
    4747
    4848}
Note: See TracChangeset for help on using the changeset viewer.