left click selection
This commit is contained in:
@@ -1,4 +1,34 @@
|
||||
import java.lang.Double;
|
||||
Citizen[] citizen = new Citizen[10];
|
||||
|
||||
void initCitizen(){
|
||||
//namen: ethuriel, nathaniel, loriel, samuel, aluriel, aleriel, thaliel, suriel, kaliel,
|
||||
|
||||
citizen[0] = new Citizen(59, "Test");
|
||||
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(int(random(0, houses.size())));
|
||||
}
|
||||
|
||||
selectCitizen(0);
|
||||
//citizen[2].spawn(59);
|
||||
}
|
||||
|
||||
int i_selectedCitizen;
|
||||
void selectCitizen(int i){
|
||||
citizen[i_selectedCitizen].b_selected = false;
|
||||
citizen[i].b_selected = true;
|
||||
i_selectedCitizen = i;
|
||||
}
|
||||
|
||||
class Citizen {
|
||||
int i_xSpawn, i_ySpawn, i_diameter;
|
||||
@@ -8,6 +38,8 @@ class Citizen {
|
||||
String S_name;
|
||||
float f_xPos, f_yPos;
|
||||
float f_movementSpeed = 10;
|
||||
boolean b_selected;
|
||||
|
||||
//0-100:
|
||||
//motivation (bei arbeiter montag ~40, freitag ~80 - 100)
|
||||
//7 emotionen?
|
||||
@@ -48,11 +80,8 @@ class Citizen {
|
||||
|
||||
|
||||
boolean b_moveDiagonally() {
|
||||
if (int(rNodes[nextNode].xf()) != int(f_xPos) && int(rNodes[nextNode].yf()) != int(f_yPos)) {
|
||||
return true;
|
||||
} else {
|
||||
return false;
|
||||
}
|
||||
if (int(rNodes[nextNode].xf()) != int(f_xPos) && int(rNodes[nextNode].yf()) != int(f_yPos)) return true;
|
||||
else return false;
|
||||
}
|
||||
int i_direction(float f, float v) {
|
||||
if (f <= 0-v) return -1;
|
||||
@@ -100,12 +129,15 @@ class Citizen {
|
||||
}
|
||||
if (b_drawPathDestination) {
|
||||
pg_map.stroke(160, 0, 0);
|
||||
pg_map.fill(255, 0, 0);
|
||||
if(b_selected) pg_map.fill(255, 0, 0);
|
||||
else pg_map.fill(0);
|
||||
pg_map.ellipse(rNodes[rNodes.length-1].xf(), rNodes[rNodes.length-1].yf(), nodeSize, nodeSize);
|
||||
}
|
||||
pg_map.popStyle();
|
||||
}
|
||||
if(b_selected) pg_map.fill(c_selectedCitizen);
|
||||
pg_map.ellipse(f_xPos, f_yPos, i_diameter, i_diameter);
|
||||
pg_map.fill(0);
|
||||
pg_map.textSize(10);
|
||||
pg_map.text(S_name, f_xPos, f_yPos-10);
|
||||
}
|
||||
|
||||
20
UI.pde
20
UI.pde
@@ -34,6 +34,15 @@ void mousePressed() {
|
||||
i_uiOffsetStartY = mouseY;
|
||||
i_initUiY = i_uiY;
|
||||
} else {
|
||||
int selectedCitizen = i_selectedCitizen;
|
||||
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
|
||||
&& i_mapViewToMap(mouseY, i_mapOffsetY)+10 >= citizen[i].f_yPos - citizen[i].i_diameter/2 && i_mapViewToMap(mouseY, i_mapOffsetY)-10 <= citizen[i].f_yPos + citizen[i].i_diameter/2) {
|
||||
selectCitizen(i);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
if (mouseButton == CENTER) {
|
||||
@@ -42,12 +51,15 @@ void mousePressed() {
|
||||
i_mapOffsetStartY = mouseY - i_mapOffsetY;
|
||||
}
|
||||
if (mouseButton == RIGHT) {
|
||||
if (b_mapZoom)
|
||||
citizen[0].goTo(constrain((mouseX-i_mapOffsetX)*2, 0, pg_map.width), constrain((mouseY-i_mapOffsetY)*2, 0, pg_map.height));
|
||||
else
|
||||
citizen[0].goTo(constrain(mouseX-i_mapOffsetX, 0, pg_map.width), constrain(mouseY-i_mapOffsetY, 0, pg_map.height));
|
||||
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;
|
||||
}
|
||||
|
||||
void mouseDragged() {
|
||||
if (b_mouseChangeMapOffset) {
|
||||
i_mapOffsetX = (mouseX - i_mapOffsetStartX);
|
||||
|
||||
41
citizen.pde
41
citizen.pde
@@ -1,5 +1,3 @@
|
||||
Citizen[] citizen = new Citizen[10];
|
||||
|
||||
//settings
|
||||
boolean b_smallerImage = false; //use a cropped, smaller version of the 1920x1080 image for faster development
|
||||
boolean b_loadSun = false; //load sun from web-api instead of local json file (local file is adressed to january 4th 2019. might implement a check that downloads today's information only once...
|
||||
@@ -9,17 +7,17 @@ boolean b_drawPathDestination = true;
|
||||
boolean b_randomRun = false;
|
||||
float f_nodeResolution = 0.2; //defines density of path-finding nodes, multiplied with resolution
|
||||
int i_pathAlgorithm = 3;
|
||||
int i_selectedCitizen = 0;
|
||||
int i_mapW, i_mapH;
|
||||
int i_windowW, i_windowH;
|
||||
int i_viewportW, i_viewportH;
|
||||
color c_selectedCitizen = color(128, 50, 50);
|
||||
//void mousePressed() {
|
||||
// citizen[0].goTo(constrain(mouseX, 0, img_houses.width), constrain(mouseY, 0, img_houses.height));
|
||||
//}
|
||||
|
||||
|
||||
void setup() {
|
||||
size(700,600);
|
||||
size(700, 600);
|
||||
//blendMode(MULTIPLY);
|
||||
i_windowW = width;
|
||||
i_windowH = height;
|
||||
@@ -40,33 +38,8 @@ void setup() {
|
||||
initWeather();
|
||||
initCitizen();
|
||||
initUI();
|
||||
|
||||
}
|
||||
|
||||
|
||||
void initCitizen(){
|
||||
|
||||
|
||||
//namen: ethuriel, nathaniel, loriel, samuel, aluriel, aleriel, thaliel, suriel, kaliel,
|
||||
|
||||
citizen[0] = new Citizen(59, "Test");
|
||||
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(int(random(0, houses.size())));
|
||||
}
|
||||
//citizen[2].spawn(59);
|
||||
}
|
||||
|
||||
|
||||
void pre() {
|
||||
if (i_windowW != width || i_windowH != height) {
|
||||
// Sketch window has resized
|
||||
@@ -82,12 +55,12 @@ void draw() {
|
||||
|
||||
pg_map.beginDraw();
|
||||
|
||||
pg_map.fill(0);
|
||||
pg_map.image(img_houses, 0,0, img_houses.width, img_houses.height);
|
||||
pg_map.image(img_houses, 0, 0, img_houses.width, img_houses.height);
|
||||
//image(img_streets, 0, 0, img_houses.width, img_houses.height);
|
||||
|
||||
pg_map.textSize(7);
|
||||
pg_map.textAlign(CENTER);
|
||||
pg_map.fill(0);
|
||||
//pg_map.textSize(7);
|
||||
//pg_map.textAlign(CENTER);
|
||||
//for (House house : houses) {
|
||||
// house.display();
|
||||
//}
|
||||
@@ -97,9 +70,11 @@ void draw() {
|
||||
for (int i = 0; i < citizen.length; i++) {
|
||||
if (citizen[i].b_linked) {
|
||||
citizen[i].update();
|
||||
if (i != i_selectedCitizen)
|
||||
citizen[i].display();
|
||||
}
|
||||
}
|
||||
citizen[i_selectedCitizen].display();
|
||||
|
||||
pg_map.endDraw();
|
||||
image(pg_map, i_mapOffsetX, i_mapOffsetY, i_mapW, i_mapH);
|
||||
|
||||
Reference in New Issue
Block a user