Game Development Community

TGEA Starter.Racing for 1.7 - 1.8

by Mike Rowley · 01/16/2009 (3:17 pm) · 2 comments

This is a bug fix version fixing the options crash issue.

This is a port of the starter.racing kit from tge to tgea. The zip includes a fully functional game with script source and 1 Cpp file.
The speedometer included in tgea doesn't render a needle, so I ported the guiDigiSpeedometer to work in tgea and added it to the starter kit.
This kit is a complete multiplayer racing game where you will race around a dirt track, navagate 2 bridges. There are also examples of in Game advertising. The source files, (script and .map) change log to show what changes are needed to make this game work in your source. For this example, I ported the stronghold example.
Here is the change log:

These are the files changed in the stronghold example,  to make this racing starter kit.
**************************************************************************************************
Copy:

Engine/source/T3D/vehicles/guiDigiSpeedometer.cc
-------------------------------------------------------------------------
Add to your project and compile.

****************************************************************************************************
Changes to script files:
***************************
Racing/game/ScriptsAndAssets/client/scripts/playGui.cs
--------------------------------------------------------------------------------
After:
-------
function PlayGui::onSleep(%this)
{
   Canvas.popDialog( MainChatHud  );
   
   // pop the keymaps
   moveMap.pop();
}

Add:
------
//Added functions for our lap counter

function PlayGui::updateLapCounter(%this)
{
	LapCounter.setText("Lap" SPC %this.lap SPC "/" SPC %this.maxLaps);
}

function clientCmdSetMaxLaps(%laps)
{
	// Reset the current lap to 1 and set the max laps.
	PlayGui.lap = 1;
	PlayGui.maxLaps = %laps;
	PlayGui.updateLapCounter();
}

function clientCmdIncreaseLapCounter()
{
	// Increase the lap.
	PlayGui.lap++;
	PlayGui.updateLapCounter();
}
************************************************************************************************
In ScriptsAndAssets/client/ui/playGui.gui
-----------------------------------------------------------
Before the closing brace add:
------------------------------------------

  // speedometer and lap counters
   new GuiTextCtrl(LapCounter) {
      canSaveDynamicFields = "0";
      Enabled = "1";
      isContainer = "0";
      Profile = "GuiBigTextProfile";
      HorizSizing = "left";
      VertSizing = "bottom";
      position = "450 5";
      Extent = "170 39";
      MinExtent = "8 2";
      canSave = "1";
      Visible = "1";
      hovertime = "1000";
      Margin = "0 0 0 0";
      Padding = "0 0 0 0";
      AnchorTop = "1";
      AnchorBottom = "0";
      AnchorLeft = "1";
      AnchorRight = "0";
      text = "Lap 1 / 5";
      maxLength = "255";
   };
   new GuiDigiSpeedometerHud() {
      canSaveDynamicFields = "0";
      Enabled = "1";
      isContainer = "0";
      Profile = "GuiDigiSpeedometerProfile";
      HorizSizing = "left";
      VertSizing = "top";
      position = "293 452";
      canSave = "1";
      Visible = "1";
      hovertime = "1000";
//      bitmap = "";
      wrap = "0";
      maxSpeed = "100";
      digitSize = "13 13";
   };
******************************************************************************************
Copy digitalReadout1.png to scriptsAndAssets/client/ui/
******************************************************************************************
In client/scripts/ui/customProfiles.cs 
Add at the end of the file:
---------------------------------------------------
//--------------------------------------
// Digital Speedometer GUI (Client)
//--------------------------------------
if (isObject(GuiDigiSpeedometerProfile)) GuiDigiSpeedometerProfile.delete(); 
 new GuiControlProfile(GuiDigiSpeedometerProfile)
 {
       bitmap = "./digitalReadout1";
       hasBitmapArray = true;
       justify = "0 0";
};
//
-----------------------------------------------------------------------------------------------------------------------

Copy:
car.cs and checkpoint.cs to scriptsAndAssets/server/scripts/
******************************************************************************************
Copy:
Data/shapes/buggy/ folder to scriptsAndAssets/data/shapes/
******************************************************************************************

In scriptsAndAssets/server/scripts/game.cs:
-------------------------------------------------------------
Add:
--------
// The amount of laps to race through.
// Change this number for how many laps you want your race to hold.

$Game::Laps = 5;

After:
----------

$Game::EndGamePause = 10;
------------------------------------------------------------------------------
Add before    exec("./sgExamples.cs");
------------------------------------------------------
   exec("./car.cs");
   exec("./checkpoint.cs");

Replace:
------------
function startGame()
{
   if ($Game::Running) {
      error("startGame: End the game first!");
      return;
   }

   // Inform the client we're starting up
   for( %clientIndex = 0; %clientIndex < ClientGroup.getCount(); %clientIndex++ ) {
      %cl = ClientGroup.getObject( %clientIndex );
      commandToClient(%cl, 'GameStart');
}

With this:
------------
function startGame()
{
   if ($Game::Running) {
      error("startGame: End the game first!");
      return;
   }

   // Inform the client we're starting up
   for( %clientIndex = 0; %clientIndex < ClientGroup.getCount(); %clientIndex++ ) {
      %cl = ClientGroup.getObject( %clientIndex );
      commandToClient(%cl, 'GameStart');
     // Other client specific setup..
      %cl.score = 0;
      %cl.lap = 0;
      %cl.nextCheck = 1;
}

In function startGame(), after       %cl.score = 0; Add:
------------------------------------------------------------------------

      %cl.lap = 0;
      %cl.nextCheck = 1;
 
Before the closing brace.
===================

In function GameConnection::onClientEnterGame,
After commandToClient(%this, 'SyncClock', $Sim::Time - $Game::StartTime);, Add:
---------------------------------------------------------------------------------------------------------------------

   commandToClient(%this, 'SetMaxLaps', $Game::Laps);

Change:
-------------


   // Create the player object
   %player = new Player() {
      dataBlock = PlayerBody;
      client = %this;
   };

To read:
-----------

   // Create the player object
   %player = new WheeledVehicle() {
      dataBlock = DefaultCar;
      client = %this;
   };

Save file.
-------------

You should now be good to go.
(or you can just copy the changed files I've already made for you.)

Here is the racing kit.
Here is the Cpp file I forgot to add to the zip.

Let's see what you can do with this.







#1
01/19/2009 (12:01 pm)
hello :)

interested in nice looking car for your kit?
img90.imageshack.us/img90/7063/car01vm6.th.jpg
#2
01/22/2009 (11:21 pm)
Thanks, that helped. did you use Max