camera tracking, autoplay, demography files

This commit is contained in:
2019-01-15 06:25:51 +01:00
parent 9306a4be5b
commit c86e141561
5 changed files with 35071 additions and 53 deletions

View File

@@ -1,29 +1,29 @@
import java.lang.Double;
int i_citizenAmount = 1500;
int i_citizenAmount = 5;
int i_femaleCount;
Citizen[] citizen = new Citizen[i_citizenAmount];
void initCitizen() {
//namen: ethuriel, nathaniel, loriel, samuel, aluriel, aleriel, thaliel, suriel, kaliel,
int[][] claireArray = { { 00, 2 }, { 1, 3} };
for (int i = 0; i < i_citizenAmount; i++){
int gender = int(random(0,2));
if(gender == 0) i_femaleCount++;
int age = int(random(0,100));
citizen[i] = new Citizen(int(random(0,houses.size())), S_citizenNames[gender][int(random(0,S_citizenNames[gender].length))], gender, age);
//int[][] claireArray = { { 00, 2 }, { 1, 3} };
citizen[0] = new Citizen(59, "Test", 0, 26);
citizen[1] = new Citizen(121, "Matze", 1, 28);
citizen[2] = new Citizen(18, "Freddy", 1, 28);
citizen[3] = new Citizen(59, "Korbi", 1, 28);
citizen[4] = new Citizen(121, "Lotte", 1, 26);
//citizen[5] = new Citizen(18, "Reifi", 1, 26);
//citizen[6] = new Citizen(59, "Grasso", 1, 28);
//citizen[7] = new Citizen(121, "Nico", 1, 29);
//citizen[8] = new Citizen(18, "Victor", 1, 28);
//citizen[9] = new Citizen(59, "Paul", 1, 28);
for (int i = 10; i < i_citizenAmount; i++) {
int gender = int(random(0, 2));
if (gender == 0) i_femaleCount++;
int age = int(random(0, 100));
citizen[i] = new Citizen(int(random(0, houses.size())), S_citizenNames[gender][int(random(0, S_citizenNames[gender].length))], gender, age);
}
//citizen[0] = new Citizen(59, "Test", claireArray);
//citizen[1] = new Citizen(121, "Matze");
//citizen[2] = new Citizen(18, "Freddy");
//citizen[3] = new Citizen(59, "Korbi");
//citizen[4] = new Citizen(121, "Lotte");
//citizen[5] = new Citizen(18, "Reifi");
//citizen[6] = new Citizen(59, "Grasso");
//citizen[7] = new Citizen(121, "Nico");
//citizen[8] = new Citizen(18, "Victor");
//citizen[9] = new Citizen(59, "Paul");
for (int i = 0; i < citizen.length; i++) {
citizen[i].spawn(citizen[i].i_home);
@@ -34,7 +34,13 @@ void initCitizen() {
int i_selectedCitizen;
void selectCitizen(int i) {
citizen[i_selectedCitizen].b_randomRun = true;
citizen[i_selectedCitizen].b_moving = true;
citizen[i_selectedCitizen].b_selected = false;
if (!b_autoPlayAfterSelect) {
citizen[i].b_randomRun = false;
citizen[i].b_moving = false;
}
citizen[i].b_selected = true;
i_selectedCitizen = i;
}
@@ -46,12 +52,12 @@ class Citizen {
int i_home;
String S_name;
float f_xPos, f_yPos;
float f_movementSpeed = 10;
float f_movementSpeed;
boolean b_selected;
int i_gender;
String S_gender;
int i_age;
boolean b_randomRun = true;
//0-100:
//motivation (bei arbeiter montag ~40, freitag ~80 - 100)
//7 emotionen?
@@ -69,6 +75,7 @@ class Citizen {
i_age = age;
i_diameter = 15;
pathFinder = makePathFinder(gs, pathAlgorithm);
f_movementSpeed = random(0.1, 2);
}
void spawn(int house) {
@@ -97,7 +104,6 @@ class Citizen {
else if (f >= 0+v) return 1;
else return 0;
}
void update() {
if (b_moving) { //if rNodes.length > 0
if (rNodes.length > nextNode) {
@@ -122,7 +128,6 @@ class Citizen {
nextNode = 0;
if (!b_randomRun) {
//check if standing on an other citizens position
} else {
goTo(int(random(0, pg_map.width)), int(random(0, pg_map.height)));
}
@@ -200,9 +205,8 @@ class Citizen {
String[][] S_citizenNames = { { "Marie", "Mari", "Sophie", "Maria", "Sophia", "Sofia", "Emilia", "Emma", "Hannah", "Hanna", "Anna", "Luisa", "Louisa", "Mia", "Emma", "Sophia", "Sofia", "Hanna", "Hannah", "Emilia",
"Mia", "Anna", "Lina", "Mila", "Klara", "Clara", "Marie", "Lea", "Leah", "Lena", "Henri", "Luisa", "Ella", "Leni", "Sophie", "Sofie", "Marie", "Maria", "Luise", "Louise", "Sophia", "Sofia",
"Elisabeth", "Katharina", "Catharina", "Charlotte", "Johanna", "Emilia", "Anna", "Luisa", "Louisa", "Victoria", "Viktoria", "Josefine", "Josephine", "Mathilda", "Matilda", "Layla", "Leyla", "Elif", "Nur", "Amira", "Aliyah", "Amina" },
{ "Maximilian", "Alexander", "Paul", "Elias", "Ben", "Noah", "Noa", "Leon", "Léon", "Louis", "Luis", "Jonas", "Felix", "Ben", "Paul", "Noah", "Noa", "Leon", "Léon", "Jonas", "Felix",
"Elias", "Louis", "Luis", "Lukas", "Lucas", "Maximilian", "Finn", "Henry", "Emil", "Luca", "Luka", "Jakob", "Jacob", "Alexander", "Maximilian", "Elias", "Paul", "Michael", "Karl", "Carl",
"Johannes", "Nico", "Luka", "Johann", "Stefan", "Louis", "Luis", "Christian", "Kristian", "Anton", "Andreas", "David", "Mohammed", "Ali", "Malik", "Emir", "Yusuf", "Ilyas" } };
"Mia", "Anna", "Lina", "Mila", "Klara", "Clara", "Marie", "Lea", "Leah", "Lena", "Henri", "Luisa", "Ella", "Leni", "Sophie", "Sofie", "Marie", "Maria", "Luise", "Louise", "Sophia", "Sofia",
"Elisabeth", "Katharina", "Catharina", "Charlotte", "Johanna", "Emilia", "Anna", "Luisa", "Louisa", "Victoria", "Viktoria", "Josefine", "Josephine", "Mathilda", "Matilda", "Layla", "Leyla", "Elif", "Nur", "Amira", "Aliyah", "Amina" },
{ "Maximilian", "Alexander", "Paul", "Elias", "Ben", "Noah", "Noa", "Leon", "Léon", "Louis", "Luis", "Jonas", "Felix", "Ben", "Paul", "Noah", "Noa", "Leon", "Léon", "Jonas", "Felix",
"Elias", "Louis", "Luis", "Lukas", "Lucas", "Maximilian", "Finn", "Henry", "Emil", "Luca", "Luka", "Jakob", "Jacob", "Alexander", "Maximilian", "Elias", "Paul", "Michael", "Karl", "Carl",
"Johannes", "Nico", "Luka", "Johann", "Stefan", "Louis", "Luis", "Christian", "Kristian", "Anton", "Andreas", "David", "Mohammed", "Ali", "Malik", "Emir", "Yusuf", "Ilyas" } };

84
UI.pde
View File

@@ -2,7 +2,7 @@
int i_uiTransparency = 200;
void initUI() {
i_uiX = 0;
i_uiY = 520;
i_uiY = 518;
i_uiW = width;
i_uiH = height - i_uiY;
}
@@ -21,40 +21,65 @@ void drawUI() {
textAlign(LEFT);
text(String.format("%02d", hour()) + ":" + String.format("%02d", minute()) + ":" + String.format("%02d", second()), 10, 30);
//camera tracking
if (b_cameraFollow) {
if (b_mapZoom) {
i_mapOffsetX = width/2-int(citizen[i_selectedCitizen].f_xPos)/2;
i_mapOffsetY = height/2-int(citizen[i_selectedCitizen].f_yPos)/2;
} else {
i_mapOffsetX = width/2-int(citizen[i_selectedCitizen].f_xPos);
i_mapOffsetY = height/2-int(citizen[i_selectedCitizen].f_yPos);
}
}
//debug
String[] debug = {
"FPS: " + int(frameRate),
"Amount citizen: " + i_citizenAmount,
"Amount citizen: " + i_citizenAmount,
"Females: " + i_femaleCount + " Males: " + str(i_citizenAmount-i_femaleCount),
" ",
" ",
"Selected Citizen ID: " + i_selectedCitizen,
"Name: " + citizen[i_selectedCitizen].S_name,
"Gender: " + citizen[i_selectedCitizen].S_gender,
"Age: " + citizen[i_selectedCitizen].i_age,
"x: " + citizen[i_selectedCitizen].f_xPos + " y: " + citizen[i_selectedCitizen].f_yPos,
"Movement speed: " + citizen[i_selectedCitizen].f_movementSpeed,
"Velocity: ",
"Outside",
"Mood: "
"Gender: " + citizen[i_selectedCitizen].S_gender,
"Age: " + citizen[i_selectedCitizen].i_age,
"x: " + int(citizen[i_selectedCitizen].f_xPos),
"y: " + int(citizen[i_selectedCitizen].f_yPos),
"Movement speed: " + round(citizen[i_selectedCitizen].f_movementSpeed*100),
"Random Run: " + citizen[i_selectedCitizen].b_randomRun,
" ",
"Global",
" ",
"Autoplay: " + b_autoPlayAfterSelect,
"Locked Camera: " + b_cameraFollow,
//"Velocity: ",
//"Outside",
//"Mood: "
};
int ts = i_debugTextSize;
textSize(ts);
int line = 0;
int maxLinesPerColumn = i_uiH/ts;
int columnWidth = 130;
if (maxLinesPerColumn > 0) {
int requiredColumns = (debug.length/maxLinesPerColumn)+1;
for (int i = 0; i < requiredColumns; i++) {
while (((line-(maxLinesPerColumn*i)) * ts + ts)+i_uiY<height && line < debug.length) {
text(debug[line], 10+(150*i), i_uiY+(ts*((line-(maxLinesPerColumn*i))+1)));
while (((line-(maxLinesPerColumn*i)) * ts + ts-1)+i_uiY<height && line < debug.length) {
text(debug[line], 10+(columnWidth*i), i_uiY+(ts*((line-(maxLinesPerColumn*i))+1)));
line++;
}
}
//text("FPS: " + int(frameRate), 10, i_uiY + 15);
//text("Selected Citizen: " + i_selectedCitizen, 10, i_uiY + 30);
}
//buttons
fill(150, 170, 250, 80);
rect(i_uiX+i_uiW-135, i_uiY+ts/2, 120, ts, 5);
fill(0);
text("Autoplay", i_uiX+i_uiW-135, i_uiY+ts/2+ts);
fill(150, 170, 250, 80);
rect(i_uiX+i_uiW-135, i_uiY+ts/2+1.41*ts+ts/2, 120, ts, 5);
fill(0);
text("Lock Camera", i_uiX+i_uiW-135, i_uiY+ts/2+1.41*ts+ts+ts/2);
}
boolean b_mouseChangeMapOffset, b_mouseChangeUiHeight;
@@ -62,12 +87,24 @@ boolean b_hoverUI;
void mousePressed() {
if (mouseButton == LEFT) {
if (mouseX >= i_uiX && mouseX <= i_uiX+i_uiW && mouseY >= i_uiY-10 && mouseY <= i_uiY+10) {
if (mouseX >= i_uiX && mouseX <= i_uiX+i_uiW && mouseY >= i_uiY-10 && mouseY <= i_uiY+10) { //drag and drop debug window size
b_mouseChangeUiHeight = true;
i_uiOffsetStartY = mouseY;
i_initUiY = i_uiY;
} else if (mouseX >= i_uiX+i_uiW-135 && mouseX <= i_uiX+i_uiW-135+120 //autoplay button
&& mouseY >= i_uiY+i_debugTextSize/2-5 && mouseY <= i_uiY+i_debugTextSize/2+i_debugTextSize+5) {
//if (b_autoPlayAfterSelect) {
// citizen[i_selectedCitizen].b_moving = false;
// citizen[i_selectedCitizen].b_randomRun = false;
//}
citizen[i_selectedCitizen].b_moving = !citizen[i_selectedCitizen].b_moving;
citizen[i_selectedCitizen].b_randomRun = !citizen[i_selectedCitizen].b_randomRun;
b_autoPlayAfterSelect = !b_autoPlayAfterSelect;
} else if (mouseX >= i_uiX+i_uiW-135 && mouseX <= i_uiX+i_uiW-135+120 //autoplay button
&& mouseY >= i_uiY+i_debugTextSize/2+1.41*i_debugTextSize+i_debugTextSize/2-5 && mouseY <= i_uiY+i_debugTextSize/2+1.41*i_debugTextSize+i_debugTextSize/2+i_debugTextSize+5) {
b_cameraFollow = !b_cameraFollow;
} else {
int selectedCitizen = i_selectedCitizen;
int selectedCitizen = i_selectedCitizen; //leftclick select citizen
for (int i = 0; i < citizen.length; i++) {
if (selectedCitizen != i) {
if (i_mapViewToMap(mouseX, i_mapOffsetX)+10 >= citizen[i].f_xPos - citizen[i].i_diameter/2 && i_mapViewToMap(mouseX, i_mapOffsetX)-10 <= citizen[i].f_xPos + citizen[i].i_diameter/2
@@ -79,15 +116,20 @@ void mousePressed() {
}
}
if (mouseButton == CENTER) {
b_mouseChangeMapOffset = true;
i_mapOffsetStartX = mouseX - i_mapOffsetX;
i_mapOffsetStartY = mouseY - i_mapOffsetY;
if (!b_cameraFollow) {
b_mouseChangeMapOffset = true;
i_mapOffsetStartX = mouseX - i_mapOffsetX;
i_mapOffsetStartY = mouseY - i_mapOffsetY;
}
}
if (mouseButton == RIGHT) {
if (!b_autoPlayAfterSelect) {
citizen[i_selectedCitizen].b_randomRun = false;
citizen[i_selectedCitizen].b_moving = false;
}
citizen[i_selectedCitizen].goTo(constrain(i_mapViewToMap(mouseX, i_mapOffsetX), 0, pg_map.width), constrain(i_mapViewToMap(mouseY, i_mapOffsetY), 0, pg_map.height));
}
}
int i_mapViewToMap(int mouse, int offset) {
if (b_mapZoom) return (mouse-offset)*2;
else return mouse-offset;

View File

@@ -4,10 +4,11 @@ boolean b_loadSun = false; //load sun from web-api instead of local json file (l
boolean b_drawNodes = false;
boolean b_drawPathLine = false;
boolean b_drawPathDestination = true;
boolean b_randomRun = false;
boolean b_cameraFollow = true;
boolean b_autoPlayAfterSelect = false;
float f_nodeResolution = 0.2; //defines density of path-finding nodes, multiplied with resolution
int i_pathAlgorithm = 3;
int i_debugTextSize = 12;
int i_debugTextSize = 10;
int i_mapW, i_mapH;
int i_windowW, i_windowH;
int i_viewportW, i_viewportH;
@@ -78,8 +79,10 @@ void draw() {
}
}
citizen[i_selectedCitizen].display();
pg_map.endDraw();
image(pg_map, i_mapOffsetX, i_mapOffsetY, i_mapW, i_mapH);
drawUI();
}

File diff suppressed because one or more lines are too long