Beispiel #1
0
        public static void ApplyStretch(Sprite sprite, Enum.Axis axis, int defaultX, int defaultY, float rate, int minimumSize, int maximumSize)
        {
            if (axis == Enum.Axis.Horizontal)
            {
                sprite.Width = (int)(sprite.DefaultWidth * rate);

                if (sprite.Width < minimumSize)
                {
                    sprite.Width = minimumSize;
                }
                else if (sprite.Width > maximumSize)
                {
                    sprite.Width = maximumSize;
                }

                sprite.X = defaultX - ((sprite.Width - sprite.DefaultWidth) / 2) + 1;
            }
            else if (axis == Enum.Axis.Vertical)
            {
                sprite.Height = (int)(sprite.DefaultHeight * rate);

                if (sprite.Height * rate < minimumSize)
                {
                    sprite.Height = minimumSize;
                }
                else if (sprite.Height * rate > maximumSize)
                {
                    sprite.Height = maximumSize;
                }

                sprite.Y = defaultY - (sprite.Height - sprite.DefaultHeight);
            }
        }
Beispiel #2
0
        public static void WarpSprite(Sprite sprite, Sprite stage, Enum.Axis axis)
        {
            if (sprite != null && sprite.Rectangle != null)
            {
                if (axis == Enum.Axis.Horizontal || axis == Enum.Axis.All)
                {
                    if (sprite.X > stage.Width)
                    {
                        sprite.X = 0 - sprite.Width + 1;
                    }
                    else if (sprite.X < 0 - sprite.Width)
                    {
                        sprite.X = stage.Width;
                    }
                }

                if (axis == Enum.Axis.Vertical || axis == Enum.Axis.All)
                {
                    if (sprite.Rectangle.Location.Y > stage.Height)
                    {
                        sprite.Y = 0 - sprite.Height + 1;
                    }
                    else if (sprite.Rectangle.Location.Y < 0 - sprite.Height)
                    {
                        sprite.Y = stage.Height;
                    }
                }
            }
        }
    /* DrawCut
     *
     * Generates a 3D plane in space composed of Debug.DrawLine gizmos
     *
     * parameters:
     *  int axis: -
     *  int value: axis value
     *  int p1: coordenate [X,Y,Z]
     *  int p2: coordenate [X,Y,Z]
     *  int size1: size[X,Y,Z]
     *  int size2: size[X,Y,Z]
     *  Color color: -
     */
    void DrawCut(Enum.Axis axis, int value, int p1, int p2, int size1, int size2, Color color)
    {
        int lineInterval = 5;

        if (axis == Enum.Axis.x)
        {
            //cut with an x value
            for (int i = p1; i < size1; i += lineInterval)
            {
                Debug.DrawLine(new Vector3(value, i, p2), new Vector3(value, i, size2), color, 5, false);
            }
        }
        else if (axis == Enum.Axis.y)
        {
            //cut with a y value
            for (int i = p1; i < size1; i += lineInterval)
            {
                Debug.DrawLine(new Vector3(i, value, p2), new Vector3(i, value, size2), color, 5, false);
            }
        }
        else if (axis == Enum.Axis.z)
        {
            //cut with a z value
            for (int i = p1; i < size1; i += lineInterval)
            {
                Debug.DrawLine(new Vector3(i, p2, value), new Vector3(i, size2, value), color, 5, false);
            }
        }
        else
        {
            Debug.LogError("Invalid axis number");
        }
    }
    /* CanCutInEnum.Axis
     *
     * determines if we can further cut section(Cube) in the [X,Y,Z] axis,
     *  this taking consideration in maxSection[X,Y,Z]
     *
     * parameters:
     * Cube section: section(Cube) being considered for cut
     * Enum.Axis axis: axis being determined
     *
     * return:
     *  bool: true if we can cut
     */
    bool CanCutInEnumAxis(Cube section, Enum.Axis axis)
    {
        int distance;

        if (axis == Enum.Axis.x)
        {
            distance = section.disX - section.x;
            if (distance <= maxSectionX)
            {
                return(false);
            }
        }
        else if (axis == Enum.Axis.y)
        {
            distance = section.disY - section.y;
            if (distance <= maxSectionY)
            {
                return(false);
            }
        }
        else if (axis == Enum.Axis.z)
        {
            distance = section.disZ - section.z;
            if (distance <= maxSectionZ)
            {
                return(false);
            }
        }
        else
        {
            Debug.LogError("Invalid Enum.Axis");
        }
        return(true);
    }
Beispiel #5
0
        public Vector3 FromAxis(Enum.Axis axis)
        {
            //canonical unit vectors
            switch (axis)
            {
            case Enum.Axis.X: return(new Vector3(1, 0, 0));

            case Enum.Axis.Y: return(new Vector3(0, 1, 0));

            case Enum.Axis.Z: return(new Vector3(0, 0, 1));
            }
            //should never happen?
            return(new Vector3());
        }
Beispiel #6
0
        public static void ApplyDrag(float Drag, Sprite sprite, Enum.Axis axis)
        {
            if (axis == Enum.Axis.Horizontal || axis == Enum.Axis.All)
            {
                if (sprite.HorizontalVelocity > 0)
                {
                    sprite.HorizontalVelocity -= Drag;

                    if (sprite.HorizontalVelocity < 0)
                    {
                        sprite.HorizontalVelocity = 0;
                    }
                }
                else if (sprite.HorizontalVelocity < 0)
                {
                    sprite.HorizontalVelocity += Drag;

                    if (sprite.HorizontalVelocity > 0)
                    {
                        sprite.HorizontalVelocity = 0;
                    }
                }
            }

            if (axis == Enum.Axis.Vertical || axis == Enum.Axis.All)
            {
                if (sprite.VerticalVelocity > 0)
                {
                    sprite.VerticalVelocity -= Drag;

                    if (sprite.VerticalVelocity < 0)
                    {
                        sprite.VerticalVelocity = 0;
                    }
                }
                else if (sprite.VerticalVelocity < 0)
                {
                    sprite.VerticalVelocity += Drag;

                    if (sprite.VerticalVelocity > 0)
                    {
                        sprite.VerticalVelocity = 0;
                    }
                }
            }
        }
    /* CutAxis
     * calculates random value in [X,Y,Z] axis to cut section(Cube)
     *  creating 2 sections(Cube s) and call GenerateCutRec
     *
     * parameters:
     *  Cube section: section(Cube) being considered for cut
     *  Axis axis: axis in which we are performing a cut
     *  TreeNode<Cube>: reference to BSP tree
     *
     * return:
     *  void
     */
    void CutAxis(Cube section, Enum.Axis axis, TreeNode <Cube> node)
    {
        int  value;
        Cube sectionLeft  = null;
        Cube sectionRight = null;

        if (axis == Enum.Axis.x)
        {
            value = Random.Range(section.x + minSectionX, section.disX - minSectionX);
            //DrawCut(Enum.Axis.x, value, section.y, section.z, section.disY, section.disZ, Color.red);

            sectionLeft  = new Cube(section.x, section.y, section.z, value, section.disY, section.disZ);
            sectionRight = new Cube(value, section.y, section.z, section.disX, section.disY, section.disZ);
        }
        else if (axis == Enum.Axis.y)
        {
            value = Random.Range(section.y + minSectionY, section.disY - minSectionY);
            //DrawCut(Enum.Axis.y, value, section.x, section.z, section.disX, section.disZ, Color.green);

            sectionLeft  = new Cube(section.x, section.y, section.z, section.disX, value, section.disZ);
            sectionRight = new Cube(section.x, value, section.z, section.disX, section.disY, section.disZ);
        }
        else if (axis == Enum.Axis.z)
        {
            value = Random.Range(section.z + minSectionZ, section.disZ - minSectionZ);
            //DrawCut(Enum.Axis.z, value, section.x, section.y, section.disX, section.disY, Color.blue);

            sectionLeft  = new Cube(section.x, section.y, section.z, section.disX, section.disY, value);
            sectionRight = new Cube(section.x, section.y, value, section.disX, section.disY, section.disZ);
        }
        else
        {
            Debug.LogError("Invalid axis number repesentation");
        }

        node.AddLeft(sectionLeft);
        node.AddRight(sectionRight);
        GenerateCutRec(sectionLeft, node.LeftNode);
        GenerateCutRec(sectionRight, node.RightNode);
    }
