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;
|
let newCoords: Coordinates;
|
||||||
const existingCoordinates = existingRevealables.map(({ area }) => ({ x: area.x, y: area.y }));
|
const existingCoordinates = existingRevealables.map(({ area }) => ({ x: area.x, y: area.y }));
|
||||||
|
|
||||||
do {
|
if (existingRevealables.length === 0) {
|
||||||
newCoords = generateRandomEdgeCoordinates();
|
return generateRandomEdgeCoordinates();
|
||||||
} while (isColliding(newCoords, existingCoordinates));
|
} else {
|
||||||
|
do {
|
||||||
|
newCoords = generateRandomEdgeCoordinates();
|
||||||
|
} while (isColliding(newCoords, existingCoordinates));
|
||||||
|
}
|
||||||
|
|
||||||
return newCoords;
|
return newCoords;
|
||||||
}
|
}
|
||||||
|
|
@ -111,34 +115,12 @@ export function generateRevealables(revealables: RevealableInterface[]): Reveala
|
||||||
area: {
|
area: {
|
||||||
x: coordinates.x,
|
x: coordinates.x,
|
||||||
y: coordinates.y,
|
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));
|
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) },
|
|
||||||
];
|
|
||||||
}*/
|
|
||||||
|
|
|
||||||
|
|
@ -26,6 +26,7 @@ export class DetailScene {
|
||||||
if (!_.isEqual(state.revealables, prevState.revealables)) {
|
if (!_.isEqual(state.revealables, prevState.revealables)) {
|
||||||
this.revealables = state.revealables;
|
this.revealables = state.revealables;
|
||||||
this.revealableObjects = generateRevealables(this.revealables);
|
this.revealableObjects = generateRevealables(this.revealables);
|
||||||
|
console.log(this.revealableObjects);
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Reference in a new issue