Exemplo n.º 1
0
 public void ChangeDirection(VectorDirection direction)
 {
     this.direction = direction;
     // reset out animation frame counter
     _frameIndex       = 0;
     _directionChanged = true;
 }
Exemplo n.º 2
0
 public Vector(int offset, string reg, int count, VectorDirection dir)
 {
     Offset    = offset;
     Register  = reg;
     Count     = count;
     Direction = dir;;
 }
Exemplo n.º 3
0
        public static Vector2Int GetVectorTowardsDirection(VectorDirection direction)
        {
            switch (direction)
            {
            case VectorDirection.North:
                return(NORTH);

            case VectorDirection.NorthEast:
                return(NORTH_EAST);

            case VectorDirection.NorthWest:
                return(NORTH_WEST);

            case VectorDirection.South:
                return(SOUTH);

            case VectorDirection.SouthEast:
                return(SOUTH_EAST);

            case VectorDirection.SouthWest:
                return(SOUTH_WEST);

            case VectorDirection.East:
                return(EAST);

            case VectorDirection.West:
                return(WEST);

            case VectorDirection.None:
                return(new Vector2Int(0, 0));

            default:
                throw new Exception("Bad direction");
            }
        }
Exemplo n.º 4
0
 public static void OnMovingInput(VectorDirection direction)
 {
     if (onPlayerMovingInput != null)
     {
         onPlayerMovingInput(direction);
     }
 }
Exemplo n.º 5
0
        public static VectorDirection GetVectorDirection(this Vector vector)
        {
            var             x_ = vector.X;
            var             y_ = vector.Y;
            VectorDirection V_ = 0;

            #if DEBUG
            Stopwatch st = new Stopwatch();
            st.Start();
            #endif

            if (double.IsNegative(x_) && double.IsNegative(y_))
            {
                V_ = VectorDirection.AllNegative;
            }
            else if (double.IsNegative(x_) && double.IsNormal(y_))
            {
                V_ = VectorDirection.NegativeX;
            }
            else if (double.IsNormal(x_) && double.IsNegative(y_))
            {
                V_ = VectorDirection.NegativeY;
            }
            else if (!double.IsNegative(x_) && !double.IsNegative(y_))
            {
                V_ = VectorDirection.AllPositive;
            }

            #if DEBUG
            st.Stop();
            Debug.WriteLine($"measure direction takes {st.ElapsedMilliseconds} ms too long");
            #endif

            return(V_);
        }
Exemplo n.º 6
0
 public static void OnMovingInput(VectorDirection direction)
 {
     if (onPlayerMovingInput != null)
     {
         onPlayerMovingInput(direction);
     }
 }
Exemplo n.º 7
0
 public ComputationResult(ComputationResult res, VectorDirection direction)
 {
     OdData       = res.OdData;
     LiteralValue = res.LiteralValue;
     VectorData   = res.VectorData;
     Direction    = direction;
 }
Exemplo n.º 8
0
        /// <summary>
        /// Gets the vector R(n) or C(n) from the matrix
        /// </summary>
        /// <param name="mat">The matrix</param>
        /// <param name="direction">The direction to retrive the vector from (either rows or columns)</param>
        /// <param name="index">The index of the row or column</param>
        /// <returns>The vector at R(n) or C(n)</returns>
        public static T[] GetVector <T>(this T[,] mat, VectorDirection direction, int index)
        {
            T[] vector = new T[mat.GetDimensions().InDirection(direction)];

            // if (vector.Length <= index){
            //     throw new IndexOutOfRangeException($"Index {index + 1} is larger than the size of the matrix axis {vector.Length}");
            // }
            if (index < 1)
            {
                throw new IndexOutOfRangeException($"Index {index} is less than 1");
            }

            if (direction == VectorDirection.Row)
            {
                for (int c = 0; c < vector.Length; c++)
                {
                    vector[c] = mat[index - 1, c];
                }
            }
            else
            {
                for (int r = 0; r < vector.Length; r++)
                {
                    vector[r] = mat[r, index - 1];
                }
            }

            return(vector);
        }
Exemplo n.º 9
0
 /// <summary>
 /// Converts a "smooth" jagged 2D array into a matrix
 /// </summary>
 /// <param name="jaggedArray">The "smooth" jagged 2D array</param>
 /// <param name="direction">The direction of the jagged 2D array's major axis</param>
 /// <returns>A matrix of the jagged 2D array</returns>
 public static T[,] ToMatrix <T>(this T[][] jaggedArray, VectorDirection direction)
 {
     if (jaggedArray.Length == 0)
     {
         throw new MatrixSizeException("A matrix cannot have zero elements");
     }
     foreach (T[] arr in jaggedArray)
     {
         if (jaggedArray[0].Length != arr.Length)
         {
             throw new MatrixSizeException("A matrix cannot be jagged");
         }
     }
     if (jaggedArray[0].Length == 0)
     {
         throw new MatrixSizeException("A matrix cannot have zero elements");
     }
     if (direction == VectorDirection.Row)
     {
         return(new MatrixDimensions(jaggedArray.Length, jaggedArray[0].Length).CreateMatrix <T>().Apply((v, r, c) => jaggedArray[r - 1][c - 1]));
     }
     else
     {
         return(new MatrixDimensions(jaggedArray[0].Length, jaggedArray.Length).CreateMatrix <T>().Apply((v, r, c) => jaggedArray[c - 1][r - 1]));
     }
 }
