Created
March 19, 2020 01:47
-
-
Save m-byte918/212c9aed5810c859f7a94f2381bb8b96 to your computer and use it in GitHub Desktop.
Control cell boost direction
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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