Хабр Курсы для всех
РЕКЛАМА
Практикум, Хекслет, SkyPro, авторские курсы — собрали всех и попросили скидки. Осталось выбрать!
while(!separated) {
let separated = true;
this.preRooms.forEach((room1) => {
let velocity = new geom.Point();
let center1 = room1.createRectangle().createCenter();
this.preRooms.forEach((room2) => {
if (room1 === room2) return;
if (!geom.Rectangle.intersect(room1.createRectangle(), room2.createRectangle())) return;
let center2 = room2.createRectangle().createCenter();
let diff = center1.clone().sub(center2);
let diffLength2 = diff.length2();
if (diffLength2 > 0) {
diff.nor();
velocity.add(diff);
}
});
if (velocity.length2() > 0) {
separated = false;
velocity.nor().mult(4);
room1._position.add(velocity);
room1.setxy(room1._position);
}
});
}
очень мало игроков захотят 3+ раз бегать по одним и тем же локациям и сражаться с одними и теми же противниками
Процедурная генерация случайных игровых подземелий