Changeset 6700 in orxonox.OLD
- Timestamp:
- Jan 25, 2006, 3:10:17 PM (19 years ago)
- Location:
- trunk/src/world_entities
- Files:
-
- 11 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/world_entities/playable.cc
r6695 r6700 22 22 #include "state.h" 23 23 24 #include "world_entities/projectiles/projectile.h" 25 24 26 #include "power_ups/weapon_power_up.h" 25 27 #include "power_ups/param_power_up.h" … … 97 99 { 98 100 if (entity->isA(CL_PROJECTILE)) 99 this-> removeEnergy(entity->getEnergy());101 this->decreaseHealth(entity->getHealth()); 100 102 101 103 // EXTREME HACK 102 if (this->get Energy() == 0.0f)104 if (this->getHealth() == 0.0f) 103 105 this->deactivateNode(); 104 106 } … … 166 168 switch(ppu->getType()) { 167 169 case POWERUP_PARAM_HEALTH: 168 this-> addEnergy(ppu->getValue());170 this->increaseHealth(ppu->getValue()); 169 171 return true; 170 172 case POWERUP_PARAM_MAX_HEALTH: 171 this-> setMaxEnergy(this->getMaxEnergy() +ppu->getValue());173 this->increaseHealthMax(ppu->getValue()); 172 174 return true; 173 175 } -
trunk/src/world_entities/player.cc
r6443 r6700 58 58 { 59 59 this->controllable = controllable; 60 this->hud.setEnergyWidget(this->controllable->get EnergyWidget());60 this->hud.setEnergyWidget(this->controllable->getHealthWidget()); 61 61 this->hud.setWeaponManager(this->controllable->getWeaponManager()); 62 62 return true; -
trunk/src/world_entities/projectiles/bomb.cc
r6619 r6700 46 46 47 47 this->setMinEnergy(1); 48 this->set MaxEnergy(10);48 this->setHealthMax(10); 49 49 50 50 this->lifeSpan = 15; -
trunk/src/world_entities/projectiles/guided_missile.cc
r6637 r6700 41 41 42 42 this->setMinEnergy(1); 43 this->set MaxEnergy(10);43 this->setHealthMax(10); 44 44 this->lifeSpan = 10.0; 45 45 this->agility = 5; -
trunk/src/world_entities/projectiles/laser.cc
r6695 r6700 47 47 48 48 this->setMinEnergy(1); 49 this->set MaxEnergy(10);49 this->setHealthMax(10); 50 50 this->lifeSpan = 5.0; 51 51 -
trunk/src/world_entities/projectiles/rocket.cc
r6628 r6700 42 42 43 43 this->setMinEnergy(1); 44 this->set MaxEnergy(10);44 this->setHealthMax(10); 45 45 this->lifeSpan = 5; 46 46 -
trunk/src/world_entities/projectiles/test_bullet.cc
r6622 r6700 42 42 43 43 this->setMinEnergy(1); 44 this->set MaxEnergy(10);44 this->setHealthMax(10); 45 45 this->lifeSpan = 2; 46 46 -
trunk/src/world_entities/space_ships/space_ship.cc
r6696 r6700 143 143 // cycle = 0.0; 144 144 145 this->set MaxEnergy(100);146 this->set Energy(80);145 this->setHealthMax(100); 146 this->setHealth(80); 147 147 148 148 travelSpeed = 40.0; -
trunk/src/world_entities/weapons/weapon.cc
r6695 r6700 150 150 Projectile* pj = dynamic_cast<Projectile*>(this->projectileFactory->resurrect()); 151 151 this->minCharge = pj->getMinEnergy(); 152 this->maxCharge = pj->get MaxEnergy();152 this->maxCharge = pj->getHealthMax(); 153 153 this->chargeable = pj->isChageable(); 154 154 this->projectileFactory->kill(pj); -
trunk/src/world_entities/world_entity.cc
r6695 r6700 51 51 52 52 this->obbTree = NULL; 53 this-> energyWidget = NULL;54 this-> energyMax = 1.0f;55 this-> energy= 1.0f;53 this->healthWidget = NULL; 54 this->healthMax = 1.0f; 55 this->health = 1.0f; 56 56 this->scaling = 1.0f; 57 57 … … 77 77 delete this->obbTree; 78 78 79 if (this-> energyWidget != NULL)80 delete this-> energyWidget;79 if (this->healthWidget != NULL) 80 delete this->healthWidget; 81 81 82 82 // Delete the model (unregister it with the ResourceManager) … … 105 105 .defaultValues(3, NULL, 1.0f, 0); 106 106 107 LoadParam(root, "max Energy", this, WorldEntity, setMaxEnergy)108 .describe("The Maximum energythat can be loaded onto this entity")107 LoadParam(root, "maxHealth", this, WorldEntity, setHealthMax) 108 .describe("The Maximum health that can be loaded onto this entity") 109 109 .defaultValues(1, 1.0f); 110 110 111 LoadParam(root, " energy", this, WorldEntity, setEnergy)112 .describe("The Energythe WorldEntity has at this moment")111 LoadParam(root, "health", this, WorldEntity, setHealth) 112 .describe("The Health the WorldEntity has at this moment") 113 113 .defaultValues(1, 1.0f); 114 114 } … … 343 343 344 344 /** 345 * @param energy the Energyto add.346 * @returns the energy left (this->energyMax - energy+this->energy)347 */ 348 float WorldEntity:: addEnergy(float energy)349 { 350 this-> energy += energy;351 if (this-> energy > this->energyMax)352 { 353 float ret Energy = this->energyMax - this->energy;354 this-> energy = this->energyMax;355 this->update EnergyWidget();356 return ret Energy;357 } 358 this->update EnergyWidget();345 * @param health the Health to add. 346 * @returns the health left (this->healthMax - health+this->health) 347 */ 348 float WorldEntity::increaseHealth(float health) 349 { 350 this->health += health; 351 if (this->health > this->healthMax) 352 { 353 float retHealth = this->healthMax - this->health; 354 this->health = this->healthMax; 355 this->updateHealthWidget(); 356 return retHealth; 357 } 358 this->updateHealthWidget(); 359 359 return 0.0; 360 360 } 361 361 362 362 /** 363 * @param energy the Energyto be removed363 * @param health the Health to be removed 364 364 * @returns 0.0 or the rest, that was not substracted (bellow 0.0) 365 365 */ 366 float WorldEntity:: removeEnergy(float energy)367 { 368 this-> energy -= energy;369 370 if (this-> energy< 0)371 { 372 float ret Energy = -this->energy;373 this-> energy= 0.0f;374 this->update EnergyWidget();375 return ret Energy;376 } 377 this->update EnergyWidget();366 float WorldEntity::decreaseHealth(float health) 367 { 368 this->health -= health; 369 370 if (this->health < 0) 371 { 372 float retHealth = -this->health; 373 this->health = 0.0f; 374 this->updateHealthWidget(); 375 return retHealth; 376 } 377 this->updateHealthWidget(); 378 378 return 0.0; 379 379 … … 381 381 382 382 /** 383 * @param max Energy the maximal energythat can be loaded onto the entity.384 */ 385 void WorldEntity::set MaxEnergy(float maxEnergy)386 { 387 this-> energyMax = maxEnergy;388 if (this-> energy > this->energyMax)389 { 390 PRINTF(3)("new max Energy is bigger as the old energy. Did you really intend to do this for (%s::%s)\n", this->getClassName(), this->getName());391 this-> energy = this->energyMax;392 } 393 this->update EnergyWidget();394 } 395 396 /** 397 * @brief creates the EnergyWidget398 * 399 * since not all entities need an EnergyWidget, it is only created on request.400 */ 401 void WorldEntity::create EnergyWidget()402 { 403 if (this-> energyWidget == NULL)404 { 405 this-> energyWidget = new GLGuiBar();406 this-> energyWidget->setSize2D(30,400);407 this-> energyWidget->setAbsCoor2D(10,100);408 409 this->update EnergyWidget();383 * @param maxHealth the maximal health that can be loaded onto the entity. 384 */ 385 void WorldEntity::setHealthMax(float healthMax) 386 { 387 this->healthMax = healthMax; 388 if (this->health > this->healthMax) 389 { 390 PRINTF(3)("new maxHealth is bigger as the old health. Did you really intend to do this for (%s::%s)\n", this->getClassName(), this->getName()); 391 this->health = this->healthMax; 392 } 393 this->updateHealthWidget(); 394 } 395 396 /** 397 * @brief creates the HealthWidget 398 * 399 * since not all entities need an HealthWidget, it is only created on request. 400 */ 401 void WorldEntity::createHealthWidget() 402 { 403 if (this->healthWidget == NULL) 404 { 405 this->healthWidget = new GLGuiBar(); 406 this->healthWidget->setSize2D(30,400); 407 this->healthWidget->setAbsCoor2D(10,100); 408 409 this->updateHealthWidget(); 410 410 } 411 411 else 412 PRINTF(3)("Allready created the EnergyWidget for %s::%s\n", this->getClassName(), this->getName()); 413 } 414 415 GLGuiWidget* WorldEntity::getEnergyWidget() 416 { 417 this->createEnergyWidget(); 418 return this->energyWidget; 419 } 420 421 /** 422 * @param visibility shows or hides the energy-bar 412 PRINTF(3)("Allready created the HealthWidget for %s::%s\n", this->getClassName(), this->getName()); 413 } 414 415 void WorldEntity::increaseHealthMax(float increaseHealth) 416 { 417 this->healthMax += increaseHealth; 418 this->updateHealthWidget(); 419 } 420 421 422 GLGuiWidget* WorldEntity::getHealthWidget() 423 { 424 this->createHealthWidget(); 425 return this->healthWidget; 426 } 427 428 /** 429 * @param visibility shows or hides the health-bar 423 430 * (creates the widget if needed) 424 431 */ 425 void WorldEntity::set EnergyWidgetVisibilit(bool visibility)432 void WorldEntity::setHealthWidgetVisibilit(bool visibility) 426 433 { 427 434 if (visibility) 428 435 { 429 if (this-> energyWidget != NULL)430 this-> energyWidget->show();436 if (this->healthWidget != NULL) 437 this->healthWidget->show(); 431 438 else 432 439 { 433 this->create EnergyWidget();434 this->update EnergyWidget();435 this-> energyWidget->show();440 this->createHealthWidget(); 441 this->updateHealthWidget(); 442 this->healthWidget->show(); 436 443 } 437 444 } 438 else if (this-> energyWidget != NULL)439 this-> energyWidget->hide();440 } 441 442 /** 443 * @brief updates the EnergyWidget444 */ 445 void WorldEntity::update EnergyWidget()446 { 447 if (this-> energyWidget != NULL)448 { 449 this-> energyWidget->setMaximum(this->energyMax);450 this-> energyWidget->setValue(this->energy);445 else if (this->healthWidget != NULL) 446 this->healthWidget->hide(); 447 } 448 449 /** 450 * @brief updates the HealthWidget 451 */ 452 void WorldEntity::updateHealthWidget() 453 { 454 if (this->healthWidget != NULL) 455 { 456 this->healthWidget->setMaximum(this->healthMax); 457 this->healthWidget->setValue(this->health); 451 458 } 452 459 } -
trunk/src/world_entities/world_entity.h
r6695 r6700 87 87 88 88 /** @returns the Energy of the entity */ 89 float get Energy() const { return this->energy; };89 float getHealth() const { return this->health; }; 90 90 /** @returns the Maximum energy this entity can be charged with */ 91 float get MaxEnergy() const { return this->energyMax; }92 float addEnergy(float energy);93 float removeEnergy(float energy);94 void setMaxEnergy(float maxEnergy);95 GLGuiWidget* get EnergyWidget();91 float getHealthMax() const { return this->healthMax; } 92 float increaseHealth(float health); 93 float decreaseHealth(float health); 94 void increaseHealthMax(float increaseHealth); 95 GLGuiWidget* getHealthWidget(); 96 96 97 97 protected: 98 void setEnergy(float energy) { this->energy = energy; }; 99 void setEnergyWidgetVisibilit(bool visibility); 100 void createEnergyWidget(); 98 void setHealth(float health) { this->health = health; }; 99 void setHealthWidgetVisibilit(bool visibility); 100 void setHealthMax(float healthMax); 101 void createHealthWidget(); 101 102 // CharacterAttributes* charAttr; //!< the character attributes of a world_entity 102 103 private: 103 void update EnergyWidget();104 void updateHealthWidget(); 104 105 105 106 private: 106 107 /// TODO maybe we will move the following three entries and the corresponding functions to Playable AND NPC 107 float energy; //!< The Energy of this Entity, if the Entity has any energy at all.108 float energyMax; //!< The Maximal energy this entity can take.109 GLGuiBar* energyWidget; //!< The Slider (if wanted).108 float health; //!< The Energy of this Entity, if the Entity has any energy at all. 109 float healthMax; //!< The Maximal energy this entity can take. 110 GLGuiBar* healthWidget; //!< The Slider (if wanted). 110 111 111 112 std::vector<Model*> models; //!< The model that should be loaded for this entity.
Note: See TracChangeset
for help on using the changeset viewer.