Esempio n. 1
0
        public static UnitDirection RotateClockWise(this UnitDirection direction, int count)
        {
            UnitDirection rotated;

            if (count > 0)
            {
                rotated = direction switch
                {
                    UnitDirection.North => UnitDirection.East,
                    UnitDirection.East => UnitDirection.South,
                    UnitDirection.South => UnitDirection.West,
                    UnitDirection.West => UnitDirection.North,
                    _ => direction
                };
                return(RotateClockWise(rotated, count - 1));
            }
            if (count < 0)
            {
                rotated = direction switch
                {
                    UnitDirection.North => UnitDirection.West,
                    UnitDirection.East => UnitDirection.North,
                    UnitDirection.South => UnitDirection.East,
                    UnitDirection.West => UnitDirection.South,
                    _ => direction
                };
                return(RotateClockWise(rotated, count + 1));
            }
            return(direction);
        }
    }
}
Esempio n. 2
0
        // Shared utility:

        public (int x, int y) GetDirectionVector(UnitDirection direction)
        {
            int dx = 0, dy = 0;

            switch (direction)
            {
            case UnitDirection.North:
                dy--;
                break;

            case UnitDirection.East:
                dx++;
                break;

            case UnitDirection.South:
                dy++;
                break;

            case UnitDirection.West:
                dx--;
                break;

            default:
                break;
            }
            return(dx, dy);
        }
Esempio n. 3
0
        void SetDirection(UnitDirection direction)
        {
            if (CurrentDirection == direction)
            {
                return;
            }
            var currentScale = animPivot.transform.localScale;

            CurrentDirection = direction;
            if (CurrentDirection == UnitDirection.LEFT)
            {
                if (currentScale.x > 0)
                {
                    currentScale.x *= -1f;
                }
            }
            else
            {
                if (currentScale.x < 0)
                {
                    currentScale.x *= -1f;
                }
            }
            animPivot.transform.localScale = currentScale;
        }
Esempio n. 4
0
 void Awake()
 {
     colour        = GetRandomColour();
     direction     = UnitDirection.Left;
     minX          = 0;
     maxX          = 0;
     walkingToGoal = false;
     speed         = GameConstants.RECRUITMENT_UNIT_WALK_SPEED;
 }
Esempio n. 5
0
 public void changeDirection(UnitDirection d)
 {
     if (direction == d)
     {
         return;
     }
     direction           = d;
     frameNum            = 0;
     lastFrameChangeTime = Time.realtimeSinceStartup;
 }
Esempio n. 6
0
        public SubWeapon currentSubWeapon = SubWeapon.MACHINEGUN;//나중에 옮길 것

        private void Awake()
        {
            if (MoveController != null)
            {
                //smth
                Destroy(gameObject);
                return;
            }
            _moveController  = this;
            CurrentDirection = UnitDirection.RIGHT;
        }
Esempio n. 7
0
 public void FaceDirection(UnitDirection dir)
 {
     if (dir == UnitDirection.Left)
     {
         anim.transform.localScale = new Vector3(Mathf.Abs(anim.transform.localScale.x), anim.transform.localScale.y, anim.transform.localScale.z);
     }
     else if (dir == UnitDirection.Right)
     {
         anim.transform.localScale = new Vector3(-Mathf.Abs(anim.transform.localScale.x), anim.transform.localScale.y, anim.transform.localScale.z);
     }
 }
Esempio n. 8
0
 public void WalkToGoal(float x, float time)
 {
     walkingToGoal = true;
     goalX         = x;
     if (transform.position.x > x)
     {
         direction = UnitDirection.Left;
     }
     else
     {
         direction = UnitDirection.Right;
     }
     speed = Mathf.Max(GameConstants.RECRUITMENT_UNIT_RUN_SPEED,
                       Mathf.Abs(transform.position.x - x) / time);
 }
Esempio n. 9
0
    void UpdateWalking()
    {
        switch (direction)
        {
        case UnitDirection.Left:
            SetDeltaX(-speed * Time.deltaTime);
            SetScaleXSign(-1);
            if (GetX() <= minX)
            {
                SetX(minX);
                direction = UnitDirection.Right;
            }
            break;

        case UnitDirection.Right:
            SetDeltaX(speed * Time.deltaTime);
            SetScaleXSign(1);
            if (GetX() >= maxX)
            {
                SetX(maxX);
                direction = UnitDirection.Left;
            }
            break;
        }

        if (walkingToGoal)
        {
            if ((direction == UnitDirection.Left && transform.position.x <= goalX) ||
                (direction == UnitDirection.Right && transform.position.x >= goalX))
            {
                walkingToGoal    = false;
                renderer.enabled = false;
                speed            = 0;
            }
        }
    }
Esempio n. 10
0
    public void EnableLaser(PassageObjectModel passage, List <WorkerModel> targets)
    {
        currentPassage  = passage;
        this.targetList = targets;

        float         startX         = this.model.GetMovableNode().GetCurrentViewPosition().x;
        float         minX           = 0f;
        MapNode       passageEndNode = null;
        UnitDirection rot            = UnitDirection.RIGHT;

        if (passage == null)
        {
            Debug.Log("Null");

            LaserDisable();
            return;
        }

        foreach (MapNode node in passage.GetNodeList())
        {
            UnitDirection dir;
            float         nodeX = node.GetPosition().x;
            float         value = 0f;
            if (startX > nodeX)
            {
                value = startX - nodeX;
                dir   = UnitDirection.LEFT;
            }
            else if (startX == nodeX)
            {
                continue;
            }
            else
            {
                value = nodeX - startX;
                dir   = UnitDirection.RIGHT;
            }

            if (value > minX)
            {
                minX           = value;
                passageEndNode = node;
                rot            = dir;
            }
        }
        script.SetUnitDirection(rot);
        currentDir = rot;

        /*
         * minX = float.MaxValue;
         * WorkerModel target = null;
         * foreach (WorkerModel wm in targets) {
         *  float currentX = wm.GetMovableNode().GetCurrentViewPosition().x;
         *  float val = 0f;
         *
         *
         *
         * }
         *
         */

        //this.endPos.transform.position = target.GetMovableNode().GetCurrentViewPosition();

        //currentTarget = target;
        ReadyPos();//Stopping worker needed
    }