GithubHelp home page GithubHelp logo

jpsfindpath's Introduction

cocos create JPS寻路(跳点寻路)算法TS版本


  • 简介
+ 最近又研究了一下跳点寻路所以又来分享给大家了接口什么的没变,此外还有a星什么的也有自己翻阅哈
+ 具体原理参考 https://zhuanlan.zhihu.com/p/25093275

avatar

  • 快速使用
    private customGenerateLogicMap() {
        let mapData = AutoFindPath.formatToMapData(this.map, this.map.children[0].width);
        let autoFindPath = new AutoFindPath(mapData);
        this.autoFindPath = autoFindPath;
        //更新当前地图里所有障碍物
        for (const child of this.obstacles.children) autoFindPath.updateMap(child);
    }

    private searchPath() {
        let pos0 = cc.find('Canvas/起点');
        let pos1 = cc.find('Canvas/终点');
        let paths = this.autoFindPath.gridPositionConvertGameObjectPosition(this.autoFindPath.findGridPath(pos0, pos1, models.normal),
            cc.v2(0.5, 0.5), cc.Vec2);
        if (paths.length === 0) console.log('死路');
        for (let i = 0; i < paths.length; i++) {
            this.scheduleOnce(() => {
                pos0.runAction(cc.moveTo(0.5, paths[i]));
            }, i * 0.5);
        }
    }

    start() {
        this.customGenerateLogicMap();
        this.searchPath();
    }

avatar

avatar


  • 扩展
本项目还可以动态的添加和移除障碍物(比如建筑物被攻击后可以移动到该位置,以及在游戏过程中添加建筑),更多细节可以看核心类AutoFindPath
1. 移除障碍物的方法是
autoFindPath.removeFixObstacle(...obstacles);
1. 添加障碍物的方法是
autoFindPath.updateMap(...obstacles);

  • 结尾
有问题欢迎大家提issue

jpsfindpath's People

Contributors

microcisco avatar

Stargazers

Arnold Soteros avatar  avatar  avatar  avatar  avatar Gixiv avatar Linle avatar Xiao P avatar  avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.