Exemplo n.º 10
0
    protected override void OnPlayerInput(VectorDirection direction)
    {
        if (State.MovingMode != MoveMode.Snapping &&
            _isMovingEnabled != false)
        {
            if (direction == VectorDirection.Up)
            {
                if (CanJump)
                {
                    Jump();
                    SetAniamation("idle", true);
                }
                else if (CanReduceGravity)
                {
                    gravity.ReduceGravity();
                    SetAniamation("fly", true);
                }
                return;
            }

            if ((direction == VectorDirection.Right && !_isFacingForward) ||
                (direction == VectorDirection.Left && _isFacingForward))
            {
                Flip();
            }
        }
        _direction = direction;
    }
 public void SetShoot(bool shoot, VectorDirection vectorDirection)
 {
     if (this.CanShoot())
     {
         this.Shoot = shoot;
     }
 }
Exemplo n.º 12
0
        /// <summary>
        /// Inserts a row or column vector into a matrix
        /// </summary>
        /// <param name="mat">The matrix</param>
        /// <param name="direction">The type of vector to insert (row or column)</param>
        /// <param name="insertIndex">The vector index to insert at</param>
        /// <param name="vector">The vector to insert at the index. If not incuded or null, the vector is populated with default values.</param>
        /// <returns>The matrix with an additional row/column at the specified index</returns>
        public static T[,] InsertVector <T>(this T[,] mat, VectorDirection direction, int insertIndex, T[] vector = null)
        {
            MatrixDimensions d = mat.GetDimensions();

            T[,] newMat;

            if (vector != null && d.InDirection(direction) != vector.Length)
            {
                throw new VectorSizeException("A vector cannot be inserted into a matrix of a different size");
            }

            if (direction == VectorDirection.Column)
            {
                if (insertIndex > d.cols + 1 || insertIndex < 1)
                {
                    throw new IndexOutOfRangeException("That column index does not and will not exist in the new matrix.");
                }
                newMat = new T[d.rows, d.cols + 1];
                return(newMat.Apply((v, r, c) => {
                    if (c < insertIndex)
                    {
                        return mat[r - 1, c - 1];
                    }
                    else if (c > insertIndex)
                    {
                        return mat[r - 1, c - 2];
                    }
                    if (vector != null)
                    {
                        return vector[r - 1];
                    }
                    return v;
                }));
            }
            else
            {
                if (insertIndex > d.rows + 1 || insertIndex < 1)
                {
                    throw new IndexOutOfRangeException("That row index does not and will not exist in the new matrix.");
                }
                newMat = new T[d.rows + 1, d.cols];
                return(newMat.Apply((v, r, c) => {
                    if (r < insertIndex)
                    {
                        return mat[r - 1, c - 1];
                    }
                    else if (r > insertIndex)
                    {
                        return mat[r - 2, c - 1];
                    }
                    if (vector != null)
                    {
                        return vector[c - 1];
                    }
                    return v;
                }));
            }
        }
Exemplo n.º 13
0
 /// <summary>
 /// Applies a vector function to a matrix in a specified direction
 /// </summary>
 /// <param name="matrix">The matrix</param>
 /// <param name="direction">The direction of vector to apply on</param>
 /// <param name="f">The function to be applied over each vector in the matrix
 /// <para>Its arguments are the vector along the specified axis and the index of that vector.</para></param>
 /// <returns></returns>
 public static T[,] ApplyOverVector <T>(this T[,] matrix, VectorDirection direction, Func <T[], int, T[]> f)
 {
     T[][] arr = matrix.ToJagged(direction);
     for (int i = 0; i < arr.Length; i++)
     {
         arr[i] = f.Invoke(matrix.GetVector(direction, i + 1), i + 1);
     }
     return(arr.ToMatrix(direction));
 }
Exemplo n.º 14
0
 /// <summary>
 /// Converts a matrix to a jagged 2D array
 /// </summary>
 /// <param name="matrix">The matrix</param>
 /// <param name="direction">The direction for the major axis of the jagged 2D array</param>
 /// <returns>A jagged 2D array of the matrix</returns>
 public static T[][] ToJagged <T>(this T[,] matrix, VectorDirection direction)
 {
     T[][] jaggedArray = new T[matrix.GetDimensions().InDirection(direction)][];
     for (int i = 0; i < jaggedArray.Length; i++)
     {
         jaggedArray[i] = matrix.GetVector(direction, i + 1);
     }
     return(jaggedArray);
 }
Exemplo n.º 15
0
    /// <summary>
    /// Start this instance.
    /// </summary>
    private void Start()
    {
        // Make the transform the current parent if no object has been selected
        if (!tileTransform)
        {
            tileTransform = this.transform.parent;
        }

        orgTransformVector = VectorDirection.DetermineDirection(triggerDirection);
        oppTransformVector = VectorDirection.DetermineOppositeDirection(triggerDirection);
    }