Beispiel #8
0
        public static void TeleportSprite(Sprite sprite, System.Windows.Forms.Panel stage, Enum.Axis axis)
        {
            if (sprite != null && sprite.PictureBoxMain != null)
            {
                if (axis == Enum.Axis.Horizontal || axis == Enum.Axis.All)
                {
                    if (sprite.X > stage.Width)
                    {
                        sprite.X = 0 - sprite.PictureBoxMain.Width + 1;
                    }
                    else if (sprite.X < 0 - sprite.PictureBoxMain.Width)
                    {
                        sprite.X = stage.Width;
                    }
                }

                if (axis == Enum.Axis.Vertical || axis == Enum.Axis.All)
                {
                    if (sprite.PictureBoxMain.Location.Y > stage.Height)
                    {
                        sprite.Y = 0 - sprite.PictureBoxMain.Height + 1;
                    }
                    else if (sprite.PictureBoxMain.Location.Y < 0 - sprite.PictureBoxMain.Height)
                    {
                        sprite.Y = stage.Height;
                    }
                }
            }
        }
Beispiel #9
0
 public static void ApplyDrag(Sprite sprite, FormStageBase stage, Enum.Axis axis)
 {
     ApplyDrag(sprite.Drag + stage.Drag, sprite, axis);
 }
Beispiel #10
0
 public static void ApplyDrag(Sprite sprite, Enum.Axis axis)
 {
     ApplyDrag(sprite.Drag, sprite, axis);
 }
    /* GenerateCutRec
     *
     * determines if it can cut a section(Cube) in either axis[x,y,z],
     *  if multiple axis can be cut, uses random.
     *
     * parameters:
     *  Cube section: section being proccesd
     *  TreeNode<Cube>: reference to BSP tree
     *
     * return:
     *  void
     *
     * recursive:
     *  calls methods for either axis being cut which
     *  each call GenerateCubeRec 2 times.
     */
    void GenerateCutRec(Cube section, TreeNode <Cube> node)
    {
        bool canCutX = CanCutInEnumAxis(section, Enum.Axis.x);
        bool canCutY = CanCutInEnumAxis(section, Enum.Axis.y);
        bool canCutZ = CanCutInEnumAxis(section, Enum.Axis.z);

        //can cut in the three dimensions?
        if (canCutX && canCutY && canCutZ)
        {
            //random pick
            Enum.Axis axis = RandomAxis();
            if (axis == Enum.Axis.x)
            {
                CutAxis(section, Enum.Axis.x, node);
            }
            else if (axis == Enum.Axis.y)
            {
                CutAxis(section, Enum.Axis.y, node);
            }
            else if (axis == Enum.Axis.z)
            {
                CutAxis(section, Enum.Axis.z, node);
            }
            else
            {
                Debug.LogError("Invalid Random Enum.Axis");
            }
        }
        else if (canCutX && canCutY)
        {
            //can cut in x and y? random pick
            if (RandomBool())
            {
                CutAxis(section, Enum.Axis.x, node);
            }
            else
            {
                CutAxis(section, Enum.Axis.y, node);
            }
        }
        else if (canCutX && canCutZ)
        {
            //can cut in x and z? random pick
            if (RandomBool())
            {
                CutAxis(section, Enum.Axis.x, node);
            }
            else
            {
                CutAxis(section, Enum.Axis.z, node);
            }
        }
        else if (canCutY && canCutZ)
        {
            //can cut in y and z? random pick
            if (RandomBool())
            {
                CutAxis(section, Enum.Axis.y, node);
            }
            else
            {
                CutAxis(section, Enum.Axis.z, node);
            }
        }//can only cut in one, do it
        else if (canCutX)
        {
            CutAxis(section, Enum.Axis.x, node);
        }
        else if (canCutY)
        {
            CutAxis(section, Enum.Axis.y, node);
        }
        else if (canCutZ)
        {
            CutAxis(section, Enum.Axis.z, node);
        }
        else
        {
            //Debug.Log("Recursive End");
        }
    }