Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

Changeset 10602 in orxonox.OLD


Ignore:
Timestamp:
Mar 26, 2007, 12:31:58 AM (17 years ago)
Author:
rennerc
Message:

added ghost feature, which lets player fly around and print coords
add this to level file to enable ghost
<Spectator>

<name>Ghost</name>
<allowGhost>1</allowGhost>

</Spectator>

Location:
branches/cleanup/src/world_entities
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • branches/cleanup/src/world_entities/spectator.cc

    r10601 r10602  
    2525#include "src/world_entities/npcs/generic_npc.h"
    2626
     27#include "src/lib/util/loading/load_param.h"
     28
     29#include "player.h"
     30
    2731
    2832ObjectListDefinition(Spectator);
    2933CREATE_FACTORY(Spectator);
    3034
    31 
     35Spectator* Spectator::ghost = NULL;
     36Playable* Spectator::regularPlayable = NULL;
    3237
    3338#include "state.h"
     39#include "shell_command.h"
     40             
     41SHELL_COMMAND( enableGhost, Spectator, enableGhost )
     42             ->describe("fly around")
     43             ->setAlias("ghost");
    3444
    3545
     
    109119/**
    110120 * loads the Settings of a Spectator from an XML-element.
    111  * @param root the XML-element to load the Spaceship's properties from
     121 * @param root the XML-element to load the Spectator's properties from
    112122 */
    113123void Spectator::loadParams(const TiXmlElement* root)
    114124{
    115125  Playable::loadParams(root);
     126 
     127  LoadParam(root, "allowGhost", this, Spectator, allowGhost)
     128    .describe("Allows the Player to fly around");
     129}
     130
     131
     132
     133void Spectator::allowGhost( bool flag )
     134{
     135  PRINTF(0)( "SPECTATOR ALLOWGHOST: %d\n", flag );
     136  if ( flag )
     137  {
     138    assert( ghost == NULL && "only one flySpectator allowed" );
     139   
     140    ghost = this;
     141  }
     142  else
     143  {
     144    ghost = NULL;
     145  }
     146}
     147
     148
     149void Spectator::enableGhost( )
     150{
     151  if ( !regularPlayable )
     152  {
     153    if ( !State::getPlayer() || !State::getPlayer()->getPlayable() )
     154      return;
     155   
     156    regularPlayable = State::getPlayer()->getPlayable();
     157   
     158    ghost->setAbsCoor( regularPlayable->getAbsCoor() );
     159    ghost->setAbsDir( regularPlayable->getAbsDir() );
     160   
     161    State::getPlayer()->setPlayable( ghost );
     162  }
     163  else
     164  {
     165    if ( !State::getPlayer() || !State::getPlayer()->getPlayable() )
     166      return;
     167   
     168    State::getPlayer()->setPlayable( regularPlayable );
     169    regularPlayable = NULL;
     170  }
    116171}
    117172
     
    264319
    265320
     321
  • branches/cleanup/src/world_entities/spectator.h

    r9869 r10602  
    3030
    3131    virtual void process(const Event &event);
     32   
     33    void allowGhost( bool flag );
     34   
     35    static void enableGhost();
    3236
    3337  private:
     
    4549    float                 angleX;
    4650    float                 angleY;
     51   
     52    static Spectator*     ghost;
     53    static Playable*      regularPlayable;
    4754
    4855};
Note: See TracChangeset for help on using the changeset viewer.