Changeset 8152 in orxonox.OLD for branches/network/src/world_entities
- Timestamp:
- Jun 5, 2006, 1:23:45 PM (18 years ago)
- Location:
- branches/network/src/world_entities
- Files:
-
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
branches/network/src/world_entities/spectator.cc
r8147 r8152 23 23 CREATE_FACTORY(Spectator, CL_SPECTATOR); 24 24 25 25 #if 0 26 26 /** 27 27 * constructor … … 35 35 bool bForward; 36 36 bool bBackward; 37 38 float xMouse; //!< mouse moved in x-Direction39 float yMouse; //!< mouse moved in y-Direction40 37 41 38 this->bLeft = false; … … 45 42 this->xMouse = 0.0f; 46 43 this->yMouse = 0.0f; 47 44 45 registerVar( new SynchronizeableBool( &bLeft, &bLeft, "bLeft", PERMISSION_OWNER ) ); 46 registerVar( new SynchronizeableBool( &bRight, &bRight, "bRight", PERMISSION_OWNER ) ); 47 registerVar( new SynchronizeableBool( &bForward, &bForward, "bForward", PERMISSION_OWNER ) ); 48 registerVar( new SynchronizeableBool( &bBackward, &bBackward, "bBackward", PERMISSION_OWNER ) ); 49 registerVar( new SynchronizeableQuaternion( &mouseDir, &mouseDir, "mouseDir", PERMISSION_OWNER ) ); 50 48 51 registerEvent(KeyMapper::PEV_FORWARD); 49 52 registerEvent(KeyMapper::PEV_BACKWARD); … … 52 55 registerEvent(KeyMapper::PEV_FIRE1); 53 56 registerEvent(EV_MOUSE_MOTION); 54 55 registerVar( new SynchronizeableBool( &bLeft, &bLeft, "bLeft", PERMISSION_OWNER ) );56 registerVar( new SynchronizeableBool( &bRight, &bRight, "bRight", PERMISSION_OWNER ) );57 registerVar( new SynchronizeableBool( &bForward, &bForward, "bForward", PERMISSION_OWNER ) );58 registerVar( new SynchronizeableBool( &bBackward, &bBackward, "bBackward", PERMISSION_OWNER ) );59 registerVar( new SynchronizeableQuaternion( &mouseDir, &mouseDir, "mouseDir", PERMISSION_OWNER ) );60 57 } 61 58 … … 165 162 } 166 163 } 164 #endif 165 166 167 #include "executor/executor.h" 168 169 #include "util/loading/resource_manager.h" 170 171 #include "weapons/test_gun.h" 172 #include "weapons/turret.h" 173 #include "weapons/cannon.h" 174 175 #include "dot_emitter.h" 176 #include "sprite_particles.h" 177 178 #include "util/loading/factory.h" 179 #include "key_mapper.h" 180 181 #include "network_game_manager.h" 182 183 #include "power_ups/weapon_power_up.h" 184 #include "power_ups/param_power_up.h" 185 186 #include "graphics_engine.h" 187 188 #include "plane.h" 189 190 #include "state.h" 191 #include "player.h" 192 193 #include "util/loading/load_param.h" 194 195 196 using namespace std; 197 198 199 /** 200 * destructs the spaceship, deletes alocated memory 201 */ 202 Spectator::~Spectator () 203 { 204 this->setPlayer(NULL); 205 } 206 207 /** 208 * loads a Spaceships information from a specified file. 209 * @param fileName the name of the File to load the spaceship from (absolute path) 210 */ 211 Spectator::Spectator(const std::string& fileName) 212 { 213 this->init(); 214 TiXmlDocument doc(fileName); 215 216 if(!doc.LoadFile()) 217 { 218 PRINTF(2)("Loading file %s failed for spaceship.\n", fileName.c_str()); 219 return; 220 } 221 222 this->loadParams(doc.RootElement()); 223 } 224 225 /** 226 * creates a new Spaceship from Xml Data 227 * @param root the xml element containing spaceship data 228 229 @todo add more parameters to load 230 */ 231 Spectator::Spectator(const TiXmlElement* root) 232 { 233 this->init(); 234 if (root != NULL) 235 this->loadParams(root); 236 237 } 238 239 240 /** 241 * initializes a Spaceship 242 */ 243 void Spectator::init() 244 { 245 // this->setRelDir(Quaternion(M_PI, Vector(1,0,0))); 246 this->setClassID(CL_SPECTATOR, "Spectator"); 247 248 PRINTF(4)("SPACESHIP INIT\n"); 249 250 251 this->getWeaponManager().changeWeaponConfig(1); 252 253 this->bLeft = false; 254 this->bRight = false; 255 this->bForward = false; 256 this->bBackward = false; 257 this->xMouse = 0.0f; 258 this->yMouse = 0.0f; 259 260 this->setHealthMax(100); 261 this->setHealth(80); 262 263 this->mouseDir = this->getAbsDir(); 264 265 //add events to the eventlist 266 registerEvent(KeyMapper::PEV_FORWARD); 267 registerEvent(KeyMapper::PEV_BACKWARD); 268 registerEvent(KeyMapper::PEV_LEFT); 269 registerEvent(KeyMapper::PEV_RIGHT); 270 registerEvent(KeyMapper::PEV_FIRE1); 271 registerEvent(EV_MOUSE_MOTION); 272 273 this->getWeaponManager().setSlotCount(0); 274 275 this->getWeaponManager().getFixedTarget()->setParent(this); 276 this->getWeaponManager().getFixedTarget()->setRelCoor(100000,0,0); 277 278 dynamic_cast<Element2D*>(this->getWeaponManager().getFixedTarget())->setVisibility( false); 279 280 281 registerVar( new SynchronizeableBool( &bLeft, &bLeft, "bLeft", PERMISSION_OWNER ) ); 282 registerVar( new SynchronizeableBool( &bRight, &bRight, "bRight", PERMISSION_OWNER ) ); 283 registerVar( new SynchronizeableBool( &bForward, &bForward, "bForward", PERMISSION_OWNER ) ); 284 registerVar( new SynchronizeableBool( &bBackward, &bBackward, "bBackward", PERMISSION_OWNER ) ); 285 registerVar( new SynchronizeableQuaternion( &mouseDir, &mouseDir, "mouseDir", PERMISSION_OWNER ) ); 286 } 287 288 289 /** 290 * loads the Settings of a Spectator from an XML-element. 291 * @param root the XML-element to load the Spaceship's properties from 292 */ 293 void Spectator::loadParams(const TiXmlElement* root) 294 { 295 Playable::loadParams(root); 296 } 297 298 void Spectator::setPlayDirection(const Quaternion& quat, float speed) 299 { 300 this->mouseDir = quat; 301 this->angleY = quat.getHeading(); 302 this->angleX = quat.getAttitude(); 303 } 304 305 306 void Spectator::reset() 307 { 308 this->bLeft = false; 309 this->bRight = false; 310 this->bForward = false; 311 this->bBackward = false; 312 this->xMouse = 0.0f; 313 this->yMouse = 0.0f; 314 315 this->setHealth(80); 316 } 317 318 319 void Spectator::enter() 320 { 321 dynamic_cast<Element2D*>(this->getWeaponManager().getFixedTarget())->setVisibility( true); 322 this->attachCamera(); 323 } 324 325 void Spectator::leave() 326 { 327 dynamic_cast<Element2D*>(this->getWeaponManager().getFixedTarget())->setVisibility( false); 328 this->detachCamera(); 329 } 330 331 332 /** 333 * this function is called, when two entities collide 334 * @param entity: the world entity with whom it collides 335 * 336 * Implement behaviour like damage application or other miscellaneous collision stuff in this function 337 * @todo dont let Spectator fly through walls 338 */ 339 void Spectator::collidesWith(WorldEntity* entity, const Vector& location) 340 { 341 } 342 343 344 345 /** 346 * the function called for each passing timeSnap 347 * @param time The timespan passed since last update 348 */ 349 void Spectator::tick (float time) 350 { 351 Playable::tick( time ); 352 353 if( ( xMouse != 0 || yMouse != 0 ) && this->getOwner() == this->getHostID() ) 354 { 355 xMouse *= time / 10; 356 yMouse *= time / 10; 357 358 angleX -= xMouse; 359 angleY -= yMouse; 360 361 if ( angleY > 2.05 ) 362 angleY = 2.05; 363 364 if ( angleY < -1.15 ) 365 angleY = -1.15; 366 367 this->mouseDir = Quaternion( angleX, Vector( 0, 1, 0 ) ) * Quaternion( angleY, Vector( 0, 0, 1 ) ); 368 369 xMouse = yMouse = 0; 370 } 371 372 this->setAbsDir( this->mouseDir ); 373 374 Vector velocity; 375 376 if ( this->bForward ) 377 { 378 velocity += this->getAbsDirX(); 379 } 380 381 if ( this->bBackward ) 382 { 383 velocity -= this->getAbsDirX(); 384 } 385 386 if ( this->bRight ) 387 { 388 velocity += this->getAbsDirZ(); 389 } 390 391 if ( this->bLeft ) 392 { 393 velocity -= this->getAbsDirZ(); 394 } 395 396 velocity *= 100; 397 398 this->shiftCoor( velocity*time ); 399 } 400 401 /** 402 * @todo switch statement ?? 403 */ 404 void Spectator::process(const Event &event) 405 { 406 Playable::process(event); 407 408 if( event.type == KeyMapper::PEV_LEFT) 409 this->bLeft = event.bPressed; 410 else if( event.type == KeyMapper::PEV_RIGHT) 411 this->bRight = event.bPressed; 412 else if( event.type == KeyMapper::PEV_FORWARD) 413 this->bForward = event.bPressed; //this->shiftCoor(0,.1,0); 414 else if( event.type == KeyMapper::PEV_BACKWARD) 415 this->bBackward = event.bPressed; //this->shiftCoor(0,-.1,0); 416 else if( event.type == EV_MOUSE_MOTION) 417 { 418 this->xMouse += event.xRel; 419 this->yMouse += event.yRel; 420 } 421 } 422 423 424 425 -
branches/network/src/world_entities/spectator.h
r8147 r8152 9 9 #include "playable.h" 10 10 11 #if 0 11 12 class Spectator : public Playable 12 13 { … … 40 41 float angleY; 41 42 }; 43 #endif 44 45 class Vector; 46 class Event; 47 class ParticleEmitter; 48 class ParticleSystem; 49 50 class Spectator : public Playable 51 { 52 53 public: 54 Spectator(const std::string& fileName); 55 Spectator(const TiXmlElement* root = NULL); 56 virtual ~Spectator(); 57 58 virtual void loadParams(const TiXmlElement* root); 59 60 virtual void setPlayDirection(const Quaternion& rot, float speed = 0.0f); 61 62 virtual void enter(); 63 virtual void leave(); 64 65 virtual void reset(); 66 67 virtual void collidesWith(WorldEntity* entity, const Vector& location); 68 virtual void tick(float time); 69 70 virtual void process(const Event &event); 71 72 private: 73 void init(); 74 75 bool bLeft; 76 bool bRight; 77 bool bForward; 78 bool bBackward; 79 80 float xMouse; //!< mouse moved in x-Direction 81 float yMouse; //!< mouse moved in y-Direction 82 Quaternion mouseDir; //!< the direction where the player wants to fly 83 84 //Quaternion rotY; 85 //Quaternion rotAxis; 86 float angleX; 87 float angleY; 88 89 }; 42 90 43 91 #endif
Note: See TracChangeset
for help on using the changeset viewer.