예제 #1
0
 public Player(string playername, UnitType type, Dictionary<Keys, Controllers> input)
     : base(type)
 {
     Name = playername;
     Position 		= new Vector2 (100, 100);
     _controlMap     = input;
     Team = 'P';     //Team Player
 }
예제 #2
0
 /// <summary>
 /// Constructor for an Entity
 /// </summary>
 /// <param name="textureID">The name of the texture file to use</param>
 public Entity(UnitType type)
 {
     IsCollidable = true;
     this.type = type;
     Texture = type.Texture;
     Width = Texture.Width;
     Height = Texture.Height;
     TurnRate = type.GetValue<float>(UnitValues.TurnRate);
     MaxHealth = Health = type.GetValue<float>(UnitValues.Health);
     Speed = type.GetValue<float>(UnitValues.Speed);
     PrimaryWeapon = ResourceManager.GetParticleTemplate(type.GetValue<string>(UnitValues.PrimaryWeapon));
     SecondaryWeapon = ResourceManager.GetParticleTemplate(type.GetValue<string>(UnitValues.SecondaryWeapon));
     DestroyOnCollsion = type.GetValue<bool>(UnitValues.DestroyOnCollision);
 }
        public SelectPlayerState(int numberOfplayers, bool versus, List<Player> playerList = null)
        {
            //First player?
            if (playerList == null) playerList = new List<Player>();

            //Load all playable tanks
            _playableUnits.AddRange(ResourceManager.GetAllUnitTypes().Where(unit => unit.GetValue<bool>(UnitValues.IsPlayable)));
            _unitType = _playableUnits[0];

            int x = 50;
            int y = 50;
            Label player1Label = new Label("=PLAYER " + (playerList.Count + 1) + "=", x, y);
            components.Add(player1Label);

            x = 400;
            y += 32;

            components.Add(new Label("Name: ", x, y));

            //Player name
            InputField player1Name = new InputField("Player " + (playerList.Count + 1), x + 100, y, 150, 32);
            components.Add(player1Name);
            y += 100;

            //Unit Type
            Label unitType = new Label("Unit Type", x, y);
            components.Add(unitType);
            y += 150;
            x += 50;

            Button previousType = new Button("<-", x, y, 32, 32);
            previousType.SetOnClickFunction(() =>
                {
                    int index = _playableUnits.IndexOf(_unitType) - 1;
                    if (index < 0) index = _playableUnits.Count-1;
                    _unitType = _playableUnits[index];
                });
            components.Add(previousType);

            Button nextType = new Button("->", x + 50, y, 32, 32);
            nextType.SetOnClickFunction(() =>
            {
                int index = _playableUnits.IndexOf(_unitType) + 1;
                if (index >= _playableUnits.Count) index = 0;
                _unitType = _playableUnits[index];
            });
            components.Add(nextType);

            //Load default controls
            x = 50;
            y = 82;
            if (playerList.Count == 0)
            {
                _playerInput[Keys.RightShift] = Player.Controllers.Secondary;
                _playerInput[Keys.RightControl] = Player.Controllers.Primary;
                _playerInput[Keys.Right] = Player.Controllers.Right;
                _playerInput[Keys.Up] = Player.Controllers.Forward;
                _playerInput[Keys.Down] = Player.Controllers.Back;
                _playerInput[Keys.Left] = Player.Controllers.Left;
            }
            else
            {
                _playerInput[Keys.LeftShift] = Player.Controllers.Secondary;
                _playerInput[Keys.LeftControl] = Player.Controllers.Primary;
                _playerInput[Keys.D] = Player.Controllers.Right;
                _playerInput[Keys.W] = Player.Controllers.Forward;
                _playerInput[Keys.S] = Player.Controllers.Back;
                _playerInput[Keys.A] = Player.Controllers.Left;
            }

            foreach (var input in _playerInput)
            {
                Keys key = input.Key;
                Player.Controllers controller = input.Value;

                y += 32;
                Label inputMap = new Label(controller.ToString() + ":", x, y);
                components.Add(inputMap);

                Button keyMap = new Button(key.ToString(), x + 150, y, 150, 32);
                keyMap.SetOnClickFunction(() =>
                    {
                        keyMap.setText("...");
                        _getControlKey = controller;
                        _getInputKey = keyMap;
                        _playerInput.Remove(key);
                    });
                components.Add(keyMap);
            }

            //Buttons to start game or go back to main menu
            Button newGameButton = new Button("Start!", 550, 400);
            newGameButton.SetOnClickFunction(() =>
                {
                    playerList.Add(new Player(player1Name.Text, _unitType, _playerInput));
                    if(versus) playerList.Last().Team += (char)playerList.Count;

                    if (playerList.Count < numberOfplayers)
                    {
                        NextGameState = new SelectPlayerState(numberOfplayers, versus, playerList);
                    }
                    else
                    {
                        NextGameState = new PlayingState(playerList, versus);
                        DestroyCurrentState();
                    }

                });
            components.Add(newGameButton);

            Button backButton = new Button("Back", 50, 400, 150, 50, Keys.Escape);
            backButton.SetOnClickFunction(() =>
                {
                    NextGameState = null;
                });
            components.Add(backButton);
        }
        public static UnitType GetUnitType(string unitID)
        {
            if (!_loadedUnits.ContainsKey(unitID))
            {
                _loadedUnits[unitID] = new UnitType(ContentFolder + "units/" + unitID);
            }

            return _loadedUnits[unitID];
        }