Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

Changeset 6107 in orxonox.OLD for branches/powerups


Ignore:
Timestamp:
Dec 14, 2005, 3:15:54 PM (19 years ago)
Author:
manuel
Message:

implemented param_power_up.
started some powerup respawn possibilities
powerups don't display yet!

Location:
branches/powerups/src
Files:
6 edited
2 copied

Legend:

Unmodified
Added
Removed
  • branches/powerups/src/defs/class_id.h

    r5965 r6107  
    150150  CL_LASER_POWER_UP             =    0x00000212,
    151151  CL_WEAPON_POWER_UP            =    0x00000213,
    152   CL_SHIELD_POWER_UP            =    0x00000214,
     152  CL_PARAM_POWER_UP             =    0x00000214,
    153153
    154154  CL_TEST_GUN                   =    0x00000230,
  • branches/powerups/src/world_entities/power_ups/param_power_up.cc

    r6040 r6107  
    2828using namespace std;
    2929
    30 CREATE_FACTORY(WeaponPowerUp, CL_WEAPON_POWER_UP);
     30CREATE_FACTORY(ParamPowerUp, CL_PARAM_POWER_UP);
    3131
    32 WeaponPowerUp::WeaponPowerUp () : PowerUp(0.0, 1.0, 0.0)
     32ParamPowerUp::ParamPowerUp () : PowerUp(0.0, 0.0, 1.0)
    3333{
    3434  this->init();
    3535}
    3636
    37 WeaponPowerUp::WeaponPowerUp(const TiXmlElement* root) : PowerUp(0.0, 1.0, 0.0)
     37ParamPowerUp::ParamPowerUp(const TiXmlElement* root) : PowerUp(0.0, 0.0, 1.0)
    3838{
    3939  this->init();
     
    4242
    4343
    44 WeaponPowerUp::~WeaponPowerUp ()
     44ParamPowerUp::~ParamPowerUp ()
    4545{
    4646}
    4747
    4848
    49 void WeaponPowerUp::init()
     49void ParamPowerUp::init()
    5050{
    51   weaponXML = NULL;
    52   weapon = NULL;
     51  this->value = 0;
     52  this->max_value = 0;
     53  this->min_value = 0;
    5354}
    5455
    5556
    56 void WeaponPowerUp::loadParams(const TiXmlElement* root)
     57void ParamPowerUp::loadParams(const TiXmlElement* root)
    5758{
    5859  static_cast<PowerUp*>(this)->loadParams(root);
    59   const TiXmlElement* elem = root->FirstChildElement("weapon");
    60   if(elem != NULL && (elem = elem->FirstChildElement()) != NULL)
    61   {
    62     this->weaponXML = elem;
    63     createWeapon();
     60  LoadParam(root, "type", this, ParamPowerUp, setType);
     61  if(root->FirstChildElement("value") != NULL) {
     62    LoadParam(root, "value", this, ParamPowerUp, setValue);
    6463  }
    65   else
    66   {
    67     LoadParam(root, "weaponID", this, WeaponPowerUp, setWeaponClass);
     64  else {
     65    LoadParam(root, "max-value", this, ParamPowerUp, setMaxValue);
     66    LoadParam(root, "min-value", this, ParamPowerUp, setMinValue);
     67    respawn();
    6868  }
    6969}
    7070
    71 Weapon* WeaponPowerUp::getWeapon()
     71void ParamPowerUp::setValue(int value)
    7272{
    73   return this->weapon;
     73  this->value = value;
    7474}
    7575
    76 void WeaponPowerUp::createWeapon()
     76void ParamPowerUp::setType(const char* type)
    7777{
    78   this->weapon = dynamic_cast<Weapon*>((weaponXML == NULL)
    79       ? Factory::fabricate(static_cast<ClassID>(this->weapon->getClassID()))
    80       : Factory::fabricate(weaponXML));
     78  for(int i = 0; i < PARAM_size; ++i) {
     79    if(strcmp(type, paramTypes[i]) == 0) {
     80      this->type = (EnumParamPowerUpType)i;
     81      break;
     82    }
     83  }
    8184}
    8285
    83 void WeaponPowerUp::setWeaponClass(const char* name)
     86void ParamPowerUp::setMaxValue(int value)
    8487{
    85   this->weapon = dynamic_cast<Weapon*>(Factory::fabricate(name));
     88  this->max_value = value;
    8689}
    8790
    88 void WeaponPowerUp::hide()
     91void ParamPowerUp::setMinValue(int value)
    8992{
    90   PowerUp::hide();
    91   this->createWeapon();
     93  this->min_value = value;
    9294}
     95
     96int ParamPowerUp::getValue()
     97{
     98  return this->value;
     99}
     100
     101EnumParamPowerUpType ParamPowerUp::getType()
     102{
     103  return this->type;
     104}
     105
     106void ParamPowerUp::respawn()
     107{
     108  if(this->min_value != this->max_value)
     109  {
     110    value = this->min_value + (int)(rand() * (this->max_value - this->min_value));
     111  }
     112}
     113
     114const char* ParamPowerUp::paramTypes[] = {
     115  "shield"
     116};
     117
     118
  • branches/powerups/src/world_entities/power_ups/param_power_up.h

    r6006 r6107  
    11/*!
    22 * @file weapon_power_up.h
    3  * @brief A class representing a PowerUp containing a weapon.
     3 * @brief A class representing a PowerUp modifying parameters.
    44*/
    55
    6 #ifndef _WEAPON_POWER_UP_H
    7 #define _WEAPON_POWER_UP_H
     6#ifndef _PARAM_POWER_UP_H
     7#define _PARAM_POWER_UP_H
    88
    99#include "power_up.h"
    10 #include "weapons/weapon.h"
    1110
    1211/* FORWARD DEFINITION */
    1312
    14 class WeaponPowerUp : public PowerUp {
     13typedef enum EnumParamPowerUpType {
     14  PARAM_SHIELD,
     15  PARAM_size
     16} EnumParamPowerUpType;
     17
     18class ParamPowerUp : public PowerUp {
    1519
    1620public:
    17   WeaponPowerUp();
    18   WeaponPowerUp(const TiXmlElement* root);
    19   virtual ~WeaponPowerUp ();
     21  ParamPowerUp();
     22  ParamPowerUp(const TiXmlElement* root);
     23  virtual ~ParamPowerUp ();
    2024
    21   Weapon* getWeapon();
    22   void setWeaponClass(const char* name);
     25  void setValue(int value);
     26  void setType(EnumParamPowerUpType type)
    2327
    2428protected:
    25   void hide();
     29  virtual void respawn();
    2630
    2731private:
    2832  void init();
    2933  void loadParams(const TiXmlElement* root);
     34
    3035private:
    31   Weapon* weapon;
    32   const TiXmlElement* weaponXML;
    33 
    34   void createWeapon();
     36  static const char* paramTypes;
     37  EnumParamPowerUpType type;
     38  int value;
     39  int max_value;
     40  int min_value;
    3541};
    3642
    37 #endif /* _WEAPON_POWER_UP_H */
     43#endif /* _PARAM_POWER_UP_H */
  • branches/powerups/src/world_entities/power_ups/power_up.cc

    r6040 r6107  
    5050    if(dynamic_cast<Extendable*>(entity)->pickup(this))
    5151    {
    52       this->hide();
     52      this->setVisibiliy(false);
    5353    }
    5454  }
    5555}
    5656
    57 void PowerUp::hide()
     57void PowerUp::draw() const
    5858{
    59   this->setVisibiliy(false);
     59  WorldEntity::draw();
     60
     61  glMatrixMode(GL_MODELVIEW);
     62  glPushMatrix();
     63  float matrix[4][4];
     64
     65  /* translate */
     66  glTranslatef (this->getAbsCoor ().x,
     67                this->getAbsCoor ().y,
     68                this->getAbsCoor ().z);
     69  /* rotate */ // FIXME: devise a new Way to rotate this
     70  this->getAbsDir ().matrix (matrix);
     71  glMultMatrixf((float*)matrix);
     72
     73  this->sphereMaterial->select();
     74  sphereModel->draw();
     75
     76  glPopMatrix();
    6077}
    6178
    62 void PowerUp::draw()
     79const char* PowerUp::respawnTypes[] = {
     80  "none",
     81  "time"
     82};
     83
     84void PowerUp::setRespawnType(const char* type)
    6385{
    64   WorldEntity::draw();
    65   this->sphereMaterial->select();
    66   sphereModel->draw();
     86  for(int i = 0; i < RESPAWN_size; ++i) {
     87    if(strcmp(type, respawnTypes[i]) == 0) {
     88      this->respawnType = (PowerUpRespawn)i;
     89      break;
     90    }
     91  }
    6792}
    6893
  • branches/powerups/src/world_entities/power_ups/power_up.h

    r6040 r6107  
    1111class Material;
    1212
     13typedef enum PowerUpRespawn {
     14  RESPAWN_NONE,
     15  RESPAWN_TIME,
     16  RESPAWN_size
     17} PowerUpRespawn;
     18
    1319class PowerUp : public WorldEntity {
    1420
     
    1723  void collidesWith (WorldEntity* entity, const Vector& location);
    1824
    19   void draw();
     25  virtual void draw () const;
     26  void setRespawnType(const char* type);
    2027
    2128protected:
    2229  PowerUp(float r, float g, float b);
    2330  virtual ~PowerUp ();
    24   virtual void hide();
     31  virtual void respawn() {};
    2532
    2633  static Model* sphereModel;
     
    2835private:
    2936  Material* sphereMaterial;
     37  PowerUpRespawn respawnType;
     38  static const char* respawnTypes[];
    3039};
    3140
  • branches/powerups/src/world_entities/power_ups/weapon_power_up.cc

    r6040 r6107  
    6161  {
    6262    this->weaponXML = elem;
    63     createWeapon();
     63    respawn();
    6464  }
    6565  else
     
    7474}
    7575
    76 void WeaponPowerUp::createWeapon()
     76void WeaponPowerUp::respawn()
    7777{
    7878  this->weapon = dynamic_cast<Weapon*>((weaponXML == NULL)
     
    8585  this->weapon = dynamic_cast<Weapon*>(Factory::fabricate(name));
    8686}
    87 
    88 void WeaponPowerUp::hide()
    89 {
    90   PowerUp::hide();
    91   this->createWeapon();
    92 }
  • branches/powerups/src/world_entities/power_ups/weapon_power_up.h

    r5988 r6107  
    2323
    2424protected:
    25   void hide();
     25  virtual void respawn();
    2626
    2727private:
  • branches/powerups/src/world_entities/space_ships/space_ship.cc

    r5988 r6107  
    427427    }
    428428  }
    429   else if(powerUp->isA(CL_SHIELD_POWER_UP)) {
     429  else if(powerUp->isA(CL_PARAM_POWER_UP)) {
    430430
    431431  }
Note: See TracChangeset for help on using the changeset viewer.