Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Path going straight through Towers (11111) #207

Open
JanVeb opened this issue Dec 11, 2022 · 0 comments
Open

Path going straight through Towers (11111) #207

JanVeb opened this issue Dec 11, 2022 · 0 comments

Comments

@JanVeb
Copy link

JanVeb commented Dec 11, 2022

Path going straight through TOWERS?

import { Grid, Finder, AStarFinder } from "pathfinding";

export let mapPath = [
  [0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0],
  [0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0],
  [0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0],
  [0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0],
  [0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0],
  [0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0],
  [0, 0, 0, 0, 1, 1, 1, 1, 1, 1, 1, 1, 0],
  [0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0],
  [1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 0],
  [0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0],
  [0, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1],
  [0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0],
  [0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0],
];

let start_x = 0;
let start_y = 6;
let end_x = 12;
let end_y = 6;

export let waypointsDy = [];
export function getPath() {
  var grid = new Grid(mapPath);
  var finder = new JumpPointFinder({
    allowDiagonal: true,
    dontCrossCorners: true,
  });
  waypointsDy = [];
  let path = finder.findPath(start_x, start_y, end_x, end_y, grid);
  for (let i = 0; i < path.length; i++) {
    waypointsDy[i] = {
      x: path[i][1] * 64 + 32,
      y: path[i][0] * 64 + 32,
    };
  }
}

Capture

Tried to implemet pathfinder.js in Tower defense game, though cant figure out whats wrong, you can see code im using and screen shot of path returned by pathfinder, you can see it goes straight through the towers???
Whats wrong? 1 is blocked, 0 is open, right?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant