- Timestamp:
- Jan 8, 2006, 12:14:49 AM (19 years ago)
- Location:
- trunk/src/world_entities
- Files:
-
- 3 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/world_entities/space_ships/space_ship.cc
r6426 r6430 132 132 cycle = 0.0; 133 133 134 this->setMaxEnergy(100); 135 this->setEnergy(80); 134 136 135 137 travelSpeed = 15.0; … … 212 214 this->attachCamera(); 213 215 216 this->setEnergyWidgetVisibilit(true); 214 217 215 218 } … … 220 223 this->detachCamera(); 221 224 225 this->setEnergyWidgetVisibilit(false); 222 226 223 227 } … … 315 319 316 320 //readjust 317 321 318 322 /* 319 323 In the game "Yager" the spaceship gets readjusted when the player moves the mouse. 320 324 I (bknecht) go and check it out how they do it, we could probably use this also in Orxonox. 321 325 */ 322 //if (xMouse != 0 && yMouse != 0) 323 326 //if (xMouse != 0 && yMouse != 0) 327 324 328 //if (this->getAbsDirZ().y > 0.1) this->shiftDir(Quaternion(time*0.3, Vector(1,0,0))); 325 329 //else if (this->getAbsDirZ().y < -0.1) this->shiftDir(Quaternion(-time*0.3, Vector(1,0,0))); -
trunk/src/world_entities/world_entity.cc
r6424 r6430 27 27 #include "obb_tree.h" 28 28 29 #include "glgui_bar.h" 30 29 31 #include "state.h" 30 32 … … 32 34 33 35 SHELL_COMMAND(model, WorldEntity, loadModel) 34 35 36 ->describe("sets the Model of the WorldEntity") 37 ->defaultValues(2, "models/ships/fighter.obj", 1.0); 36 38 37 39 SHELL_COMMAND(debugEntity, WorldEntity, debugWE); … … 43 45 * that can calls WorldEntities loadParams for itself. 44 46 */ 45 WorldEntity::WorldEntity( const TiXmlElement* root)46 : Synchronizeable()47 WorldEntity::WorldEntity() 48 : Synchronizeable() 47 49 { 48 50 this->setClassID(CL_WORLD_ENTITY, "WorldEntity"); 49 51 50 52 this->obbTree = NULL; 53 this->energyWidget = NULL; 54 this->energyMax = 1.0f; 55 this->energy = 1.0f; 51 56 52 57 this->md2TextureFileName = NULL; 53 58 54 if (root != NULL)55 this->loadParams(root);56 59 57 60 this->setVisibiliy(true); … … 72 75 delete this->obbTree; 73 76 77 if (this->energyWidget != NULL) 78 delete this->energyWidget; 79 74 80 // Delete the model (unregister it with the ResourceManager) 75 81 for (unsigned int i = 0; i < this->models.size(); i++) … … 89 95 90 96 LoadParam(root, "md2texture", this, WorldEntity, loadMD2Texture) 91 92 97 .describe("the fileName of the texture, that should be loaded onto this world-entity. (must be relative to the data-dir)") 98 .defaultValues(1, NULL); 93 99 94 100 // Model Loading 95 101 LoadParam(root, "model", this, WorldEntity, loadModel) 96 .describe("the fileName of the model, that should be loaded onto this world-entity. (must be relative to the data-dir)") 97 .defaultValues(3, NULL, 1.0f, 0); 102 .describe("the fileName of the model, that should be loaded onto this world-entity. (must be relative to the data-dir)") 103 .defaultValues(3, NULL, 1.0f, 0); 104 105 LoadParam(root, "maxEnergy", this, WorldEntity, setMaxEnergy) 106 .describe("The Maximum energy that can be loaded onto this entity") 107 .defaultValues(1, 1.0f); 108 109 LoadParam(root, "energy", this, WorldEntity, setEnergy) 110 .describe("The Energy the WorldEntity has at this moment") 111 .defaultValues(1, 1.0f); 98 112 } 99 113 … … 111 125 if ( fileName != NULL && strcmp(fileName, "") ) 112 126 { 113 // search for the special character # in the LoadParam127 // search for the special character # in the LoadParam 114 128 if (strchr(fileName, '#') != NULL) 115 129 { … … 147 161 PRINTF(4)("fetching MD2 file: %s\n", fileName); 148 162 Model* m = new MD2Model(fileName, this->md2TextureFileName); 149 163 //this->setModel((Model*)ResourceManager::getInstance()->load(fileName, MD2, RP_CAMPAIGN), 0); 150 164 this->setModel(m, 0); 151 165 } … … 170 184 { 171 185 Resource* resource = ResourceManager::getInstance()->locateResourceByPointer(this->models[modelNumber]); 172 // if (resource != NULL)186 // if (resource != NULL) 173 187 ResourceManager::getInstance()->unload(resource, RP_LEVEL); 174 188 } … … 179 193 180 194 181 // if (this->model != NULL)182 // this->buildObbTree(4);195 // if (this->model != NULL) 196 // this->buildObbTree(4); 183 197 } 184 198 … … 251 265 * You can always define a default Action.... don't be affraid just test it :) 252 266 */ 253 // PRINTF(3)("collision %s vs %s @ (%f,%f,%f)\n", this->getClassName(), entity->getClassName(), location.x, location.y, location.z);267 // PRINTF(3)("collision %s vs %s @ (%f,%f,%f)\n", this->getClassName(), entity->getClassName(), location.x, location.y, location.z); 254 268 } 255 269 … … 260 274 */ 261 275 void WorldEntity::postSpawn () 262 { 263 } 276 {} 264 277 265 278 … … 273 286 */ 274 287 void WorldEntity::leftWorld () 275 { 276 } 288 {} 277 289 278 290 … … 284 296 */ 285 297 void WorldEntity::tick(float time) 286 { 287 } 298 {} 288 299 289 300 … … 296 307 void WorldEntity::draw() const 297 308 { 298 309 //PRINTF(0)("(%s::%s)\n", this->getClassName(), this->getName()); 299 310 // assert(!unlikely(this->models.empty())); 300 311 { … … 325 336 } 326 337 glPopMatrix(); 338 } 339 } 340 341 /** 342 * @param energy the Energy to add. 343 * @returns the energy left (this->energyMax - energy+this->energy) 344 */ 345 float WorldEntity::addEnergy(float energy) 346 { 347 this->energy += energy; 348 if (this->energy > this->energyMax) 349 { 350 float retEnergy = this->energyMax - this->energy; 351 this->energy = this->energyMax; 352 this->updateEnergyWidget(); 353 return retEnergy; 354 } 355 this->updateEnergyWidget(); 356 return 0.0; 357 } 358 359 /** 360 * @param energy the Energy to be removed 361 * @returns 0.0 or the rest, that was not substracted (bellow 0.0) 362 */ 363 float WorldEntity::removeEnergy(float energy) 364 { 365 this->energy -= energy; 366 367 if (this->energy < 0) 368 { 369 float retEnergy = -this->energy; 370 this->energy = 0.0f; 371 this->updateEnergyWidget(); 372 return retEnergy; 373 } 374 this->updateEnergyWidget(); 375 return 0.0; 376 377 } 378 379 /** 380 * @param maxEnergy the maximal energy that can be loaded onto the entity. 381 */ 382 void WorldEntity::setMaxEnergy(float maxEnergy) 383 { 384 this->energyMax = maxEnergy; 385 if (this->energy > this->energyMax) 386 { 387 PRINTF(3)("new maxEnergy is bigger as the old energy. Did you really intend to do this for (%s::%s)\n", this->getClassName(), this->getName()); 388 this->energy = this->energyMax; 389 } 390 this->updateEnergyWidget(); 391 } 392 393 void WorldEntity::createEnergyWidget() 394 { 395 if (this->energyWidget == NULL) 396 { 397 this->energyWidget = new GLGuiBar(); 398 this->energyWidget->setSize2D(30,400); 399 this->energyWidget->setAbsCoor2D(5,100); 400 401 this->updateEnergyWidget(); 402 } 403 else 404 PRINTF(3)("Allready created the EnergyWidget for %s::%s\n", this->getClassName(), this->getName()); 405 } 406 407 void WorldEntity::setEnergyWidgetVisibilit(bool visibility) 408 { 409 if (visibility) 410 { 411 if (this->energyWidget != NULL) 412 this->energyWidget->show(); 413 else 414 { 415 this->createEnergyWidget(); 416 this->updateEnergyWidget(); 417 this->energyWidget->show(); 418 } 419 } 420 else if (this->energyWidget != NULL) 421 this->energyWidget->hide(); 422 } 423 424 void WorldEntity::updateEnergyWidget() 425 { 426 if (this->energyWidget != NULL) 427 { 428 this->energyWidget->setMaximum(this->energyMax); 429 this->energyWidget->setValue(this->energy); 327 430 } 328 431 } -
trunk/src/world_entities/world_entity.h
r6424 r6430 20 20 class BVTree; 21 21 class Model; 22 class GLGuiBar; 22 23 23 24 //class CharacterAttributes; … … 27 28 class WorldEntity : public PNode, public Synchronizeable 28 29 { 29 30 WorldEntity( const TiXmlElement* root = NULL);30 public: 31 WorldEntity(); 31 32 virtual ~WorldEntity (); 32 33 … … 35 36 void loadModel(const char* fileName, float scaling = 1.0f, unsigned int modelNumber = 0); 36 37 void setModel(Model* model, unsigned int modelNumber = 0); 37 38 Model* getModel(unsigned int modelNumber = 0) const { return (this->models.size() > modelNumber)? this->models[modelNumber] : NULL; }; 38 39 39 40 inline void loadMD2Texture(const char* fileName) { this->md2TextureFileName = fileName; } … … 61 62 62 63 63 void debugWE() { this->debugEntity(); }; ///FIXME 64 void debugWE() { this->debugEntity(); } 65 ; ///FIXME 64 66 void debugEntity() const; 65 67 … … 82 84 int readState(byte* data, int maxLength ); 83 85 84 protected: 85 // CharacterAttributes* charAttr; //!< the character attributes of a world_entity 86 /** @returns the Energy of the entity */ 87 float getEnergy() const { return this->energy; }; 88 /** @returns the Maximum energy this entity can be charged with */ 89 float getMaxEnergy() const { return this->energyMax; } 90 float addEnergy(float energy); 91 float removeEnergy(float energy); 92 void setMaxEnergy(float maxEnergy); 86 93 87 94 88 private: 95 protected: 96 void setEnergy(float energy) { this->energy = energy; }; 97 void setEnergyWidgetVisibilit(bool visibility); 98 void createEnergyWidget(); 99 // CharacterAttributes* charAttr; //!< the character attributes of a world_entity 100 private: 101 void updateEnergyWidget(); 102 103 private: 104 /// TODO maybe we will move the following three entries and the corresponding functions to Playable AND NPC 105 float energy; //!< The Energy of this Entity, if the Entity has any energy at all. 106 float energyMax; //!< The Maximal energy this entity can take. 107 GLGuiBar* energyWidget; //!< The Slider (if wanted). 108 89 109 std::vector<Model*> models; //!< The model that should be loaded for this entity. 90 110 const char* md2TextureFileName; //!< the file name of the md2 model texture, only if this
Note: See TracChangeset
for help on using the changeset viewer.