Game Development Community

Player Lives..

by Tom Feni · in Torque Game Builder · 01/05/2006 (5:44 pm) · 3 replies

Ok I am trying to add player lives to the game.. here is where I am at so far..

in client.cs

function setupT2DScene()
{

 // Create fxSceneGraph2D.
	new fxSceneGraph2D(t2dSceneGraph);

    //t2dSceneGraph.setDebugOn( BIT(0) );
    t2dSceneGraph.setScenePhysicsFPSActive(true);
	// Associate Scenegraph with Window.
	sceneWindow2D.setSceneGraph( t2dSceneGraph );

    // Setyo Player.
	setupPlayer();
    setLives();
    //create Paddles
    setupPaddles();
    //setupRotaters();
    //create Paddles
    setupbumpers();

    //create Plunger
    setupPlunger();

    // Set up the enemy
    //CreateEnemy();
    // Reference Layers.
    $score = 0;
 ......etc

and in player.cs

function resetPlayerScore()
{
	// Reset Player Score.
	$playerScore = 0;

	// Update Scores.
	updateScore();
}



function addPlayerScore(%score)
{
	// Update Player Score.
	$playerScore += %score;
    checkForExtraLife()

	// Update Best Score if needed.
	if ( $playerScore > $pref::pinball::bestScore )
		$pref::pinball::bestScore = $playerScore;

	// Update Scores.
	updateScore();
}

function setLives()
{
    $playerLives = 3;

}




function checkForExtraLife()
{
         $rewardExtraLifeAt = 500; //initial value
    if 	 ( $playerScore >= $rewardExtraLifeAt )
    {
    	$playerLives += 1; //add one life, could do $playerLives = $playerLives + 1;
    	$rewardExtraLifeAt += 500; //use this for extralife at 500,1000,1500,2000 etc
    	//$rewardExtraLifeAt *= 2; //use this for extralife at 500,1000,2000,4000,8000
     	echo ("got some lives");
    }
}

function newLives() {
    %times = 0;
    if (!$nReward)
        $nReward = 500;
    while ($playerScore > $nReward) {
        $nReward *= 2;
        $playerLives++;
        %times++;

    }
    echo ("Received" SPC %times SPC "lives.");
}

function KillPlayer() {
   $player.setVisible( false );
   $player.setAtRest();
   $playerLives--;
   playerMap.pop();
   schedule(10, 0, "ResetPlayer");

 }

function ResetPlayer()
   {
   $player.setPosition("114 55");
   $player.setVisible(true);
   $player.setAtRest();
   //schedule(2000,0,launch);
   // Reset Player Score.
   if ($playerLives <= 0) {
         $playerLives = 0;
         resetPlayerScore();

   }
   else {
      playerMap.push();
   }
   echo("Player has " @ $playerLives @ " left.");
}

.... etc

and in pref.cs

$pref::particleEditor2D::viewZoom = "1";
$pref::pinball::bestScore = "13720";
$pref::lives = "0";
$Pref::player::CurrentFOV = 45;
$pref::Player::defaultFov = 90;


now it works for the most part but it wont add the 1 player at 500 points.. :)
any ideas?

TomFeni

#1
01/05/2006 (7:06 pm)
There is no semi-colon in this line

checkForExtraLife()


In this function

function addPlayerScore(%score)
{
	// Update Player Score.
	$playerScore += %score;
    checkForExtraLife()

	// Update Best Score if needed.
	if ( $playerScore > $pref::pinball::bestScore )
		$pref::pinball::bestScore = $playerScore;

	// Update Scores.
	updateScore();
}
#2
01/05/2006 (7:41 pm)
One thing that i spotted is every time you call checkForExtraLife() you always set $rewardExtraLifeAt back to 500.

What i think you're trying to do (correct me if i'm wrong please) :-

- Check if score is bigger than 500, if so, reward life and set next score check at 1000.
- Check if score is bigger than 1000, if so, reward life and set next score check at 1500.

To fix it, i believe you can just declare $rewardExtraLifeAt = 500; outside of the checkForExtraLife() function. I'd put it in one of the setup functions you're using so it only gets called once, at the start of the game. Then after that you can keep incrementing by 500 each time you check for the extra life.

I'm not the best at explaining, if i dont make any sense, i'm sorry :>
#3
01/05/2006 (8:59 pm)
No problem.. I actually came up with the fix.. I will post it in a bit.. :)