Ejemplo n.º 1
0
        /// <summary>
        /// Instantiate a player with the given ID and return a reference to it
        /// </summary>
        /// <param name="userID">
        /// ID to assign to instantiated player
        /// </param>
        /// <param name="fortress">
        /// Fortress to assign to player
        /// </param>
        /// <returns>
        /// Instantiated player
        /// </returns>
        public Player AddPlayer(string userID, Fortress fortress)
        {
            // TODO: Handle adding active player as main player
            if (GetPlayer(userID))
            {
                return(null);
            }
            GameObject playerObject = Instantiate(_playerPrefab, this.transform);
            Player     player;

            Debug.Log(userID);
            Debug.Log(ConnectionManager.Instance.UserID);
            if (userID == ConnectionManager.Instance.UserID)
            {
                player      = playerObject.AddComponent <MainPlayer>();
                player.Peer = false;
                GameObject.FindGameObjectWithTag("MainCamera").GetComponent <Follow>().Target = playerObject.transform;
            }
            else
            {
                player      = playerObject.AddComponent <Peer>();
                player.Peer = true;
            }
            player.Initialize(userID, fortress);

            _players[userID] = player;

            return(player);
        }
Ejemplo n.º 2
0
        protected override void Awake()
        {
            base.Awake();

            animator       = GetComponent <Animator>();
            fortress       = FindObjectOfType <Fortress>();
            attackPosition = Physics2D.Raycast(transform.position, moveDirection).point;
        }
Ejemplo n.º 3
0
 public void Initialize(string userID, Fortress fortress)
 {
     UserID             = userID;
     Fortress           = fortress;
     _renderer          = transform.Find("Sprite").GetComponent <SpriteRenderer>();
     _mainPlayerMinimap = transform.Find("MainPlayerMinimap").gameObject;
     _enemyMinimap      = transform.Find("EnemyMinimap").gameObject;
     Despawn();
 }
Ejemplo n.º 4
0
        /// <summary>
        /// Get or create the player with the given ID
        /// </summary>
        /// <param name="userID">
        /// ID of player to get
        /// </param>
        /// <param name="fortressID">
        /// ID of fortress to assign to created player
        /// </param>
        /// <returns>
        /// Player with the given ID
        /// </returns>
        public Player GetOrAddPlayer(string userID, int fortressID = -1)
        {
            // TODO: Passing creation info into GetOrAddPlayer is bad
            Player player;

            if (_players.TryGetValue(userID, out player))
            {
                return(player);
            }
            else
            {
                // Create player if it doesn't exist
                Fortress fortress = GetFortress(fortressID);
                return(AddPlayer(userID, fortress));
            }
        }
Ejemplo n.º 5
0
        /// <summary>
        /// Get the Fortress with the given ID
        /// </summary>
        /// <param name="fortressID">
        /// ID of Fortress to get
        /// </param>
        /// <returns>
        /// Fortress with the given ID
        /// </returns>
        public Fortress GetFortress(int fortressID)
        {
            Fortress fortress = _fortresses.Keys.FirstOrDefault(item => item.ID == fortressID);

            return(fortress);
        }