Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

Ignore:
Timestamp:
Jun 5, 2007, 2:48:15 PM (17 years ago)
Author:
nicolasc
Message:

moved "ship attributes" to world entity
electronic and shield widget not yet working

File:
1 edited

Legend:

Unmodified
Added
Removed
  • branches/vs-enhencements/src/world_entities/world_entity.cc

    r10618 r10670  
    7575  this->aabbNode = NULL;
    7676  this->healthWidget = NULL;
     77  this->electronicWidget = NULL;
     78  this->shieldWidget = NULL;
    7779  this->healthMax = 1.0f;
    7880  this->health = 1.0f;
     
    776778  this->updateHealthWidget();
    777779  return 0.0;
    778 
    779 }
     780}
     781
    780782
    781783/**
     
    792794  this->updateHealthWidget();
    793795}
     796
     797
     798
     799/**
     800 * @param shiled the Shieldstength to add.
     801 * @returns the shield left (this->shieldMax - shiled + this->shield)
     802 */
     803float WorldEntity::increaseShield(float shiled)
     804{
     805  this->shield += shield;
     806  if (this->shield > this->shieldTH * this->shieldMax) { this->bShieldActive = true; }
     807  if (this->shield > this->shieldMax)
     808  {
     809    float retShield = this->shieldMax - this->shield;
     810    this->shield = this->shieldMax;
     811    this->updateShieldWidget();
     812    return retShield;
     813  }
     814  this->updateShieldWidget();
     815  return 0.0;
     816}
     817
     818/**
     819 * @param shield the Shieldstrength to be removed
     820 * @returns 0.0 or the rest, if the shield drops belew 0.0
     821 */
     822float WorldEntity::decreaseShield(float shield)
     823{
     824  this->shield -= shield;
     825
     826  if (this->shield <= 0)
     827  {
     828    float retShield = -this->shield;
     829    this->updateShieldWidget();
     830    this->bShieldActive = false;
     831    return retShield;
     832  }
     833  this->updateShieldWidget();
     834  return 0.0;
     835}
     836
     837
    794838
    795839/**
     
    813857}
    814858
     859
     860void WorldEntity::createShieldWidget()
     861{
     862  if (this->shieldWidget == NULL)
     863  {
     864    this->shieldWidget = new OrxGui::GLGuiEnergyWidgetVertical();
     865    this->updateHealthWidget();
     866  }
     867  else
     868    PRINTF(3)("Allready created the ShieldWidget for %s::%s\n", this->getClassCName(), this->getCName());
     869}
     870
     871void WorldEntity::createElectronicWidget()
     872{
     873  if (this->electronicWidget == NULL)
     874  {
     875    this->electronicWidget = new OrxGui::GLGuiEnergyWidgetVertical();
     876    this->updateElectronicWidget();
     877  }
     878  else
     879    PRINTF(3)("Allready created the ElectronicWidget for %s::%s\n", this->getClassCName(), this->getCName());
     880}
     881
     882
    815883void WorldEntity::increaseHealthMax(float increaseHealth)
    816884{
     
    822890OrxGui::GLGuiWidget* WorldEntity::getHealthWidget()
    823891{
    824   this->createHealthWidget();
     892  if ( this->healthWidget == NULL)
     893    this->createHealthWidget();
    825894  return this->healthWidget;
    826895}
     896
     897
     898OrxGui::GLGuiWidget* WorldEntity::getShieldWidget()
     899{
     900  if ( this->shieldWidget == NULL)
     901    this->createShieldWidget();
     902  return this->shieldWidget;
     903}
     904
     905
     906OrxGui::GLGuiWidget* WorldEntity::getElectronicWidget()
     907{
     908  if ( this->electronicWidget == NULL)
     909    this->createElectronicWidget();
     910  return this->electronicWidget;
     911}
     912
     913
    827914
    828915/**
     
    830917 * (creates the widget if needed)
    831918 */
    832 void WorldEntity::setHealthWidgetVisibilit(bool visibility)
     919void WorldEntity::setHealthWidgetVisibility(bool visibility)
    833920{
    834921  if (visibility)
     
    890977  }
    891978}
     979
     980/**
     981 * @brief updates the Electronic Widget
     982 */
     983//!< xferred from spaceship
     984void WorldEntity::updateElectronicWidget(){
     985  if (this->electronicWidget != NULL)
     986  { //if it exists already: update it
     987     this->electronicWidget->setMaximum(this->electronicMax);
     988     this->electronicWidget->setValue(this->electronic);
     989  }
     990  else
     991  { //create the widget
     992    this->electronicWidget = new OrxGui::GLGuiEnergyWidgetVertical();
     993    this->electronicWidget->getBarWidget()->setChangedValueColor(Color(1,0,0,1));
     994    //this->electronicWidget->setDisplayedName("Electronics:");
     995    //this->electronicWidget->setSize2D(100,20);
     996    //this->electronicWidget->setAbsCoor2D(150,200);
     997    this->updateElectronicWidget();
     998//     if ( dynamic_cast<SpaceShip*>(this)->hasPlayer() )
     999//       State::getPlayer()->hud().setEnergyWidget(this->electronicWidget);
     1000  }
     1001}
     1002
     1003/**
     1004 * @brief updates the ShieldWidget
     1005 */
     1006//!< xferred from spaceship
     1007void WorldEntity::updateShieldWidget()
     1008{
     1009  if (this->shieldWidget != NULL)
     1010  {
     1011    this->shieldWidget->setMaximum(this->shieldMax);
     1012    this->shieldWidget->setValue(this->shield);;
     1013  }
     1014  else
     1015  {
     1016    this->shieldWidget = new OrxGui::GLGuiEnergyWidgetVertical();
     1017    this->shieldWidget->getBarWidget()->setChangedValueColor(Color(1,0,0,1));
     1018    //this->shieldWidget->setDisplayedName("Shield:");
     1019    //his->shieldWidget->setSize2D(100,20);
     1020    //this->shieldWidget->setAbsCoor2D(200,200);
     1021    this->updateShieldWidget();
     1022//     if (dynamic_cast<SpaceShip*>(this)->hasPlayer())
     1023//       State::getPlayer()->hud().setShieldWidget(this->shieldWidget);
     1024  }
     1025}
     1026
    8921027
    8931028
     
    9851120}
    9861121
     1122
     1123void WorldEntity::regen(float time){
     1124  static float tmp;
     1125  increaseHealth(time * this->healthRegen);
     1126  increaseShield(time * this->shieldRegen);
     1127//   updateHealthWidget();
     1128//   updateShieldWidget();
     1129
     1130  //this->setHealth( this->shieldCur);      // FIXME currently just to test share system
     1131
     1132  if (this->electronic != this->electronicMax || this->electronicRegen != 0){
     1133    tmp = this->electronic + this->electronicRegen * time;
     1134    if ( tmp > electronicMax)
     1135      this->electronic = this->electronicMax;
     1136    else
     1137      this->electronic = tmp;
     1138
     1139    updateElectronicWidget();
     1140  }
     1141
     1142}
Note: See TracChangeset for help on using the changeset viewer.