Beispiel #1
0
 public void Release()
 {
     _id       = 0;
     _nextNode = null;
     _owner    = null;
     _view     = null;
 }
Beispiel #2
0
        /// <summary>
        /// Snaker src collides to other.
        /// </summary>
        public static bool HitTest(Snaker src, Snaker other, ref SnakerNode hitNode, bool ignoreTeam = false)
        {
            hitNode = null;

            if (src == null || other == null || src.IsDead || other.IsDead)
            {
                return(false);
            }

            if (ignoreTeam || src.TeamID != other.TeamID)
            {
                SnakerNode node = other.Head.NextNode; // start from Head's next node
                while (node != null)
                {
                    if (node.IsKeyNode())
                    {
                        float distance = Vector3.Distance(src.Head.Position, node.Position);
                        if (distance <= src.Head.Radius + node.Radius)
                        {
                            hitNode = node;
                            return(true);
                        }
                    }
                    node = node.NextNode;
                }
            }
            return(false);
        }
Beispiel #3
0
 public SnakerAI(Snaker owner) : base(owner)
 {
     _aiType          = 0;
     _curState        = State.Wait;
     _curFrame        = 0;
     curStateEndFrame = 0;
 }
Beispiel #4
0
 public SnakerAI(Snaker owner, int aiType) : base(owner)
 {
     _aiType          = aiType;
     _curState        = State.Wait;
     _curFrame        = 0;
     curStateEndFrame = 0;
     _curTarget       = null;
 }
Beispiel #5
0
 public void SetFocusSnaker(int playerId)
 {
     _focusPlayerId = playerId;
     if (_focusPlayerId <= 0)
     {
         _focusSnaker = null;
     }
 }
Beispiel #6
0
 void OnSnakerDead(Snaker snaker, object killer)
 {
     if (_focusPlayerId == snaker.PlayerID)
     {
         _focusPlayerId = 0;
         SyncGameCamera();
     }
 }
Beispiel #7
0
        public void InitData(int id, int index, Snaker owner, Vector3 initPos)
        {
            _id     = id;
            _index  = index;
            _owner  = owner;
            _data   = CSVTableLoader.GetTableContainer("SnakerNode").GetRow(_id.ToString());
            _radius = _data["Radius"].IntValue;

            _prePosition = _position = initPos;
        }
Beispiel #8
0
 private void AddSnaker(Snaker snaker)
 {
     if (_snakerList.ContainsKey(snaker.PlayerID))
     {
         this.LogError("You are trying to add a duplicated snaker " + snaker.PlayerID.ToString());
     }
     else
     {
         _snakerList[snaker.PlayerID] = snaker;
     }
 }
Beispiel #9
0
        internal Snaker CreateSnaker(PlayerData data, Vector3 pos, float speed = 0f)
        {
            if (data == null)
            {
                return(null);
            }

            Snaker snaker = new Snaker(data, pos, speed);

            // Debuger.Log("BattleEngine", "CreateSnaker: {0}", data.playerID);
            tobeAddSnakerList.Add(snaker);

            return(snaker);
        }
Beispiel #10
0
        public override void Unbind()
        {
            base.Unbind();

            _model = null;

            DestroyNode(_head);
            DestroyNode(_tail);

            for (int i = 0; i < _nodeList.Count; i++)
            {
                DestroyNode(_nodeList[i]);
            }
            _nodeList.Clear();
        }
Beispiel #11
0
        /// <summary>
        /// Snaker src collides to food.
        /// </summary>
        public static bool HitTest(Snaker src, Food food)
        {
            if (src == null || food == null || src.IsDead || food.IsReleased)
            {
                return(false);
            }

            float distance = Vector3.Distance(src.Head.Position, food.Position);

            if (distance <= src.Head.Radius + food.Radius)
            {
                return(true);
            }

            return(false);
        }
Beispiel #12
0
        public void Bind(Snaker model)
        {
            _model = model;

            _nodeList.Clear();

            _head = CreateNode(_model.Head);
            _head.CachedTransform.SetParent(CachedTransform);

            _tail = CreateNode(_model.Tail);
            _tail.CachedTransform.SetParent(CachedTransform);

            SyncNodeList();

            DoUpdate(0f);
        }
Beispiel #13
0
        protected bool CheckNextHitSnaker(Vector3 nextPos, ref Vector3 outValue)
        {
            outValue.x = outValue.y = outValue.z = 0f;

            foreach (var kvs in BattleEngine.Instance.SnakerList)
            {
                if (kvs.Value != _owner)
                {
                    if (Snaker.HitTest(_owner, kvs.Value, ref hitNode))
                    {
                        outValue = nextPos - hitNode.Position;
                        return(true);
                    }
                }
            }
            return(false);
        }
Beispiel #14
0
        private SnakerActor CreateSnaker(Snaker snaker)
        {
            if (snaker == null)
            {
                return(null);
            }

            GameObject prefab = Resources.Load <GameObject>(snaker.Data["Prefab"].StringValue);
            GameObject go     = Instantiate <GameObject>(prefab);

            go.name = prefab.name + "_" + snaker.PlayerID.ToString();
            go.transform.SetParent(Root);
            SnakerActor view = go.EnsureComponent <SnakerActor>();

            view.Bind(snaker);

            return(view);
        }
Beispiel #15
0
        public void InputVKey(int vkey, float arg, int playerId)
        {
            if (!_isRunning)
            {
                return;
            }

            Snaker snaker = GetSnakerByID(playerId);

            if (snaker != null)
            {
                snaker.InputKey(vkey, arg);
            }
            else
            {
                HandleOtherInput(vkey, arg, playerId);
            }
        }
Beispiel #16
0
        void LateUpdate()
        {
            if (BattleEngine.Instance.isRunning)
            {
                if (_focusSnaker == null && _focusPlayerId > 0)
                {
                    _focusSnaker = BattleEngine.Instance.GetSnakerByID(_focusPlayerId);
                }

                if (_focusSnaker != null)
                {
                    Vector3 pos = BattleView.Instance.EntityToViewPos(_focusSnaker.Head.Position);
                    if (_tran.localPosition != pos)
                    {
                        Vector3 targetPos = _tran.localPosition;
                        targetPos.x         = pos.x;
                        targetPos.y         = pos.y;
                        _tran.localPosition = ClampPosition(targetPos);
                        //_tran.localPosition = Vector3.MoveTowards(_tran.localPosition, targetPos, Time.deltaTime * moveSmooth);
                    }
                }
            }
        }
Beispiel #17
0
 void OnDestroy()
 {
     current      = null;
     _focusSnaker = null;
 }
Beispiel #18
0
 public void Reset()
 {
     _focusPlayerId = 0;
     _focusSnaker   = null;
 }
Beispiel #19
0
 public SnakerComponent(Snaker owner)
 {
     _owner = owner;
 }
Beispiel #20
0
 public virtual void Release()
 {
     _owner = null;
 }
Beispiel #21
0
        public bool EnableRevive()
        {
            Snaker snaker = BattleEngine.Instance.GetSnakerByID(_mainPlayerId);

            return(snaker != null && snaker.IsDead);
        }
Beispiel #22
0
        public void OnSnakerDead(Snaker snaker, object killer)
        {
            Context.Game.OnPlayerDie(snaker.PlayerID);

            EventManager.Instance.SendEvent <Snaker, object>("OnSnakerDead", snaker, killer);
        }