Exemplo n.º 16
0
    public MoveTile() : base("moveTileUp0")
    {
        _leftFrameElements  = new FAtlasElement[4];
        _rightFrameElements = new FAtlasElement[4];
        _upFrameElements    = new FAtlasElement[4];
        _downFrameElements  = new FAtlasElement[4];

        FAtlasManager am = Futile.atlasManager;

        _leftFrameElements[0] = am.GetElementWithName("moveTileLeft0");
        _leftFrameElements[1] = am.GetElementWithName("moveTileLeft1");
        _leftFrameElements[2] = am.GetElementWithName("moveTileLeft2");
        _leftFrameElements[3] = am.GetElementWithName("moveTileLeft3");

        _rightFrameElements[0] = am.GetElementWithName("moveTileRight0");
        _rightFrameElements[1] = am.GetElementWithName("moveTileRight1");
        _rightFrameElements[2] = am.GetElementWithName("moveTileRight2");
        _rightFrameElements[3] = am.GetElementWithName("moveTileRight3");

        _upFrameElements[0] = am.GetElementWithName("moveTileUp0");
        _upFrameElements[1] = am.GetElementWithName("moveTileUp1");
        _upFrameElements[2] = am.GetElementWithName("moveTileUp2");
        _upFrameElements[3] = am.GetElementWithName("moveTileUp3");

        _downFrameElements[0] = am.GetElementWithName("moveTileDown0");
        _downFrameElements[1] = am.GetElementWithName("moveTileDown1");
        _downFrameElements[2] = am.GetElementWithName("moveTileDown2");
        _downFrameElements[3] = am.GetElementWithName("moveTileDown3");

        _placedAt = 0.0f;

        int randomDirection = RXRandom.Range(0, 4);

        this.direction = VectorDirection.Up;         // (VectorDirection)randomDirection;

        if (randomDirection == 1)
        {
            this.direction = VectorDirection.Left;
            this.element   = _leftFrameElements[0];
        }
        else if (randomDirection == 2)
        {
            this.direction = VectorDirection.Right;
            this.element   = _rightFrameElements[0];
        }
        else if (randomDirection == 3)
        {
            this.direction = VectorDirection.Down;
            this.element   = _downFrameElements[0];
        }

        ListenForUpdate(HandleUpdate);
    }
Exemplo n.º 17
0
    public Crew() : base("walkRight0")
    {
        this.defaultVelocity = 100;
        this.currentVelocity = this.defaultVelocity;

        int randomDirection = RXRandom.Range(0, 4);

        this.direction = VectorDirection.Up;         // (VectorDirection)randomDirection;

        if (randomDirection == 1)
        {
            this.direction = VectorDirection.Left;
        }
        else if (randomDirection == 2)
        {
            this.direction = VectorDirection.Right;
        }
        else if (randomDirection == 3)
        {
            this.direction = VectorDirection.Down;
        }


        _leftFrameElements  = new FAtlasElement[4];
        _rightFrameElements = new FAtlasElement[4];
        _upFrameElements    = new FAtlasElement[4];
        _downFrameElements  = new FAtlasElement[4];

        FAtlasManager am = Futile.atlasManager;

        _rightFrameElements[0] = am.GetElementWithName("walkRight0");
        _rightFrameElements[1] = am.GetElementWithName("walkRight1");
        _rightFrameElements[2] = am.GetElementWithName("walkRight2");
        _rightFrameElements[3] = am.GetElementWithName("walkRight3");

        _leftFrameElements[0] = am.GetElementWithName("walkLeft0");
        _leftFrameElements[1] = am.GetElementWithName("walkLeft1");
        _leftFrameElements[2] = am.GetElementWithName("walkLeft2");
        _leftFrameElements[3] = am.GetElementWithName("walkLeft3");

        _upFrameElements[0] = am.GetElementWithName("walkUp0");
        _upFrameElements[1] = am.GetElementWithName("walkUp1");
        _upFrameElements[2] = am.GetElementWithName("walkUp2");
        _upFrameElements[3] = am.GetElementWithName("walkUp3");

        _downFrameElements[0] = am.GetElementWithName("walkDown0");
        _downFrameElements[1] = am.GetElementWithName("walkDown1");
        _downFrameElements[2] = am.GetElementWithName("walkDown2");
        _downFrameElements[3] = am.GetElementWithName("walkDown3");


        ListenForUpdate(HandleUpdate);
    }
Exemplo n.º 18
0
 private void OnPlayerInput(VectorDirection direction)
 {
     if (State.MovingMode != MoveMode.Snapping &&
         _isMovingEnabled != false &&
         (
             (direction == VectorDirection.Right && !_isFacingForward) ||
             (direction == VectorDirection.Left && _isFacingForward)
         ))
     {
         Flip();
     }
     _direction = direction;
 }
