diff --git a/src/helpers.ts b/src/helpers.ts index 0af5290..90db507 100644 --- a/src/helpers.ts +++ b/src/helpers.ts @@ -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) }, - ]; -}*/ diff --git a/src/scenes/DetailScene.ts b/src/scenes/DetailScene.ts index b0f4b21..53bf38e 100644 --- a/src/scenes/DetailScene.ts +++ b/src/scenes/DetailScene.ts @@ -26,6 +26,7 @@ export class DetailScene { if (!_.isEqual(state.revealables, prevState.revealables)) { this.revealables = state.revealables; this.revealableObjects = generateRevealables(this.revealables); + console.log(this.revealableObjects); } }); }