home *** CD-ROM | disk | FTP | other *** search
/ 3D Game Programming All in One / 3D Game Programming All in One Disc.iso / 3D2E / demo / server / scripts / fps.cs < prev    next >
Encoding:
Text File  |  2006-09-23  |  2.3 KB  |  81 lines

  1. //-----------------------------------------------------------------------------
  2. // Torque Game Engine 
  3. // Copyright (C) GarageGames.com, Inc.
  4. //-----------------------------------------------------------------------------
  5.  
  6. //-----------------------------------------------------------------------------
  7. //  Functions that implement game-play
  8. //-----------------------------------------------------------------------------
  9.  
  10. //-----------------------------------------------------------------------------
  11.  
  12. package FpsGame {
  13.  
  14.  
  15. //-----------------------------------------------------------------------------
  16.  
  17. function GameConnection::onClientEnterGame(%this)
  18. {
  19.    commandToClient(%this, 'SyncClock', $Sim::Time - $Game::StartTime);
  20.    commandToClient(%this, 'SetGameGUI',"FpsGUI");
  21.  
  22.    // Create a new camera object.
  23.    %this.camera = new Camera() {
  24.       dataBlock = Observer;
  25.    };
  26.    MissionCleanup.add( %this.camera );
  27.    %this.camera.scopeToClient(%this);
  28.  
  29.    // Spawn the player
  30.    %this.score = 0;
  31.    %this.spawnPlayer();
  32. }
  33.  
  34. //-----------------------------------------------------------------------------
  35.  
  36. function GameConnection::createPlayer(%this, %spawnPoint)
  37. {
  38.    if (%this.player > 0)  {
  39.       // The client should not have a player currently
  40.       // assigned.  Assigning a new one could result in 
  41.       // a player ghost.
  42.       error( "Attempting to create an angus ghost!" );
  43.    }
  44.  
  45.    // Create the player object
  46.    %player = new Player() {
  47.       dataBlock = PlayerBody;
  48.       client = %this;
  49.    };
  50.    MissionCleanup.add(%player);
  51.  
  52.    // Player setup...
  53.    %player.setTransform(%spawnPoint);
  54.    %player.setEnergyLevel(60);
  55.    %player.setShapeName(%this.name);
  56.    
  57.    // Starting equipment
  58.    %player.mountImage(CrossbowImage,0);
  59.    %player.setInventory(CrossbowAmmo,10);
  60.  
  61.    // Update the camera to start with the player
  62.    %this.camera.setTransform(%player.getEyeTransform());
  63.  
  64.    // Give the client control of the player
  65.    %this.player = %player;
  66.    %this.setControlObject(%player);
  67. }
  68.  
  69.  
  70. //-----------------------------------------------------------------------------
  71.  
  72. function serverCmdSuicide(%client)
  73. {
  74.    if (isObject(%client.player)) {
  75.       %client.player.delete();
  76.       %client.player = 0;
  77.    }
  78.    %client.spawnPlayer();
  79. }
  80.  
  81. };