Exemple #1
0
        public void Rotate()
        {
            if (_direction == ShapeDirection.CW270)
            {
                _direction = ShapeDirection.Normal;
            }
            else
            {
                _direction++;
            }
            bool f = true;

            while (!MoveRight())
            {
                MoveLeft();
                f = false;
            }
            if (f)
            {
                MoveLeft();
            }
            Refresh();
        }
Exemple #2
0
        public bool IsSequencesEqual()
        {
            if (expectedSequence.Length == 0)
            {
                expectedSequence = FindObsWithTag("Ideal");
            }

            if (currentSequence.Length == 0)
            {
                currentSequence = FindObsWithTag("Current");
            }

            for (int i = 0; i < expectedSequence.Length; ++i)
            {
                ShapeDirection first  = expectedSequence[i].GetComponent <Shape>().Direction;
                ShapeDirection second = currentSequence[i].GetComponentInChildren <Shape>(false).Direction;
                if (first != second)
                {
                    return(false);
                }
            }

            return(true);
        }
Exemple #3
0
 public void ChangeDirection()
 {
     _direction = _direction == ShapeDirection.Up ? ShapeDirection.Down : ShapeDirection.Up;
 }
Exemple #4
0
 public Shape(ShapeDirection direction)
 {
     _direction = direction;
 }
