Changeset 6700 in orxonox.OLD for trunk/src/world_entities/world_entity.cc
- Timestamp:
- Jan 25, 2006, 3:10:17 PM (18 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
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 }
Note: See TracChangeset
for help on using the changeset viewer.