Exemplo n.º 1
0
 public static bool DirectionsOnSameSide(TileDirection directionA, TileDirection directionB)
 {
     if (directionA.X == 0)
     {
         if (directionB.X == 0)
         {
             return(true);
         }
     }
     if (directionA.X == 2)
     {
         if (directionB.X == 2)
         {
             return(true);
         }
     }
     if (directionA.Y == 0)
     {
         if (directionB.Y == 0)
         {
             return(true);
         }
     }
     if (directionA.Y == 2)
     {
         if (directionB.Y == 2)
         {
             return(true);
         }
     }
     return(false);
 }
Exemplo n.º 2
0
 public static bool DirectionsAreInLine(TileDirection directionA, TileDirection directionB)
 {
     if (directionA.X == directionB.X)
     {
         return(true);
     }
     if (directionA.Y == directionB.Y)
     {
         return(true);
     }
     return(false);
 }
Exemplo n.º 3
0
 public static void RotateDirection(TileDirection initialDirection, TileOrientation orientation, ref TileDirection resultDirection)
 {
     resultDirection = initialDirection;
     if (orientation.SwitchedAxes)
     {
         resultDirection.SwitchAxes();
     }
     if (orientation.ResultXFlip)
     {
         resultDirection.FlipX();
     }
     if (orientation.ResultYFlip)
     {
         resultDirection.FlipY();
     }
 }
Exemplo n.º 4
0
 public static bool IdenticalTileDirections(TileDirection tileOrientationA, TileDirection tileOrientationB)
 {
     return(tileOrientationA.X == tileOrientationB.X & tileOrientationA.Y == tileOrientationB.Y);
 }
Exemplo n.º 5
0
        public static clsTerrain.Tile.sTexture OrientateTile(ref TileOrientationChance tileChance, TileDirection newDirection)
        {
            var returnResult = new clsTerrain.Tile.sTexture();

            //use random for empty tiles
            if (tileChance.TextureNum < 0)
            {
                returnResult.Orientation.ResultXFlip  = App.Random.Next() >= 0.5F;
                returnResult.Orientation.ResultYFlip  = App.Random.Next() >= 0.5F;
                returnResult.Orientation.SwitchedAxes = App.Random.Next() >= 0.5F;
                returnResult.TextureNum = -1;
                return(returnResult);
            }
            //stop invalid numbers
            if (tileChance.Direction.X > 2 | tileChance.Direction.Y > 2 | newDirection.X > 2 | newDirection.Y > 2)
            {
                Debugger.Break();
                return(returnResult);
            }
            //stop different direction types
            if ((newDirection.X == 1 ^ newDirection.Y == 1) ^ (tileChance.Direction.X == 1 ^ tileChance.Direction.Y == 1))
            {
                Debugger.Break();
                return(returnResult);
            }

            returnResult.TextureNum = tileChance.TextureNum;

            //if a direction is neutral then give a random orientation
            if ((newDirection.X == 1 & newDirection.Y == 1) || (tileChance.Direction.X == 1 & tileChance.Direction.Y == 1))
            {
                returnResult.Orientation.SwitchedAxes = App.Random.Next() >= 0.5F;
                returnResult.Orientation.ResultXFlip  = App.Random.Next() >= 0.5F;
                returnResult.Orientation.ResultYFlip  = App.Random.Next() >= 0.5F;
                return(returnResult);
            }

            bool isDiagonal = newDirection.X != 1 & newDirection.Y != 1;

            if (isDiagonal)
            {
                returnResult.Orientation.SwitchedAxes = false;
                //use flips to match the directions
                if (tileChance.Direction.X == 0 ^ newDirection.X == 0)
                {
                    returnResult.Orientation.ResultXFlip = true;
                }
                else
                {
                    returnResult.Orientation.ResultXFlip = false;
                }
                if (tileChance.Direction.Y == 0 ^ newDirection.Y == 0)
                {
                    returnResult.Orientation.ResultYFlip = true;
                }
                else
                {
                    returnResult.Orientation.ResultYFlip = false;
                }
                //randomly switch to the alternate orientation
                if (App.Random.Next() >= 0.5F)
                {
                    returnResult.Orientation.SwitchedAxes = !returnResult.Orientation.SwitchedAxes;
                    if ((newDirection.X == 0 ^ newDirection.Y == 0) ^ (returnResult.Orientation.ResultXFlip ^ returnResult.Orientation.ResultYFlip))
                    {
                        returnResult.Orientation.ResultXFlip = !returnResult.Orientation.ResultXFlip;
                        returnResult.Orientation.ResultYFlip = !returnResult.Orientation.ResultYFlip;
                    }
                }
            }
            else
            {
                //switch axes if the directions are on different axes
                returnResult.Orientation.SwitchedAxes = tileChance.Direction.X == 1 ^ newDirection.X == 1;
                //use a flip to match the directions
                if (returnResult.Orientation.SwitchedAxes)
                {
                    if (tileChance.Direction.Y != newDirection.X)
                    {
                        returnResult.Orientation.ResultXFlip = true;
                    }
                    else
                    {
                        returnResult.Orientation.ResultXFlip = false;
                    }
                    if (tileChance.Direction.X != newDirection.Y)
                    {
                        returnResult.Orientation.ResultYFlip = true;
                    }
                    else
                    {
                        returnResult.Orientation.ResultYFlip = false;
                    }
                }
                else
                {
                    if (tileChance.Direction.X != newDirection.X)
                    {
                        returnResult.Orientation.ResultXFlip = true;
                    }
                    else
                    {
                        returnResult.Orientation.ResultXFlip = false;
                    }
                    if (tileChance.Direction.Y != newDirection.Y)
                    {
                        returnResult.Orientation.ResultYFlip = true;
                    }
                    else
                    {
                        returnResult.Orientation.ResultYFlip = false;
                    }
                }
                //randomly switch to the alternate orientation
                if (App.Random.Next() >= 0.5F)
                {
                    if (newDirection.X == 1)
                    {
                        returnResult.Orientation.ResultXFlip = !returnResult.Orientation.ResultXFlip;
                    }
                    else
                    {
                        returnResult.Orientation.ResultYFlip = !returnResult.Orientation.ResultYFlip;
                    }
                }
            }

            return(returnResult);
        }