Skip to content

Instantly share code, notes, and snippets.

@eguneys
Created September 25, 2019 17:29
Show Gist options
  • Save eguneys/0fcd29c4e7845853898036c85963fe0f to your computer and use it in GitHub Desktop.
Save eguneys/0fcd29c4e7845853898036c85963fe0f to your computer and use it in GitHub Desktop.
allPos.forEach(pos => {
let key = pos2key(pos),
tile = tiles[key];
r.transform({
translate: [pos[0] * bounds.tileSize, pos[1] * bounds.tileSize]
}, () => {
if (current) {
let hitTile = r.checkBounds({
x: 0,
y: 0,
width: bounds.tileSize,
height: bounds.tileSize
}, current.epos.x, current.epos.y);
if (hitTile) {
current.tile = key;
}
}
if (drag) {
objForeach(hitTiles, (hitKey, hitDirs) => {
const hit = hitDirs.every(hitDir =>
r.checkBounds({
x: 0,
y: 0,
width: bounds.tileSize,
height: bounds.tileSize
}, drag.pos.x * bounds.pixelRatio + hitDir[0] * bounds.tileSize,
drag.pos.y * bounds.pixelRatio + hitDir[1] * bounds.tileSize)
);
if (hit) {
current.hitTiles[hitKey] = key;
}
});
}
if (tile) {
renderTile(bounds.tileSize, tile.number);
}
});
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment