Game Development Community

Need score help

by Jason Walters · in Torque X 2D · 12/15/2008 (10:23 am) · 2 replies

Hello!

Are there are good score tutorials out there? I am working on a shooter and would like to assign a certain amount of points to each enemy character. When the player destroys a specific character I would like his score to reflect those points.

I've gone through most of the torquex tutorials but, I'm still learning so please go easy. :)

#1
12/15/2008 (4:31 pm)
There are many ways to do it, so it's really up to you. One easy way to do this is to keep this in your Game class as integers (for fixed number of players) or an ArrayList (for a variable number of players). Then expose those variables to the rest of your project. Soooo.....

Game.cs would have something like this...

public class Game : TorqueGame
{
     private int _playerScore1 = 0;
     private int _playerScore2 = 0;
 
        public int PlayerScore1
        {
            get { return _playerScore1;  }
            set { _playerScore1 = value; }
        }
 
        public int PlayerScore2
        {
            get { return _playerScore2;  }
            set { _playerScore2 = value; }
        }
}

And then the rest of your game (any component, any gui, and object) can make the following call...

Game.Instance.PlayerScore1 = 100;

-or-

string output = "Your score is: " + Game.Instance.PlayerScore2;

Again, lots of ways to do this and there's no "right way" to do this.

John K.

(Edit:added code formatting)
#2
12/16/2008 (7:33 pm)
Thanks John!