Skip to content

Instantly share code, notes, and snippets.

@m-byte918
Created March 19, 2020 01:47
Show Gist options
  • Save m-byte918/212c9aed5810c859f7a94f2381bb8b96 to your computer and use it in GitHub Desktop.
Save m-byte918/212c9aed5810c859f7a94f2381bb8b96 to your computer and use it in GitHub Desktop.
Control cell boost direction
boostCell(cell) {
const d = cell.boost.d / 9 * this.handle.stepMult;
if (cell.owner !== null) {
let dx = cell.owner.router.mouseX - cell.x;
let dy = cell.owner.router.mouseY - cell.y;
let d0 = Math.sqrt(dx * dx + dy * dy);
if (d0 < 1) {
dx = 1;
dy = 0;
} else {
dx /= d0;
dy /= d0;
}
cell.boost.dx = dx;
cell.boost.dy = dy;
}
cell.x += cell.boost.dx * d;
cell.y += cell.boost.dy * d;
this.bounceCell(cell, true);
this.updateCell(cell);
if ((cell.boost.d -= d) >= 1) return true;
this.setCellAsNotBoosting(cell);
return false;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment