Esempio n. 1
0
        private void placeRoad(Vector2 start)
        {
            RoadPiece piece = new RoadPiece();

            piece.type = 1;

            RoadPiece piece2 = new RoadPiece();

            piece.type = 1;


            Vector2 pos = start + getRoadChange(start);

            placeRoad(pos.x, pos.y, piece.getPrefab(), 0);

            pos = pos + getRoadChange(start);
            placeRoad(pos.x, pos.y, piece2.getPrefab(), 0);
        }
Esempio n. 2
0
        private RoadPiece[] makeRoadPieces(ref List <Vector2> previous)
        {
            RoadPiece[] pieces = new RoadPiece[previous.Count];
            int         index  = 0;

            foreach (Vector2 vec in previous)
            {
                pieces [index]          = new RoadPiece();
                pieces [index].Position = vec;
                index++;
            }
            int lastAction = 1;

            index = 0;
            foreach (RoadPiece current in pieces)
            {
                int nextAction = 1;
                if (index + 1 < pieces.Length)
                {
                    Vector2 diff = current.Position - pieces[index + 1].Position;
                    if (diff.Equals(left))
                    {
                        //the diffrence from left
                        nextAction = 2;
                    }
                    if (diff.Equals(up))
                    {
                        nextAction = 1;
                    }
                    if (diff.Equals(right))
                    {
                        //the diffrence from right
                        nextAction = 0;
                    }
                    if (diff.Equals(down))
                    {
                        nextAction = 3;
                    }
                }

                pieces[index++].type = calculateRoadType(lastAction, nextAction);
                switch (lastAction)
                {
                case 0:
                    current.flipFrom = Direction.LEFT;
                    break;

                case 1:
                    current.flipFrom = Direction.UP;
                    break;

                case 2:
                    current.flipFrom = Direction.RIGHT;
                    break;

                case 3:
                    current.flipFrom = Direction.BOTTOM;
                    break;
                }
                lastAction = nextAction;
            }
            return(pieces);
        }