Fix revealable positioning
This commit is contained in:
parent
67aede1195
commit
48c021228e
2 changed files with 11 additions and 28 deletions
|
|
@ -94,9 +94,13 @@ export function generateRevealableCoords(existingRevealables: Revealable[]): Coo
|
|||
let newCoords: Coordinates;
|
||||
const existingCoordinates = existingRevealables.map(({ area }) => ({ x: area.x, y: area.y }));
|
||||
|
||||
do {
|
||||
newCoords = generateRandomEdgeCoordinates();
|
||||
} while (isColliding(newCoords, existingCoordinates));
|
||||
if (existingRevealables.length === 0) {
|
||||
return generateRandomEdgeCoordinates();
|
||||
} else {
|
||||
do {
|
||||
newCoords = generateRandomEdgeCoordinates();
|
||||
} while (isColliding(newCoords, existingCoordinates));
|
||||
}
|
||||
|
||||
return newCoords;
|
||||
}
|
||||
|
|
@ -111,34 +115,12 @@ export function generateRevealables(revealables: RevealableInterface[]): Reveala
|
|||
area: {
|
||||
x: coordinates.x,
|
||||
y: coordinates.y,
|
||||
r: revealable.size < 50 ? 50 : revealable.size > 600 ? 600 : revealable.size,
|
||||
w: revealable.size < 50 ? 50 : revealable.size > 600 ? 600 : revealable.size,
|
||||
},
|
||||
});
|
||||
});
|
||||
|
||||
console.log(revObjs);
|
||||
|
||||
return revObjs.map((revObj) => new Revealable(revObj.revealable, revObj.area));
|
||||
}
|
||||
|
||||
/*export function generateRevealableCoords(revealables: RevealableInterface[]): Coordinates[] {
|
||||
let revealableCoords = [];
|
||||
|
||||
revealables.forEach(revealable => {
|
||||
const coordinates = generateEdgeCoords();
|
||||
})
|
||||
|
||||
|
||||
const areaWidth = mp5.width / 3;
|
||||
const rowHeight = mp5.height / 2;
|
||||
|
||||
// Max. 8 revealables one in each area
|
||||
return [
|
||||
{ x: mp5.random(25, areaWidth), y: mp5.random(25, rowHeight) },
|
||||
{ x: mp5.random(areaWidth, areaWidth * 2), y: mp5.random(25, rowHeight) },
|
||||
{ x: mp5.random(areaWidth * 2, areaWidth * 3), y: mp5.random(25, rowHeight) },
|
||||
{ x: mp5.random(areaWidth * 3, areaWidth * 4 - 25), y: mp5.random(25, rowHeight) },
|
||||
{ x: mp5.random(25, areaWidth), y: mp5.random(rowHeight, rowHeight * 2) },
|
||||
{ x: mp5.random(areaWidth, areaWidth * 2), y: mp5.random(rowHeight, rowHeight * 2) },
|
||||
{ x: mp5.random(areaWidth * 2, areaWidth * 3), y: mp5.random(rowHeight, rowHeight * 2) },
|
||||
{ x: mp5.random(areaWidth * 2, areaWidth * 4 - 25), y: mp5.random(rowHeight, rowHeight * 2) },
|
||||
];
|
||||
}*/
|
||||
|
|
|
|||
Reference in a new issue