Exemplo n.º 19
0
    public MoveTile()
        : base("moveTileUp0")
    {
        _leftFrameElements = new FAtlasElement[4];
        _rightFrameElements = new FAtlasElement[4];
        _upFrameElements = new FAtlasElement[4];
        _downFrameElements = new FAtlasElement[4];

        FAtlasManager am = Futile.atlasManager;

        _leftFrameElements[0] = am.GetElementWithName("moveTileLeft0");
        _leftFrameElements[1] = am.GetElementWithName("moveTileLeft1");
        _leftFrameElements[2] = am.GetElementWithName("moveTileLeft2");
        _leftFrameElements[3] = am.GetElementWithName("moveTileLeft3");

        _rightFrameElements[0] = am.GetElementWithName("moveTileRight0");
        _rightFrameElements[1] = am.GetElementWithName("moveTileRight1");
        _rightFrameElements[2] = am.GetElementWithName("moveTileRight2");
        _rightFrameElements[3] = am.GetElementWithName("moveTileRight3");

        _upFrameElements[0] = am.GetElementWithName("moveTileUp0");
        _upFrameElements[1] = am.GetElementWithName("moveTileUp1");
        _upFrameElements[2] = am.GetElementWithName("moveTileUp2");
        _upFrameElements[3] = am.GetElementWithName("moveTileUp3");

        _downFrameElements[0] = am.GetElementWithName("moveTileDown0");
        _downFrameElements[1] = am.GetElementWithName("moveTileDown1");
        _downFrameElements[2] = am.GetElementWithName("moveTileDown2");
        _downFrameElements[3] = am.GetElementWithName("moveTileDown3");

        _placedAt = 0.0f;

        int randomDirection = RXRandom.Range(0, 4);
        this.direction = VectorDirection.Up; // (VectorDirection)randomDirection;

        if (randomDirection == 1){
            this.direction = VectorDirection.Left;
            this.element = _leftFrameElements[0];
        } else if (randomDirection == 2){
            this.direction = VectorDirection.Right;
            this.element = _rightFrameElements[0];
        } else if (randomDirection == 3){
            this.direction = VectorDirection.Down;
            this.element = _downFrameElements[0];
        }

        ListenForUpdate(HandleUpdate);
    }
Exemplo n.º 20
0
    void OnEnable()
    {
        if (objectToAnimate == null)
        {
            objectToAnimate = transform;
        }

        // The target position will be the original transform's position
        targetPosition = objectToAnimate.transform.position;

        // This will be the position where the object will appear from
        Vector3 fromPosition = targetPosition + (VectorDirection.DetermineDirection(directionToAnimateFrom) * animationScale);

        // Position the transform at the updated position
        objectToAnimate.transform.position = fromPosition;

        // Animate based on the chosen option
        switch (typeOfAnimation)
        {
        case AnimationTypes.FadeIn:
            StartCoroutine(FadeIn());
            break;

        case AnimationTypes.Rotate:
//				StartCoroutine(Rotate());
            break;

        case AnimationTypes.FadeOut:
            StartCoroutine(FadeOut());
            break;

        case AnimationTypes.ZoomIn:
            StartCoroutine(ZoomIn());
            break;

        case AnimationTypes.ZoomOut:
            StartCoroutine(ZoomOut());
            break;

        case AnimationTypes.FadeZoomIn:
            StartCoroutine(FadeZoomIn());
            break;

        default:
            break;
        }
    }
Exemplo n.º 21
0
    public Crew()
        : base("walkRight0")
    {
        this.defaultVelocity = 100;
        this.currentVelocity = this.defaultVelocity;

        int randomDirection = RXRandom.Range(0, 4);
        this.direction = VectorDirection.Up; // (VectorDirection)randomDirection;

        if (randomDirection == 1){
            this.direction = VectorDirection.Left;
        } else if (randomDirection == 2){
            this.direction = VectorDirection.Right;
        } else if (randomDirection == 3){
            this.direction = VectorDirection.Down;
        }

        _leftFrameElements = new FAtlasElement[4];
        _rightFrameElements = new FAtlasElement[4];
        _upFrameElements = new FAtlasElement[4];
        _downFrameElements = new FAtlasElement[4];

        FAtlasManager am = Futile.atlasManager;

        _rightFrameElements[0] = am.GetElementWithName("walkRight0");
        _rightFrameElements[1] = am.GetElementWithName("walkRight1");
        _rightFrameElements[2] = am.GetElementWithName("walkRight2");
        _rightFrameElements[3] = am.GetElementWithName("walkRight3");

        _leftFrameElements[0] = am.GetElementWithName("walkLeft0");
        _leftFrameElements[1] = am.GetElementWithName("walkLeft1");
        _leftFrameElements[2] = am.GetElementWithName("walkLeft2");
        _leftFrameElements[3] = am.GetElementWithName("walkLeft3");

        _upFrameElements[0] = am.GetElementWithName("walkUp0");
        _upFrameElements[1] = am.GetElementWithName("walkUp1");
        _upFrameElements[2] = am.GetElementWithName("walkUp2");
        _upFrameElements[3] = am.GetElementWithName("walkUp3");

        _downFrameElements[0] = am.GetElementWithName("walkDown0");
        _downFrameElements[1] = am.GetElementWithName("walkDown1");
        _downFrameElements[2] = am.GetElementWithName("walkDown2");
        _downFrameElements[3] = am.GetElementWithName("walkDown3");

        ListenForUpdate(HandleUpdate);
    }
Exemplo n.º 22
0
 public VectorMatch(VectorMatch vm, int arg, int start, int count, VectorDirection dir)
 {
     Offset = vm.Offset + 4 * start;;
     Reg    = vm.Reg;
     Start  = start + vm.Start;
     Count  = count;
     Upward = vm.Upward;
     calc   = vm.calc;
     if (dir == VectorDirection.Unknown)
     {
         throw new OptimizationException("VectorMatch: Unknown vector direction");
     }
     fpulines = new int[Count][];
     for (int i = Start; i < count + Start; i++)
     {
         fpulines[i - Start] = ((UnwrappedElement)vectorizer.elements[i]).FpuLines;
     }
     arguments = new Element[count][];
     Array.Copy(vm.arguments, start, arguments, 0, count);
     if (vm.pArguments != null)
     {
         pArguments = new Vector[vm.pArguments.Length + 1];
         vm.pArguments.CopyTo(pArguments, 0);
         for (int i = 0; i < vm.pArguments.Length - 1; i++)
         {
             pArguments[i].Count = count;
             if (start > 0)
             {
                 if (pArguments[i].Direction == VectorDirection.Up)
                 {
                     pArguments[i].Offset += 4 * start;
                 }
                 else if (pArguments[i].Direction == VectorDirection.Down)
                 {
                     pArguments[i].Offset -= 4 * start;
                 }
             }
         }
     }
     else
     {
         pArguments = new Vector[1];
     }
     pArguments[arg] = new Vector(arguments[0][arg].Offset, arguments[0][arg].Register, count, dir);
 }
Exemplo n.º 23
0
    private void HandleMovingInput()
    {
        VectorDirection[] directions = new VectorDirection[2];
        directions[0] = VectorDirection.None;
        var index = 0;

        if (Input.GetKey(KeyCode.D))
        {
            directions[index] = VectorDirection.Right;
            index++;
        }
        else if (Input.GetKey(KeyCode.A))
        {
            directions[index] = VectorDirection.Left;
            index++;
        }

        if (Input.GetKey(KeyCode.W))
        {
            directions[index] = VectorDirection.Up;
            index++;
        }
        else if (Input.GetKey(KeyCode.S))
        {
            directions[index] = VectorDirection.Down;
            index++;
        }

        for (var i = 0; i < directions.Length; i++)
        {
            if (directions[i] != VectorDirection.Invalid)
            {
                OnMovingInput(directions[i]);
            }
        }

        foreach (KeyValuePair <KeyCode, KeyAction> subscribedKey in _subscribedKeys)
        {
            if (Input.GetKeyUp(subscribedKey.Key))
            {
                subscribedKey.Value();
            }
        }
    }
Exemplo n.º 24
0
        /// <summary>
        /// Removes a row or column vector in a matrix
        /// </summary>
        /// <param name="mat">The matrix</param>
        /// <param name="direction">The type of vector to remove (row or column)</param>
        /// <param name="removeIndex">The vector index to remove at</param>
        /// <returns>The matrix with an removed row/column at the specified index</returns>
        public static T[,] RemoveVector <T>(this T[,] mat, VectorDirection direction, int removeIndex)
        {
            MatrixDimensions d = mat.GetDimensions();

            T[,] newMat;
            if (direction == VectorDirection.Column)
            {
                if (removeIndex > d.cols || removeIndex < 1)
                {
                    throw new IndexOutOfRangeException("That column index does not exist in the matrix.");
                }
                newMat = new T[d.rows, d.cols - 1];
                return(newMat.Apply((v, r, c) => {
                    if (c < removeIndex)
                    {
                        return mat[r - 1, c - 1];
                    }
                    else
                    {
                        return mat[r - 1, c];
                    }
                }));
            }
            else
            {
                if (removeIndex > d.rows || removeIndex < 1)
                {
                    throw new IndexOutOfRangeException("That row index does not exist in the matrix.");
                }
                newMat = new T[d.rows - 1, d.cols];
                return(newMat.Apply((v, r, c) => {
                    if (r < removeIndex)
                    {
                        return mat[r - 1, c - 1];
                    }
                    else
                    {
                        return mat[r, c - 1];
                    }
                }));
            }
        }
Exemplo n.º 25
0
 /// <summary>
 /// Converts a vector to a single-row/column matrix
 /// </summary>
 /// <param name="vector">The vector</param>
 /// <param name="shape">The resulting shape of the matrix (either horizontal or vertical)</param>
 /// <returns>The single-row/column matrix derived from the vector</returns>
 public static T[,] ExpandToMatrix <T>(this T[] vector, VectorDirection shape = VectorDirection.Vertical)
 {
     T[,] mat;
     if (shape == VectorDirection.Horizontal)
     {
         mat = new T[1, vector.Length];
         for (int i = 0; i < vector.Length; i++)
         {
             mat[0, i] = vector[i];
         }
     }
     else
     {
         mat = new T[vector.Length, 1];
         for (int i = 0; i < vector.Length; i++)
         {
             mat[i, 0] = vector[i];
         }
     }
     return(mat);
 }
Exemplo n.º 26
0
    public void Awake()
    {
        State = new MovementState();

        //better to store transforms and references if we will call them often
        _transform   = transform;
        _localScale  = transform.localScale;
        _boxCollider = GetComponent <BoxCollider2D> ();

        // size of a collider multiplied by his scale, minus skinWidth in the corners
        var colliderWidth = _boxCollider.size.x * Mathf.Abs(transform.localScale.x) - (2 * SkinWidth);

        //calculated box colllider width divided by needed pieces(for 3 rays - 2 pieces)
        _horizontalDistanceBetweenRays = colliderWidth / (TotalVerticalRays - 1);

        var colliderHeight = _boxCollider.size.y * Mathf.Abs(transform.localScale.y) - (2 * SkinWidth);

        _verticalDistanceBetweenRays = colliderHeight / (TotalHorizontalRays - 1);

        _isFacingForward = transform.localScale.x > 0;
        _forwardVector   = VectorDirection.Right;
    }
Exemplo n.º 27
0
    private bool HandleWall(ref Vector2 deltaMovement, float angle, bool isGoingRight)
    {
        var sign = isGoingRight ? 1 : -1;

        transform.Rotate(0, 0, sign * angle);
        if (transform.eulerAngles.z < 90)
        {
            _forwardVector = VectorDirection.Right;
        }
        else if (transform.eulerAngles.z < 180)
        {
            _forwardVector = VectorDirection.Down;
        }
        else if (transform.eulerAngles.z < 270)
        {
            _forwardVector = VectorDirection.Left;
        }
        else if (transform.eulerAngles.z < 360)
        {
            _forwardVector = VectorDirection.Up;
        }
        return(true);
    }
 public Vector3 GetDirectionVector3(VectorDirection direction)
 {
     switch (direction)
     {
         // Gets the direction of the two vector points
         
         case VectorDirection.AToB:
         {
             var dx = _a.x - _b.x;
             var dy = _a.y - _b.y;
             var dz = _a.z - _b.z;
             return  new Vector3(dx,dy,dz);
         }
         case VectorDirection.BToA:
         {
             var dx = _b.x - _a.x;
             var dy = _b.y - _a.y;
             var dz = _b.z - _a.z;
             return  new Vector3(dx,dy,dz);
         }
         default:
             throw new Exception();
     }
 }
Exemplo n.º 29
0
 public RegisterState(VectorDirection vd,byte b)
 {
     occupied=true;
     direction=vd;
     contains=b;
 }
Exemplo n.º 30
0
        private static VectorMatch[] ProcessSplit(VectorMatch vm, int arg)
        {
            int             Offset         = -1;
            int             ExpectedOffset = -1;
            string          Reg            = "";
            int             VectorStart    = 0;
            VectorDirection dir            = VectorDirection.Unknown;
            ArrayList       matches        = new ArrayList();

            for (int i = 0; i < vm.arguments.Length; i++)
            {
                if (i == 0 || Offset == -1)
                {
                    Offset      = vm.arguments[i][arg].Offset;
                    Reg         = vm.arguments[i][arg].Register;
                    VectorStart = i;
                }
                else if (ExpectedOffset == -1)
                {
                    if (vm.arguments[i][arg].Register == Reg && vm.arguments[i][arg].Offset == Offset + 4)
                    {
                        ExpectedOffset = vm.arguments[i][arg].Offset + 4;
                        dir            = VectorDirection.Up;
                    }
                    else if (vm.arguments[i][arg].Register == Reg && vm.arguments[i][arg].Offset == Offset - 4)
                    {
                        ExpectedOffset = vm.arguments[i][arg].Offset - 4;
                        dir            = VectorDirection.Down;
                    }
                    else if (vm.arguments[i][arg].Register == Reg && vm.arguments[i][arg].Offset == Offset)
                    {
                        ExpectedOffset = vm.arguments[i][arg].Offset;
                        dir            = VectorDirection.Static;
                    }
                    else
                    {
                        Offset         = vm.arguments[i][arg].Offset;
                        VectorStart    = i;
                        Reg            = vm.arguments[i][arg].Register;
                        ExpectedOffset = -1;
                    }
                }
                else
                {
                    if ((!(i - VectorStart == 4)) && vm.arguments[i][arg].Register == Reg && ExpectedOffset == vm.arguments[i][arg].Offset)
                    {
                        if (dir == VectorDirection.Up)
                        {
                            ExpectedOffset += 4;
                        }
                        else if (dir == VectorDirection.Down)
                        {
                            ExpectedOffset -= 4;
                        }
                    }
                    else
                    {
                        matches.Add(new VectorMatch(vm, arg, VectorStart, i - VectorStart, dir));
                        Offset         = vm.arguments[i][arg].Offset;
                        VectorStart    = i;
                        Reg            = vm.arguments[i][arg].Register;
                        ExpectedOffset = -1;
                    }
                }
            }
            if (Offset != -1 && ExpectedOffset != -1)
            {
                matches.Add(new VectorMatch(vm, arg, VectorStart, vm.arguments.Length - VectorStart, dir));
            }
            return((VectorMatch[])matches.ToArray(typeof(VectorMatch)));
        }
Exemplo n.º 31
0
 /// <summary>
 /// Load vector
 /// </summary>
 /// <param name="value">Value of the load</param>
 /// <param name="direction">Direction by (X,Y or Z)</param>
 public LoadVector(double value, VectorDirection direction)
 {
     Value     = value;
     Direction = direction;
 }
