Esempio n. 1
0
        public void Update(double deltaTime)
        {
            if (_failedTrys > 10)
            {
                return;
            }

            _lastUpdate += deltaTime;

            var ent    = EntityManager.GetEntiy <GameObject>(EntID);
            var posCom = ent.GetComponent <IPostionComponet>(PostionAlias);
            var curPos = posCom.GetPostion();

            if (_lastUpdate > PathUpdateInterval)
            {
                _path = new Queue <Postion2D>(new AStarSerach().FindPath(Grid, curPos, Target, ObstaclePattern));

                if (!_path.Last().WithinRadius(Target, 3))
                {
                    _failedTrys++;
                }

                _subTarget  = curPos;
                _lastUpdate = 0;
            }

            if (curPos.WithinRadius(_subTarget, 3))
            {
                if (_path.Count > 0)
                {
                    _subTarget = _path.Dequeue();
                }
                else
                {
                    TriggeredAtTarget.ForEach(i => GameEvenetPostMaster.Add(ent.GetIdForAlais(i)));
                }
            }

            var target = _subTarget;

            //System.Diagnostics.Debug.WriteLine("CUR POS {0} TARGET {1}", curPos, target);
            if (!curPos.WithinRadius(target, 3))
            {
                var curInc = Utils.IncrmnetForPoint(curPos, target, deltaTime, Speed);

                curPos += curInc;
                posCom.SetPostion(curPos);
            }
        }
Esempio n. 2
0
        public void Update(double deltaTime)
        {
            var ent    = EntityManager.GetEntiy <GameObject>(EntID);
            var posCom = ent.GetComponent <IPostionComponet>(PostionAlias);
            var curPos = posCom.GetPostion();
            var target = Target;

            if (!curPos.WithinRadius(target, Radius))
            {
                var curInc = Utils.IncrmnetForPoint(curPos, target, deltaTime, Speed);

                curPos += curInc;
                posCom.SetPostion(curPos);
            }
            else if (!_targetHit)
            {
                _targetHit = true;
                TriggeredAtTarget.ForEach(i => GameEvenetPostMaster.Add(ent.GetIdForAlais(i)));
            }
        }
Esempio n. 3
0
        public void Update(double deltaTime)
        {
            var ent    = EntityManager.GetEntiy <GameObject>(EntID);
            var posCom = ent.GetComponent <IPostionComponet>(PosAlais);
            var curPos = posCom.GetPostion();
            var target = _movingTowardsEnd ? End : Start;
            var curInc = Utils.IncrmnetForPoint(curPos, target, deltaTime, Speed);

            if (_firstTime)
            {
                Start      = curPos;
                _firstTime = false;
            }

            curPos += curInc;
            posCom.SetPostion(curPos);

            if (curPos.WithinRadius(target, Radius))
            {
                TriggeredAtTarget.ForEach(i => GameEvenetPostMaster.Add(ent.GetIdForAlais(i)));
                _movingTowardsEnd = !_movingTowardsEnd;
            }
        }