public static void run(String[] args)
        {
            Point a = new Point(49, 49);
            Point b = new Point(0, 0);

            Logger    log = new Logger();
            Stopwatch s   = new Stopwatch();

            log.addToLog("Initializing " + mapWidth + "x" + mapHeight + " map...");
            initMap();
            AStarMap map = new AStarMap(mapWidth, mapHeight, obstacleMap);

            log.addToLog("Generating Bresenham's Line from " + a.x + "," + a.y + " to " + b.x + "," + b.y + "...");
            s.Start();
            List <Point> line = Bresenham.getCellsOnLine(a, b);

            s.Stop();
            log.addToLog("Generation took " + s.ElapsedMilliseconds + " ms");

            String str = "";

            foreach (Point point in line)
            {
                str = str + "(" + point.x + "," + point.y + ") ";
            }
            log.addToLog("Line is:" + str);

            log.addToLog("Writing line to map...");
            log.addToLog("Printing map...");
            new PrintMap(map, line);
        }
Ejemplo n.º 2
0
        private bool lineClear(Point a, Point b)
        {
            List <Point> pointsOnLine = Bresenham.getCellsOnLine(a, b);

            foreach (Point p in pointsOnLine)
            {
                AStarCell cell = map.getCell(p.x, p.y);
                if (cell == null || cell.isObstacle())
                {
                    return(false);
                }
            }
            return(true);
        }
Ejemplo n.º 3
0
        public Point raycast(Point start, Point goal)
        {
            List <Point> pointsOnLine = Bresenham.getCellsOnLine(start, goal);

            Point hitPoint = (Point)start.Clone();

            foreach (Point p in pointsOnLine)
            {
                AStarCell cell = map.getCell(p.x, p.y);
                if (cell == null || cell.isObstacle())
                {
                    break;
                }
                else
                {
                    hitPoint = p;
                }
            }
            return(hitPoint);
        }