Exemplo n.º 32
0
 private bool HandleWall(ref Vector2 deltaMovement, float angle, bool isGoingRight)
 {
     var sign = isGoingRight ? 1 : -1;
     transform.Rotate (0, 0, sign * angle);
     if (transform.eulerAngles.z < 90 )
     {
         _forwardVector = VectorDirection.Right;
     }
     else if (transform.eulerAngles.z < 180 )
     {
         _forwardVector = VectorDirection.Down;
     }
     else if (transform.eulerAngles.z < 270 )
     {
         _forwardVector = VectorDirection.Left;
     }
     else if (transform.eulerAngles.z < 360 )
     {
         _forwardVector = VectorDirection.Up;
     }
     return true;
 }
Exemplo n.º 33
0
 /// <summary>
 /// Returns the number of rows/cols in the specified direction
 /// </summary>
 /// <param name="direction">The direction</param>
 /// <returns>The number of rows/cols in the specified direction</returns>
 public int InDirection(VectorDirection direction)
 {
     return(direction == VectorDirection.Row ? cols : rows);
 }
Exemplo n.º 34
0
 protected virtual void OnPlayerInput(VectorDirection direction)
 {
     if (State.MovingMode != MoveMode.Snapping &&
         _isMovingEnabled != false &&
         (
         (direction == VectorDirection.Right && !_isFacingForward) ||
         (direction == VectorDirection.Left && _isFacingForward)
         ))
     {
         Flip();
     }
     _direction = direction;
 }
Exemplo n.º 35
0
    protected void HandleUpdate()
    {
        float dt = Time.deltaTime;

        if (Main.GameTime - _lastCycle > 10)
        {
            // spawn some new crew every 10 seconds
            spawnInventory();
            //if(_crewSpawned < 20){
            if (_crewMembers.Count < 10)              // keep spawning crew so long as there arae not more than 10 currently out
            {
                spawnCrew(3);
            }
            _levelManager.scrambleDoors();

            int totalMeltdownSegments = 20;
            //  use 20 for shorter game play (about 3.3 minutes)
            //  use 32 for shorter game play (about 5.3 minutes)
            if (_meltdownSegmentCount < totalMeltdownSegments)
            {
                float segmentWidth = 640 / totalMeltdownSegments;

                // draw another segment on the meltdown timer
                FSprite meltdownSegment = new FSprite("meltdownSegment");
                meltdownSegment.width = segmentWidth;
                // calculate position
                float x = Futile.screen.halfWidth - (meltdownBar.width / 2) + 4 + (segmentWidth / 2);                 // 4 is to get the spacing right
                x += _meltdownSegmentCount * segmentWidth;
                meltdownSegment.SetPosition(x, 672);
                AddChild(meltdownSegment);
                _meltdownSegmentCount++;
            }
            else
            {
                GameOver();
            }

            _lastCycle = Main.GameTime;
        }

        // handle input
        bool invKeyPressed = false;

        if (Input.GetKeyDown(KeyCode.Alpha1))
        {
            invKeyPressed   = true;
            _invNumSelected = 0;
        }
        else if (Input.GetKeyDown(KeyCode.Alpha2))
        {
            invKeyPressed   = true;
            _invNumSelected = 1;
        }
        else if (Input.GetKeyDown(KeyCode.Alpha3))
        {
            invKeyPressed   = true;
            _invNumSelected = 2;
        }
        else if (Input.GetKeyDown(KeyCode.Alpha4))
        {
            invKeyPressed   = true;
            _invNumSelected = 3;
        }
        else if (Input.GetKeyDown(KeyCode.Escape))
        {
            invKeyPressed               = false;
            _invNumSelected             = -1;
            selectedInventory.isVisible = false;
        }

        if (invKeyPressed)
        {
            // so the user selected a valid inventory slot,
            // now make sure there is something in that slot
            if (_inventory[_invNumSelected] != null)
            {
                selectedInventory.SetPosition(positionForInventory(_invNumSelected));
                selectedInventory.isVisible = true;
            }
            else
            {
                // they clicked on an empty inventory
                _invNumSelected = -1;
            }
        }

        // update crew member's movement direction
        //loop backwards so if we remove a crew member from the list, it won't cause problems
        for (int i = _crewMembers.Count - 1; i >= 0; i--)
        {
            Crew            crewMember       = _crewMembers[i];
            VectorDirection currentDirection = crewMember.direction;
            Vector2         newCrewPosition  = crewMember.calculateNewPosition(dt);
            if (!_levelManager.crewMemberIsPassingThruDoor(crewMember))              // passing through a door takes precidence
            {
                if (_levelManager.willObeyFloorTile(crewMember, newCrewPosition))
                {
                }
                else if (_levelManager.willDirectCrewToDoor(crewMember))                     // check if crew member is next to an open door, if so they will be directed to it
                {
                    if (crewMember.direction != currentDirection)
                    {
                        // direction was updated, don't adjust position
                        newCrewPosition = crewMember.GetPosition();
                    }
                }
                else if (!_levelManager.checkCrewHeadingOk(crewMember, newCrewPosition))
                {
                    // crew member heading into a wall, so heading was adjusted, don't update position
                    newCrewPosition = crewMember.GetPosition();
                }
            }
            // update crew member's position (having taken into account all previous checks)
            crewMember.SetPosition(newCrewPosition);

            // check if crew member is in the escape pod room
            int escapePodXMax = (64 * 7) - 32;
            int escapePodYMax = (64 * 3) - 32;
            if (newCrewPosition.x <= escapePodXMax && newCrewPosition.y <= escapePodYMax)
            {
                // you saved this crew member!
                FSoundManager.PlaySound("crewSaved1", 0.5f);
                Main.instance.crewSaved++;
                crewSavedLabel.text = "Crew Members Saved: " + Main.instance.crewSaved;

                _crewMembers.Remove(crewMember);
                crewMember.shouldDestroy = true;
            }
        }
    }
