Skip to content

Instantly share code, notes, and snippets.

@shohan4556
Created December 5, 2021 12:25
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save shohan4556/6f2a03bbd12efded7f1ea228161781a0 to your computer and use it in GitHub Desktop.
Save shohan4556/6f2a03bbd12efded7f1ea228161781a0 to your computer and use it in GitHub Desktop.
check overlap without physics
const position = getRelativePositionToParcel(parcel, worldPosition);
console.log('relativePosition', position);
if (parcel && !isOverlap(parcel, position)) {
}
function getRelativePositionToParcel({ bounds }, pxPosition) {
// Return position top_left position in InstallationGrid
return {
x: (pxPosition.x - bounds.x) / GOTCHI,
y: (pxPosition.y - bounds.y) / GOTCHI,
};
}
function isOverlap({ grid }: Parcel, relativePosition: Vector2): boolean {
let isOverlap = false;
if (grid !== undefined) {
for (let y = relativePosition.y; y < relativePosition.y + selectedInstallation.height; y++) {
for (let x = relativePosition.x; x < relativePosition.x + selectedInstallation.width; x++) {
if (grid[y][x] !== 0) {
console.log('grid', grid[y][x]);
isOverlap = true;
break;
}
}
}
return isOverlap;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment