/* // PatherQuick: main.qml // by gabriel.ufrj@gmail.com // more info at: // http://gaf.impa.br or http://www.gabrieldesign.com.br // // This file is part of PatherQuick. // // PatherQuick is free software: you can redistribute it and/or modify // it under the terms of the GNU General Public License as published by // the Free Software Foundation, either version 3 of the License, or // (at your option) any later version. // // PatherQuick is distributed in the hope that it will be useful, // but WITHOUT ANY WARRANTY; without even the implied warranty of // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the // GNU General Public License for more details. // // You should have received a copy of the GNU General Public License // along with Foobar. If not, see . */ import QtQuick 2.4 import QtQuick.Window 2.2 Window { width: 400 height: 400 visible: true AStarQuick { id: pathFinder } GridDraw { id: graphicalMap anchors.centerIn: parent width: parent.width*0.9 } Component.onCompleted: { // The original map... // 0 (Zero) - free space (Can walk on) // 1 (One ) - Wall (Can't walk on... will avoid) var theMap = [ [0,0,0,0,0,0,0], [0,1,0,0,0,0,0], [0,0,1,1,1,1,1], [0,1,1,0,0,0,0], [0,0,1,0,0,1,0], [1,0,1,1,1,1,0], [0,0,0,0,0,0,0]] // Send the map to the AStarQuick component // (there it will be sorrounded by walls... 1's) pathFinder.setMap(theMap) pathFinder.printMap(pathFinder.map) // Serch for a path from (x=3,y=1) to (x=4,y=5) pathFinder.search(3,1,3,3) // After the search is complete print the think map on the console // This shows all the browsed squares before finding the path. pathFinder.printMap(pathFinder.thinkMap) // Give me the path as a array from start to finish // this could be usefull for animating an object over the path. var thePath = pathFinder.pathArray() // No using the return value.. but it's there... // Print a map on the console with the path.. just for checking... pathFinder.printMap(pathFinder.pathMap) // Extra component for drawing the result on the window using Rectangle component... // not useful... maybe even a bit buggy.. so don't mess around with this... // just enjoy the graphics! ;) // If no path is possible.. than you will see a orange square at the start node // with a "!"... graphicalMap.drawMap(pathFinder.pathMap) } }