示例#1
0
        public static int GetDirection(TDVector2 mNextXY)
        {
            if (mNextXY.X == 0 &&
                mNextXY.Y == 0) return -1;

            switch (mNextXY.X)
            {
                case 0:
                    if (mNextXY.Y ==
                        -1) return 0;
                    if (mNextXY.Y == 1) return 4;
                    break;
                case -1:
                    if (mNextXY.Y ==
                        -1) return 7;
                    if (mNextXY.Y == 1) return 5;
                    if (mNextXY.Y == 0) return 6;
                    break;
                case 1:
                    if (mNextXY.Y ==
                        -1) return 1;
                    if (mNextXY.Y == 1) return 3;
                    if (mNextXY.Y == 0) return 2;
                    break;
            }

            return 0;
        }
示例#2
0
 public void SetOnTextureRect(IntRect mIntRect)
 {
     OnStart = new TDVector2(mIntRect.Left, mIntRect.Top);
     OnEnd = new TDVector2(mIntRect.Width, mIntRect.Height);
 }
        public override void NextTurn()
        {
            base.NextTurn();

            TDPNode nextNode = null;
            var nextXY = TDVector2.Zero;

            if (_targetComponent.Target != null)
                nextXY = TDCMovement.GetNextXY(Entity, _targetComponent.Target.X, _targetComponent.Target.Y);

            if (IsPathfinder)
            {
                if (UsesPathmap)
                {
                    var pathmap = _instance.GetPathmap(PathmapName);
                    if (!pathmap.WasUpdatedThisTurn) pathmap.CalculatePathmap();

                    if (_movementComponent.IsReverse)
                    {
                        nextNode = pathmap.GetWorstAdjacentNode(X, Y, TDLTags.Solid, mIncludeStartNode: IncludesStartNode, mIgnoreEntities: _movementComponent.IgnoreEntities);
                        if (nextNode != null) _movementComponent.IgnoreReverseThisTurn(); // this class takes care of it!
                    }
                    else nextNode = pathmap.GetBestAdjacentNode(X, Y, TDLTags.Solid, mIncludeStartNode: IncludesStartNode, mIgnoreEntities: _movementComponent.IgnoreEntities);
                }
                else
                {
                    if (_targetComponent.Target == null) return;
                    nextNode = _instance.JumpPointSearch(X, Y, _targetComponent.Target.X, _targetComponent.Target.Y);
                }

                if (nextNode != null)
                {
                    nextXY = TDCMovement.GetNextXY(Entity, nextNode.X, nextNode.Y);
                    LastNodeXY = new TDVector2(nextNode.X, nextNode.Y);
                }
                else if (!IsObstinate) return;
            }

            if (SetsDirection)
            {
                if (_movementComponent.IsReverse && (!IsPathfinder || nextNode == null)) _directionComponent.Direction = TDCDirection.GetDirection(-nextXY);
                else _directionComponent.Direction = TDCDirection.GetDirection(nextXY);
            }

            LastNextXY = nextXY;

            _movementComponent.SetTarget(X + nextXY.X, Y + nextXY.Y);

            if (Entity.GetComponent<TDCKiller>() != null)
                foreach (var tag in _targetComponent.TargetTags)
                    foreach (var entity in Field.GetEntitiesByTag(tag))
                        _movementComponent.IgnoreEntities.Add(entity);
        }