Beispiel #1
0
        private void OnAmpDestroyed(AmpController amp)
        {
            _ampCounts[amp.OwnerId]--;

            if (_ampDictionary.ContainsKey(amp.OwnerId))
            {
                _ampDictionary[amp.OwnerId].Remove(amp);
            }

            _ampCounts[amp.OwnerId] = (_ampCounts[amp.OwnerId] < 0) ? 0 : _ampCounts[amp.OwnerId];
            _scoreP1.text           = _ampCounts[0].ToString();
            _scoreP2.text           = _ampCounts[1].ToString();
        }
Beispiel #2
0
        private void OnAmpPlaced(AmpController amp)
        {
            _ampCounts[amp.OwnerId]++;

            if (!_ampDictionary.ContainsKey(amp.OwnerId))
            {
                _ampDictionary.Add(amp.OwnerId, new List <AmpController>());
            }

            _ampDictionary[amp.OwnerId].Add(amp);

            _scoreP1.text = _ampCounts[0].ToString();
            _scoreP2.text = _ampCounts[1].ToString();
        }
Beispiel #3
0
        protected override void Update()
        {
            base.Update();

            m_MovementInputValue = (m_MovementInputValue == 0) ? UNInput.GetAxis(m_PlayerNumber, _networkVerticalAxis) : m_MovementInputValue;
            m_TurnInputValue     = (m_TurnInputValue == 0) ? UNInput.GetAxis(m_PlayerNumber, _networkHorizontalAxis) : m_TurnInputValue;

            if (Input.GetButtonDown(_placeAmpButton) || UNInput.GetButtonDown(m_PlayerNumber, "Action"))
            {
                Debug.LogFormat("Player {0} placed an Amp!", m_PlayerNumber);
                PlaceAmp();
            }

            if (Input.GetKeyDown(KeyCode.Backspace) || UNInput.GetButtonDown(m_PlayerNumber, "Start"))
            {
                for (int i = _amps.Count - 1; i >= 0; i--)
                {
                    var a = _amps[i];
                    DestroyAmp(a);
                }

                _amps.Clear();
            }

            var enemyAmps = GameController.Instance.EnemyAmps(_player);

            AmpController target  = null;
            var           minDist = float.MaxValue;

            foreach (var a in enemyAmps)
            {
                Vector3 point;
                var     dist = a.PowLine.SqrDistanceFromPoint(_transform.position, out point);

                if (dist < MaxCutSqrDistance && dist < minDist)
                {
                    minDist = dist;
                    Debug.DrawLine(point, point + Vector3.up * 100f, Color.yellow);
                    target = a;
                }
            }

            if (target != null && Input.GetButton(_cutButton) || UNInput.GetButton(m_PlayerNumber, "Back"))
            {
                target.Owner.DestroyAmp(target);
            }
        }
Beispiel #4
0
        private void DestroyAmp(AmpController amp)
        {
            if (amp.OwnerId != this.m_PlayerNumber)
            {
                return;
            }

            if (AmpDestroyed != null)
            {
                AmpDestroyed(amp);
            }
            amp.PowLine.LineConstrained -= OnPowerLineConstrained;
            amp.PowLine.LineReleased    -= OnPowerLineReleased;

            _amps.Remove(amp);
            Destroy(amp.gameObject);
        }