Esempio n. 1
0
        public List <RectangleShape> GenerateConnection(MapManipulation mapMani)
        {
            List <RectangleShape> result  = new List <RectangleShape>();
            List <Vector2f>       posList = new List <Vector2f>();
            int horizontalDist            = Math.Abs(mapMani.position.X - lever.position.X);
            int verticalDist = Math.Abs(mapMani.position.Y - lever.position.Y);
            int curX         = 0;
            int curY         = 0;
            int xfactor      = (mapMani.position.X - lever.position.X > 0) ? 1 : -1;
            int yfactor      = (mapMani.position.Y - lever.position.Y > 0) ? 1 : -1;

            posList.Add(lever.exactPosition + new Vector2f(sizePercell * 0.5f, sizePercell * 0.5f));
            bool     horizontal = (horizontalDist > verticalDist) ? true : false;
            Vector2f target     = new Vector2f(mapMani.position.X * sizePercell + sizePercell * 0.5f, mapMani.position.Y * sizePercell + sizePercell * 0.5f);

            while (!posList[posList.Count - 1].Equals(target))
            {
                int randXDif = (horizontalDist != 0)?Rand.IntValue(1, horizontalDist): 0;
                int randYDif = (verticalDist != 0)?Rand.IntValue(1, verticalDist) : 0;
                int xDif     = (randXDif < (horizontalDist - Math.Abs(curX))) ? randXDif : (horizontalDist - Math.Abs(curX));
                int yDif     = (randYDif < (verticalDist - Math.Abs(curY))) ? randYDif : (verticalDist - Math.Abs(curY));
                if (horizontal)
                {
                    curX = curX + (xfactor * xDif);
                    posList.Add(new Vector2f(lever.position.X * sizePercell + curX * sizePercell + sizePercell * 0.5f, lever.position.Y * sizePercell + curY * sizePercell + sizePercell * 0.5f));
                }
                else
                {
                    curY = curY + (yfactor * yDif);
                    posList.Add(new Vector2f(lever.position.X * sizePercell + curX * sizePercell + sizePercell * 0.5f, lever.position.Y * sizePercell + curY * sizePercell + sizePercell * 0.5f));
                }
                horizontal = !horizontal;
            }
            for (int i = 1; i < posList.Count; i++)
            {
                result.Add(GenerateLine(posList[i - 1], posList[i], 4));
            }
            return(result);
        }
Esempio n. 2
0
 private MapManipulation(MapManipulation _mapMani)
 {
     position   = _mapMani.position;
     newContent = _mapMani.newContent;
     oldContent = _mapMani.oldContent;
 }