Exemplo n.º 36
0
 public ComputationResult(SparseArray <float> data, bool accumulator, VectorDirection direction = VectorDirection.Unassigned)
 {
     VectorData  = data;
     Accumulator = accumulator;
     Direction   = direction;
 }
Exemplo n.º 37
0
 public void ChangeDirection(VectorDirection direction)
 {
     this.direction = direction;
     // reset out animation frame counter
     _frameIndex = 0;
     _directionChanged = true;
 }
Exemplo n.º 38
0
 public Vector(int offset,string reg,int count,VectorDirection dir)
 {
     Offset=offset;
     Register=reg;
     Count=count;
     Direction=dir; ;
 }
Exemplo n.º 39
0
    protected override void OnPlayerInput(VectorDirection direction)
    {
        if (State.MovingMode != MoveMode.Snapping &&
            _isMovingEnabled != false)
        {

            if (direction == VectorDirection.Up)
            {
                if (CanJump)
                {
                    Jump();
                    SetAniamation("idle", true);

                }
                else if (CanReduceGravity)
                {
                    gravity.ReduceGravity();
                    SetAniamation("fly", true);
                }
                return;
            }

            if ((direction == VectorDirection.Right && !_isFacingForward) ||
                (direction == VectorDirection.Left && _isFacingForward))
            {
                Flip();
            }

        }
        _direction = direction;
    }
Exemplo n.º 40
0
 public VectorMatch(VectorMatch vm,int arg,int start,int count,VectorDirection dir)
 {
     Offset=vm.Offset+4*start; ;
     Reg=vm.Reg;
     Start=start+vm.Start;
     Count=count;
     Upward=vm.Upward;
     calc=vm.calc;
     if(dir==VectorDirection.Unknown) throw new OptimizationException("VectorMatch: Unknown vector direction");
     fpulines=new int[Count][];
     for(int i=Start;i<count+Start;i++) {
         fpulines[i-Start]=((UnwrappedElement)vectorizer.elements[i]).FpuLines;
     }
     arguments=new Element[count][];
     Array.Copy(vm.arguments,start,arguments,0,count);
     if(vm.pArguments!=null) {
         pArguments=new Vector[vm.pArguments.Length+1];
         vm.pArguments.CopyTo(pArguments,0);
         for(int i=0;i<vm.pArguments.Length-1;i++) {
             pArguments[i].Count=count;
             if(start>0) {
                 if(pArguments[i].Direction==VectorDirection.Up) {
                     pArguments[i].Offset+=4*start;
                 } else if(pArguments[i].Direction==VectorDirection.Down) {
                     pArguments[i].Offset-=4*start;
                 }
             }
         }
     } else {
         pArguments=new Vector[1];
     }
     pArguments[arg]=new Vector(arguments[0][arg].Offset,arguments[0][arg].Register,count,dir);
 }
Exemplo n.º 41
0
    public void Awake()
    {
        State = new MovementState ();

        //better to store transforms and references if we will call them often
        _transform = transform;
        _localScale = transform.localScale;
        _boxCollider = GetComponent<BoxCollider2D> ();

        // size of a collider multiplied by his scale, minus skinWidth in the corners
        var colliderWidth = _boxCollider.size.x * Mathf.Abs (transform.localScale.x) - (2 * SkinWidth);
        //calculated box colllider width divided by needed pieces(for 3 rays - 2 pieces)
        _horizontalDistanceBetweenRays = colliderWidth / (TotalVerticalRays - 1 );

        var colliderHeight = _boxCollider.size.y * Mathf.Abs (transform.localScale.y) - (2 * SkinWidth);
        _verticalDistanceBetweenRays = colliderHeight / (TotalHorizontalRays - 1);

        _isFacingForward = transform.localScale.x > 0;
        _forwardVector = VectorDirection.Right;
    }
Exemplo n.º 42
0
    private void HandleMovingInput()
    {
        VectorDirection[] directions = new VectorDirection[2];
        directions[0] = VectorDirection.None;
        var index = 0;

        if (Input.GetKey (KeyCode.D))
        {
            directions[index] = VectorDirection.Right;
            index ++;
        }
        else if (Input.GetKey (KeyCode.A))
        {
            directions[index] = VectorDirection.Left;
            index ++;
        }

        if (Input.GetKey (KeyCode.W))
        {
            directions[index] = VectorDirection.Up;
            index ++;
        }
        else if (Input.GetKey (KeyCode.S))
        {
            directions[index] = VectorDirection.Down;
            index ++;
        }

        for (var i = 0; i < directions.Length; i++)
        {
            if (directions[i] != VectorDirection.Invalid)
            {
                OnMovingInput(directions[i]);
            }
        }

        foreach(KeyValuePair<KeyCode, KeyAction> subscribedKey in _subscribedKeys )
        {
            if (Input.GetKeyUp (subscribedKey.Key))
            {
                subscribedKey.Value();
            }
        }
    }