- Timestamp:
- Jan 18, 2006, 2:12:53 PM (19 years ago)
- Location:
- trunk/src/world_entities
- Files:
-
- 9 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/world_entities/playable.cc
r6444 r6547 21 21 #include "player.h" 22 22 #include "state.h" 23 24 #include "power_ups/weapon_power_up.h" 25 #include "power_ups/param_power_up.h" 23 26 24 27 … … 141 144 } 142 145 146 bool Playable::pickup(PowerUp* powerUp) 147 { 148 if(powerUp->isA(CL_WEAPON_POWER_UP)) { 149 Weapon* weapon = dynamic_cast<WeaponPowerUp*>(powerUp)->getWeapon(); 150 WeaponManager* manager = this->getWeaponManager(); 151 int slot = manager->getNextFreeSlot(2, weapon->getCapability()); 152 if(slot >= 0) { 153 manager->addWeapon(weapon, 2, slot); 154 return true; 155 } 156 } 157 else if(powerUp->isA(CL_PARAM_POWER_UP)) { 158 ParamPowerUp* ppu = dynamic_cast<ParamPowerUp*>(powerUp); 159 switch(ppu->getType()) { 160 case POWERUP_PARAM_HEALTH: 161 this->addEnergy(ppu->getValue()); 162 return true; 163 case POWERUP_PARAM_MAX_HEALTH: 164 this->setMaxEnergy(this->getMaxEnergy() + ppu->getValue()); 165 return true; 166 } 167 } 168 return false; 169 } 170 143 171 /** 144 172 * add an event to the event list of events this Playable can capture -
trunk/src/world_entities/playable.h
r6444 r6547 8 8 9 9 #include "world_entity.h" 10 #include "extendable.h" 10 11 #include "event.h" 11 12 #include <list> … … 21 22 * 22 23 */ 23 class Playable : public WorldEntity 24 class Playable : public WorldEntity, public Extendable 24 25 { 25 26 public: … … 29 30 virtual void enter()=0; 30 31 virtual void leave()=0; 32 33 virtual bool pickup(PowerUp* powerUp); 31 34 32 35 void addWeapon(Weapon* weapon, int configID = -1, int slotID = -1); -
trunk/src/world_entities/power_ups/param_power_up.cc
r6512 r6547 32 32 33 33 const char* ParamPowerUp::paramTypes[] = { 34 "shield" 34 "shield", 35 "max-shield", 36 "health", 37 "max-health", 35 38 }; 36 39 … … 77 80 } 78 81 79 void ParamPowerUp::setValue( int value)82 void ParamPowerUp::setValue(float value) 80 83 { 81 84 this->value = value; … … 84 87 void ParamPowerUp::setType(const char* type) 85 88 { 86 for(int i = 0; i < P ARAM_size; ++i) {89 for(int i = 0; i < POWERUP_PARAM_size; ++i) { 87 90 if(strcmp(type, paramTypes[i]) == 0) { 88 91 this->type = (EnumParamPowerUpType)i; … … 92 95 } 93 96 94 void ParamPowerUp::setMaxValue( int value)97 void ParamPowerUp::setMaxValue(float value) 95 98 { 96 99 this->max_value = value; 97 100 } 98 101 99 void ParamPowerUp::setMinValue( int value)102 void ParamPowerUp::setMinValue(float value) 100 103 { 101 104 this->min_value = value; 102 105 } 103 106 104 int ParamPowerUp::getValue()107 float ParamPowerUp::getValue() 105 108 { 106 109 return this->value; … … 116 119 if(this->min_value != this->max_value) 117 120 { 118 value = this->min_value + (int)(rand() * (this->max_value - this->min_value));121 this->value = this->min_value + rand() * (this->max_value - this->min_value); 119 122 } 120 123 } … … 132 135 SYNCHELP_READ_INT( i ); 133 136 this->type = (EnumParamPowerUpType)i; 134 SYNCHELP_READ_ INT( this->value );137 SYNCHELP_READ_FLOAT( this->value ); 135 138 136 139 if ( this->value != 0 ) 137 140 { 138 SYNCHELP_READ_ INT( this->min_value );139 SYNCHELP_READ_ INT( this->max_value );141 SYNCHELP_READ_FLOAT( this->min_value ); 142 SYNCHELP_READ_FLOAT( this->max_value ); 140 143 respawn(); 141 144 } … … 165 168 int i = (int)this->type; 166 169 SYNCHELP_WRITE_INT( i ); 167 SYNCHELP_WRITE_ INT( this->value );170 SYNCHELP_WRITE_FLOAT( this->value ); 168 171 169 172 if ( this->value != 0 ) 170 173 { 171 SYNCHELP_WRITE_ INT( this->min_value );172 SYNCHELP_WRITE_ INT( this->max_value );174 SYNCHELP_WRITE_FLOAT( this->min_value ); 175 SYNCHELP_WRITE_FLOAT( this->max_value ); 173 176 } 174 177 -
trunk/src/world_entities/power_ups/param_power_up.h
r6512 r6547 12 12 13 13 typedef enum EnumParamPowerUpType { 14 PARAM_SHIELD, 15 PARAM_size 14 POWERUP_PARAM_SHIELD, 15 POWERUP_PARAM_MAX_SHIELD, 16 POWERUP_PARAM_HEALTH, 17 POWERUP_PARAM_MAX_HEALTH, 18 POWERUP_PARAM_size 16 19 } EnumParamPowerUpType; 17 20 … … 23 26 virtual ~ParamPowerUp (); 24 27 25 void setValue( int value);26 void setMaxValue( int value);27 void setMinValue( int value);28 void setValue(float value); 29 void setMaxValue(float value); 30 void setMinValue(float value); 28 31 void setType(const char* type); 29 32 EnumParamPowerUpType getType(); 30 int getValue();33 float getValue(); 31 34 32 35 virtual int writeBytes(const byte* data, int length, int sender); … … 43 46 static const char* paramTypes[]; 44 47 EnumParamPowerUpType type; 45 int value;46 int max_value;47 int min_value;48 float value; 49 float max_value; 50 float min_value; 48 51 }; 49 52 -
trunk/src/world_entities/power_ups/power_up.cc
r6512 r6547 65 65 void PowerUp::draw() const 66 66 { 67 glMatrixMode(GL_MODELVIEW); 67 this->sphereMaterial->select(); 68 WorldEntity::draw(); 69 /*glMatrixMode(GL_MODELVIEW); 68 70 glPushMatrix(); 69 71 70 /* translate */71 72 glTranslatef (this->getAbsCoor ().x, 72 73 this->getAbsCoor ().y, … … 78 79 this->getModel(0)->draw(); 79 80 80 glPopMatrix();81 glPopMatrix();*/ 81 82 } 82 83 -
trunk/src/world_entities/power_ups/weapon_power_up.cc
r6512 r6547 50 50 void WeaponPowerUp::init() 51 51 { 52 weaponXML = NULL; 53 weapon = NULL; 52 this->setClassID(CL_WEAPON_POWER_UP, "WeaponPowerUp"); 53 this->weaponXML = NULL; 54 this->weapon = NULL; 54 55 } 55 56 -
trunk/src/world_entities/space_ships/space_ship.cc
r6532 r6547 123 123 PRINTF(4)("SPACESHIP INIT\n"); 124 124 125 //EventHandler::getInstance()->grabEvents(true);125 EventHandler::getInstance()->grabEvents(true); 126 126 127 127 bUp = bDown = bLeft = bRight = bAscend = bDescend = bRollL = bRollR = false; … … 450 450 //this->setAbsDir(mouseDir); 451 451 } 452 }453 454 /**455 *456 */457 bool SpaceShip::pickup(PowerUp* powerUp)458 {459 if(powerUp->isA(CL_WEAPON_POWER_UP)) {460 Weapon* weapon = dynamic_cast<WeaponPowerUp*>(powerUp)->getWeapon();461 WeaponManager* manager = this->getWeaponManager();462 int slot = manager->getNextFreeSlot(0, weapon->getCapability());463 if(slot >= 0) {464 manager->addWeapon(weapon, 0, slot);465 return true;466 }467 }468 else if(powerUp->isA(CL_PARAM_POWER_UP)) {469 ParamPowerUp* ppu = dynamic_cast<ParamPowerUp*>(powerUp);470 switch(ppu->getType()) {471 case PARAM_SHIELD:472 break;473 }474 }475 return false;476 452 } 477 453 -
trunk/src/world_entities/space_ships/space_ship.h
r6512 r6547 15 15 class Event; 16 16 17 class SpaceShip : public Playable , public Extendable17 class SpaceShip : public Playable 18 18 { 19 19 … … 39 39 40 40 virtual void process(const Event &event); 41 bool pickup(PowerUp* powerUp);42 41 43 42 virtual int writeBytes(const byte* data, int length, int sender); -
trunk/src/world_entities/weapons/turret.cc
r6512 r6547 54 54 { 55 55 this->init(); 56 this->loadParams(root); 56 if (root != NULL) 57 this->loadParams(root); 57 58 } 58 59
Note: See TracChangeset
for help on using the changeset viewer.