function GenerateNewCitizen(){
x=randomIntFromInterval(1,screen_width-width);
y=randomIntFromInterval(1,screen_height-height);
resident=new People(randomIntFromInterval(0,1),1,randomIntFromInterval(1,100),professions.get(1));
graphics = new PIXI.Graphics();
graphics.beginFill(professions.get(1).color);
graphics.lineStyle(2, professions.get(1).color, 1);
graphics.beginFill(professions.get(1).color, 1);
graphics.drawCircle(0,0, 1);
graphics.position.set(x, y);
graphics.direction=randomIntFromInterval(0,360);
graphics.endFill();
graphics.resident=resident;
residents.push(graphics);
app.stage.addChild(residents[residents.length-1]);
}
/**
* Начальная генерация зданий
* @returns {undefined}
*/
function InitGenerateBuilding(){
for (let i=1;i<= buldings_types.size;i++){
cnt=buldings_types.get(i).cnt/1000*residents_count;
yet_cnt=1;
while (yet_cnt<=cnt){
// случайным образом генерируем координаты и размеры здания
width=randomIntFromInterval(20,60);
height=randomIntFromInterval(20,60);
x=randomIntFromInterval(1,screen_width-width);
y=randomIntFromInterval(1,screen_height-height);
// если наложений нет, то добавляю здание в массив
if (CheckingOverlaysRect(x,y,width,height,buldings)==false){
console.log("Добавляю "+buldings_types.get(i).name+" №"+yet_cnt);
graphics = new PIXI.Graphics();
graphics.lineStyle(2, buldings_types.get(i).color, 1);
graphics.drawRect(x, y, width, height);
buldings.push(graphics);
app.stage.addChild(buldings[buldings.length-1]);
FPSText = new PIXI.Text(buldings_types.get(i).name,new PIXI.TextStyle({fontFamily: 'Arial',fontSize: 11,}));
FPSText.x = x;
FPSText.y = y;
app.stage.addChild(FPSText);
yet_cnt++;
};
}
};
}
/**
* Проверка наложения квадратов друг на друга
* @param {type} x
* @param {type} y
* @param {type} width
* @param {type} height
* @param {type} rects
* @returns {res|Boolean}
*/
function CheckingOverlaysRect(x,y,width,height,rects){
res=false;
for (let bi=1;bi<= rects.length;bi++){
rect_height=rects[bi-1].getBounds().height;
rect_width=rects[bi-1].getBounds().width;
rect_x=rects[bi-1].getBounds().x;
rect_y=rects[bi-1].getBounds().y;
//console.log(rect_height,rect_width,rect_x,rect_y);
if ((x>=rect_x)&(x<=rect_x+rect_width)){res=true;};
if ((y>=rect_y)&(y<=rect_y+rect_height)){res=true;};
if ((x+width>=rect_x)&(x+width<=rect_x+rect_width)){res=true;};
if ((y+height>=rect_y)&(y+height<=rect_y+rect_height)){res=true;};
};
return res;
}
/**
* Начальная генерация жителей
* @returns {undefined}
*/
function InitGeneratePeoples(){
for (let i=1;i<= professions.size;i++){ //перебираем все профессии
console.log("-генерирую "+professions.get(i).name);
for (let cnt=1;cnt<= professions.get(i).pers*residents_count/100;cnt++){
x=randomIntFromInterval(1,screen_width-width);
y=randomIntFromInterval(1,screen_height-height);
resident=new People(randomIntFromInterval(0,1),randomIntFromInterval(1,100),randomIntFromInterval(1,100),professions.get(i));
graphics = new PIXI.Graphics();
graphics.beginFill(professions.get(i).color);
graphics.lineStyle(2, professions.get(i).color, 1);
graphics.beginFill(professions.get(i).color, 1);
graphics.drawCircle(0,0, 1);
graphics.position.set(x, y);
graphics.direction=randomIntFromInterval(0,360);
graphics.endFill();
graphics.resident=resident;
residents.push(graphics);
app.stage.addChild(residents[residents.length-1]);
}
}
}