Пример #1
0
    public void Setup(PlayerBattleModel player)
    {
        _playerColor.color = player.PlayerModel.Color;
        _playerScore.text  = player.Score.ToString();

        var playerIndex = ApplicationModels.GetModel <BattleModel>().Players.FindIndex(player);

        _playerName.text = string.Format(PlayerNameFormat, playerIndex + 1);

        SetPlayerReady(false);
    }
Пример #2
0
    private void AddRankingItem(PlayerBattleModel player)
    {
        var item = Instantiate(_rankingItemPrefab, transform);

        item.Setup(player);

        var statusPair = new ReadyStatusPair
        {
            Widget  = item,
            IsReady = false
        };

        _rankingItems.Add(player.PlayerModel, statusPair);
    }
Пример #3
0
    private void SpawnPlayer(PlayerController controller, PlayerBattleModel model, int spawnIndex)
    {
        var isIndexValid = spawnIndex >= 0 && spawnIndex < _spawnPoints.Length;
        var spawn        = isIndexValid ? _spawnPoints[spawnIndex] : _spawnPoints.RandomElement();

        var position = spawn.Position;

        position.y += 0.5f * controller.CharacterController.height * controller.transform.localScale.y;
        controller.transform.position = position;
        controller.Coords             = spawn.Tile.Coords;

        spawn.Tile.Content.Add(controller);
        model.IsSpawned   = true;
        controller.Status = PlayerController.InputStatus.Playing;
    }
Пример #4
0
    public void Initialize(PlayerBattleModel playerBattleModel)
    {
        if (_battleModel != null)
        {
            Deinitialize();
        }

        _battleModel = playerBattleModel;
        _battleModel.Events.ScoreChanged.Connect(SetScore);
        _battleModel.Events.Eliminated.Connect(OnEliminated);

        SetScore(_battleModel.Score);

        _playerColor.color = _battleModel.PlayerModel.Color;

        GameFacade.RoundStart.Connect(OnRoundStart);
    }
Пример #5
0
    private void SpawnPlayer(PlayerBattleModel model)
    {
        var controller = _players.Find(p => p.Owner == model.PlayerModel);

        // We don't want to spawn several players at the same place
        var emptySpawnPoints = new List <int>();

        for (int i = 0, count = _spawnPoints.Length; i < count; ++i)
        {
            if (!_spawnPoints[i].Tile.HasPlayer)
            {
                emptySpawnPoints.Add(i);
            }
        }

        var spawnIndex = emptySpawnPoints.Count > 0 ? emptySpawnPoints.RandomElement() : _spawnPoints.RandomIndex();

        SpawnPlayer(controller, model, spawnIndex);
    }
Пример #6
0
 public void OnPlayerHit(PlayerBattleModel victim, PlayerBattleModel attacker)
 {
     attacker.Score += victim == attacker ? -1 : 1;
     _playersToRespawn.Add(victim);
 }
Пример #7
0
 public static int CompareScores(PlayerBattleModel player, PlayerBattleModel otherPlayer)
 {
     return(otherPlayer.Score - player.Score);
 }
Пример #8
0
 public void OnPlayerHit(PlayerBattleModel victim, PlayerBattleModel attacker)
 {
     victim.Events.Eliminated.Invoke();
 }