Changeset 6107 in orxonox.OLD for branches/powerups
- Timestamp:
- Dec 14, 2005, 3:15:54 PM (19 years ago)
- Location:
- branches/powerups/src
- Files:
-
- 6 edited
- 2 copied
Legend:
- Unmodified
- Added
- Removed
-
branches/powerups/src/defs/class_id.h
r5965 r6107 150 150 CL_LASER_POWER_UP = 0x00000212, 151 151 CL_WEAPON_POWER_UP = 0x00000213, 152 CL_ SHIELD_POWER_UP= 0x00000214,152 CL_PARAM_POWER_UP = 0x00000214, 153 153 154 154 CL_TEST_GUN = 0x00000230, -
branches/powerups/src/world_entities/power_ups/param_power_up.cc
r6040 r6107 28 28 using namespace std; 29 29 30 CREATE_FACTORY( WeaponPowerUp, CL_WEAPON_POWER_UP);30 CREATE_FACTORY(ParamPowerUp, CL_PARAM_POWER_UP); 31 31 32 WeaponPowerUp::WeaponPowerUp () : PowerUp(0.0, 1.0, 0.0)32 ParamPowerUp::ParamPowerUp () : PowerUp(0.0, 0.0, 1.0) 33 33 { 34 34 this->init(); 35 35 } 36 36 37 WeaponPowerUp::WeaponPowerUp(const TiXmlElement* root) : PowerUp(0.0, 1.0, 0.0)37 ParamPowerUp::ParamPowerUp(const TiXmlElement* root) : PowerUp(0.0, 0.0, 1.0) 38 38 { 39 39 this->init(); … … 42 42 43 43 44 WeaponPowerUp::~WeaponPowerUp ()44 ParamPowerUp::~ParamPowerUp () 45 45 { 46 46 } 47 47 48 48 49 void WeaponPowerUp::init()49 void ParamPowerUp::init() 50 50 { 51 weaponXML = NULL; 52 weapon = NULL; 51 this->value = 0; 52 this->max_value = 0; 53 this->min_value = 0; 53 54 } 54 55 55 56 56 void WeaponPowerUp::loadParams(const TiXmlElement* root)57 void ParamPowerUp::loadParams(const TiXmlElement* root) 57 58 { 58 59 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); 64 63 } 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(); 68 68 } 69 69 } 70 70 71 Weapon* WeaponPowerUp::getWeapon()71 void ParamPowerUp::setValue(int value) 72 72 { 73 return this->weapon;73 this->value = value; 74 74 } 75 75 76 void WeaponPowerUp::createWeapon()76 void ParamPowerUp::setType(const char* type) 77 77 { 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 } 81 84 } 82 85 83 void WeaponPowerUp::setWeaponClass(const char* name)86 void ParamPowerUp::setMaxValue(int value) 84 87 { 85 this-> weapon = dynamic_cast<Weapon*>(Factory::fabricate(name));88 this->max_value = value; 86 89 } 87 90 88 void WeaponPowerUp::hide()91 void ParamPowerUp::setMinValue(int value) 89 92 { 90 PowerUp::hide(); 91 this->createWeapon(); 93 this->min_value = value; 92 94 } 95 96 int ParamPowerUp::getValue() 97 { 98 return this->value; 99 } 100 101 EnumParamPowerUpType ParamPowerUp::getType() 102 { 103 return this->type; 104 } 105 106 void 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 114 const char* ParamPowerUp::paramTypes[] = { 115 "shield" 116 }; 117 118 -
branches/powerups/src/world_entities/power_ups/param_power_up.h
r6006 r6107 1 1 /*! 2 2 * @file weapon_power_up.h 3 * @brief A class representing a PowerUp containing a weapon.3 * @brief A class representing a PowerUp modifying parameters. 4 4 */ 5 5 6 #ifndef _ WEAPON_POWER_UP_H7 #define _ WEAPON_POWER_UP_H6 #ifndef _PARAM_POWER_UP_H 7 #define _PARAM_POWER_UP_H 8 8 9 9 #include "power_up.h" 10 #include "weapons/weapon.h"11 10 12 11 /* FORWARD DEFINITION */ 13 12 14 class WeaponPowerUp : public PowerUp { 13 typedef enum EnumParamPowerUpType { 14 PARAM_SHIELD, 15 PARAM_size 16 } EnumParamPowerUpType; 17 18 class ParamPowerUp : public PowerUp { 15 19 16 20 public: 17 WeaponPowerUp();18 WeaponPowerUp(const TiXmlElement* root);19 virtual ~ WeaponPowerUp ();21 ParamPowerUp(); 22 ParamPowerUp(const TiXmlElement* root); 23 virtual ~ParamPowerUp (); 20 24 21 Weapon* getWeapon();22 void set WeaponClass(const char* name);25 void setValue(int value); 26 void setType(EnumParamPowerUpType type) 23 27 24 28 protected: 25 v oid hide();29 virtual void respawn(); 26 30 27 31 private: 28 32 void init(); 29 33 void loadParams(const TiXmlElement* root); 34 30 35 private: 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; 35 41 }; 36 42 37 #endif /* _ WEAPON_POWER_UP_H */43 #endif /* _PARAM_POWER_UP_H */ -
branches/powerups/src/world_entities/power_ups/power_up.cc
r6040 r6107 50 50 if(dynamic_cast<Extendable*>(entity)->pickup(this)) 51 51 { 52 this-> hide();52 this->setVisibiliy(false); 53 53 } 54 54 } 55 55 } 56 56 57 void PowerUp:: hide()57 void PowerUp::draw() const 58 58 { 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(); 60 77 } 61 78 62 void PowerUp::draw() 79 const char* PowerUp::respawnTypes[] = { 80 "none", 81 "time" 82 }; 83 84 void PowerUp::setRespawnType(const char* type) 63 85 { 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 } 67 92 } 68 93 -
branches/powerups/src/world_entities/power_ups/power_up.h
r6040 r6107 11 11 class Material; 12 12 13 typedef enum PowerUpRespawn { 14 RESPAWN_NONE, 15 RESPAWN_TIME, 16 RESPAWN_size 17 } PowerUpRespawn; 18 13 19 class PowerUp : public WorldEntity { 14 20 … … 17 23 void collidesWith (WorldEntity* entity, const Vector& location); 18 24 19 void draw(); 25 virtual void draw () const; 26 void setRespawnType(const char* type); 20 27 21 28 protected: 22 29 PowerUp(float r, float g, float b); 23 30 virtual ~PowerUp (); 24 virtual void hide();31 virtual void respawn() {}; 25 32 26 33 static Model* sphereModel; … … 28 35 private: 29 36 Material* sphereMaterial; 37 PowerUpRespawn respawnType; 38 static const char* respawnTypes[]; 30 39 }; 31 40 -
branches/powerups/src/world_entities/power_ups/weapon_power_up.cc
r6040 r6107 61 61 { 62 62 this->weaponXML = elem; 63 createWeapon();63 respawn(); 64 64 } 65 65 else … … 74 74 } 75 75 76 void WeaponPowerUp:: createWeapon()76 void WeaponPowerUp::respawn() 77 77 { 78 78 this->weapon = dynamic_cast<Weapon*>((weaponXML == NULL) … … 85 85 this->weapon = dynamic_cast<Weapon*>(Factory::fabricate(name)); 86 86 } 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 23 23 24 24 protected: 25 v oid hide();25 virtual void respawn(); 26 26 27 27 private: -
branches/powerups/src/world_entities/space_ships/space_ship.cc
r5988 r6107 427 427 } 428 428 } 429 else if(powerUp->isA(CL_ SHIELD_POWER_UP)) {429 else if(powerUp->isA(CL_PARAM_POWER_UP)) { 430 430 431 431 }
Note: See TracChangeset
for help on using the changeset viewer.