Exemple #5
0
 public Shape()
 {
     _direction = ShapeDirection.None;
 }
    public void generateCircle(Vector3 position, float radius, bool filledIn, ShapeDirection dir, QuantizedColor color, bool explode)
    {
        int r  = (int)radius;
        int x0 = (int)position.x;
        int y0 = (int)position.y;
        int z0 = (int)position.z;


        int x   = r;
        int y   = 0;
        int err = 0;

        //TODO: handle switches for ShapeDirection (ugh)
        while (x >= y)
        {
            drawVoxel(x0 + x, y0 + y, z0, color, explode);
            drawVoxel(x0 + y, y0 + x, z0, color, explode);
            drawVoxel(x0 - y, y0 + x, z0, color, explode);
            drawVoxel(x0 - x, y0 + y, z0, color, explode);
            drawVoxel(x0 - x, y0 - y, z0, color, explode);
            drawVoxel(x0 - y, y0 - x, z0, color, explode);
            drawVoxel(x0 + y, y0 - x, z0, color, explode);
            drawVoxel(x0 + x, y0 - y, z0, color, explode);

            if (err <= 0)
            {
                y   += 1;
                err += 2 * y + 1;
            }
            if (err > 0)
            {
                x   -= 1;
                err -= 2 * x + 1;
            }
        }

        if (filledIn)
        {
            r--;
            while (r > 0)
            {
                x   = r;
                y   = 0;
                err = 0;
                while (x >= y)
                {
                    drawVoxel(x0 + x, y0 + y, z0, color, explode);
                    drawVoxel(x0 + y, y0 + x, z0, color, explode);
                    drawVoxel(x0 - y, y0 + x, z0, color, explode);
                    drawVoxel(x0 - x, y0 + y, z0, color, explode);
                    drawVoxel(x0 - x, y0 - y, z0, color, explode);
                    drawVoxel(x0 - y, y0 - x, z0, color, explode);
                    drawVoxel(x0 + y, y0 - x, z0, color, explode);
                    drawVoxel(x0 + x, y0 - y, z0, color, explode);

                    if (err <= 0)
                    {
                        y   += 1;
                        err += 2 * y + 1;
                    }
                    if (err > 0)
                    {
                        x   -= 1;
                        err -= 2 * x + 1;
                    }
                }
                r--;
            }
        }
    }
 public void clearArrayIn2d(float[] array, uint arrayLength, Vector3 position, Vector2 size, ShapeDirection dir, ShapeFront front, ShapeOrientation orientation, bool explode)
 {
     generateArrayIn2d(array, arrayLength, position, size, dir, front, orientation, TransparentColor, explode);
 }
    public void generateArrayIn2d(float[] array, uint arrayLength, Vector3 position, Vector2 size, ShapeDirection dir, ShapeFront front, ShapeOrientation orientation, QuantizedColor color, bool explode)
    {
        int y0   = 0;
        int xMin = 0;

        int y   = 0;
        int x   = 0;
        int idx = 0;

        //plane we're drawing on:
        int pos = 0;

        //how many voxels we need for each value in the array:
        int voxelsPerValue = Mathf.FloorToInt(size.x / arrayLength);

        //if we end up getting 0, then just round up to 1.
        if (voxelsPerValue <= 0)
        {
            voxelsPerValue++;
        }

        float val = 0.0f;

        switch (dir)
        {
        case ShapeDirection.UP:
            y0   = Mathf.FloorToInt(position.x);
            xMin = Mathf.FloorToInt(position.z - size.x / 2);
            pos  = Mathf.FloorToInt(position.y);
            break;

        case ShapeDirection.FRONT:
            y0   = Mathf.FloorToInt(position.y);
            xMin = Mathf.FloorToInt(position.x - size.x / 2);
            pos  = Mathf.FloorToInt(position.z);
            break;

        case ShapeDirection.SIDE:
            y0   = Mathf.FloorToInt(position.y);
            xMin = Mathf.FloorToInt(position.z - size.x / 2);
            pos  = Mathf.FloorToInt(position.x);
            break;

        default:
            break;
        }
        y = y0;
        x = xMin;

        //draw array:
        for (idx = 0; idx < arrayLength; idx++)
        {
            //if we are rendering facing the back or left, we reverse the draw.
            if (front == ShapeFront.DOWN_BACK_OR_LEFT && (dir == ShapeDirection.FRONT || dir == ShapeDirection.SIDE))
            {
                val = array[arrayLength - idx];
            }
            else
            {
                val = array[idx];
            }

            //if we are rendering facing downwards, we just negate the array:
            if (front == ShapeFront.DOWN_BACK_OR_LEFT && dir == ShapeDirection.FRONT)
            {
                y = y0 - Mathf.FloorToInt(val * size.y);
            }
            else
            {
                y = y0 + Mathf.FloorToInt(val * size.y);
            }
            //to do: if voxels per value is more than 1, draw squares rather than single voxels
            //Debug.Log("Drawing value " + val + " at x: " + x + " y: " + y);
            if (orientation == ShapeOrientation.HORIZONTAL)
            {
                switch (dir)
                {
                case ShapeDirection.UP:
                    drawVoxel(y, pos, x, color, explode);
                    break;

                case ShapeDirection.FRONT:
                    drawVoxel(x, y, pos, color, explode);
                    break;

                case ShapeDirection.SIDE:
                    drawVoxel(pos, y, x, color, explode);
                    break;

                default:
                    break;
                }
            }
            else
            {
                switch (dir)
                {
                case ShapeDirection.UP:
                    drawVoxel(x, pos, y, color, explode);
                    break;

                case ShapeDirection.FRONT:
                    drawVoxel(y, x, pos, color, explode);
                    break;

                case ShapeDirection.SIDE:
                    drawVoxel(pos, x, y, color, explode);
                    break;

                default:
                    break;
                }
            }
            x += voxelsPerValue;
        }
    }
 public void clearRect2(Vector3 position, Vector2 size, ShapeDirection dir, bool explode)
 {
     generateRect2(position, size, dir, TransparentColor, explode);
 }
    public void generateRect2(Vector3 position, Vector2 size, ShapeDirection dir, QuantizedColor color, bool explode)
    {
        int rx = Mathf.FloorToInt(size.x) / 2;
        int ry = Mathf.FloorToInt(size.y) / 2;

        //static offset on whatever plane we're drawing on:
        int pos = 0;

        int xMin = 0;
        int yMin = 0;

        switch (dir)
        {
        case ShapeDirection.UP:
            xMin = Mathf.FloorToInt(position.x) - rx;
            yMin = Mathf.FloorToInt(position.z) - ry;
            pos  = Mathf.FloorToInt(position.y);
            break;

        case ShapeDirection.FRONT:
            xMin = Mathf.FloorToInt(position.x) - rx;
            yMin = Mathf.FloorToInt(position.y) - ry;
            pos  = Mathf.FloorToInt(position.z);
            break;

        case ShapeDirection.SIDE:
            xMin = Mathf.FloorToInt(position.z) - rx;
            yMin = Mathf.FloorToInt(position.y) - ry;
            pos  = Mathf.FloorToInt(position.x);
            break;

        default:
            break;
        }

        int xMax = xMin + rx * 2;
        int yMax = yMin + ry * 2;

        int x = xMin;
        int y = yMin;

        Debug.Log("rectangle x bounds: " + xMin + " to " + xMax + " y bounds: " + yMin + " to " + yMax);

        while (x <= xMax)
        {
            while (y <= yMax)
            {
                switch (dir)
                {
                case ShapeDirection.UP:
                    drawVoxel(x, pos, y, color, explode);
                    break;

                case ShapeDirection.FRONT:
                    drawVoxel(x, y, pos, color, explode);
                    break;

                case ShapeDirection.SIDE:
                    drawVoxel(pos, y, x, color, explode);
                    break;

                default:
                    break;
                }
                y++;
            }
            y = yMin;
            x++;
        }
    }
 public void clearCircle(Vector3 position, float radius, bool filledIn, ShapeDirection dir, bool explode)
 {
     generateCircle(position, radius, filledIn, dir, TransparentColor, explode);
 }