Browse Source

tons of stuff, colors, communication..

master
Victor Giers 5 years ago
parent
commit
6c9ba5347a
6 changed files with 456 additions and 169 deletions
  1. 104
    46
      CitizenClass.pde
  2. 6
    3
      Entities.pde
  3. 1
    0
      Map.pde
  4. 116
    59
      Time.pde
  5. 145
    38
      UI.pde
  6. 84
    23
      citizen.pde

+ 104
- 46
CitizenClass.pde View File

@@ -1,8 +1,7 @@
import java.lang.Double;
int i_citizenAmount = 100;
int i_selectedCitizen;
int i_femaleCount;
int i_visionTransparency;
boolean b_makeThemGo;
//je nachdem wie hoch der derzeitige fokus ist wird es schwerer, ihn abzulenken.
//intrinsischer fokus korreliert mit joy/motivation/positive erinnerung an etwas
@@ -25,7 +24,7 @@ void initCitizen() {
//namen: ethuriel, nathaniel, loriel, samuel, aluriel, aleriel, thaliel, suriel, kaliel,
//int[][] claireArray = { { 00, 2 }, { 1, 3} };

citizen[0] = new Citizen(0, 800, "Test", 0, 27);
citizen[0] = new Citizen(0, 0, "", 0, 0);
citizen[1] = new Citizen(1, 121, "Matze", 1, 28);
citizen[2] = new Citizen(2, 18, "Freddy", 1, 28);
citizen[3] = new Citizen(3, 59, "Korbi", 1, 28);
@@ -41,13 +40,14 @@ void initCitizen() {
int age = int(random(0, 100));
citizen[i] = new Citizen(i, int(random(0, houses.size())), S_citizenNames[gender][int(random(0, S_citizenNames[gender].length))], gender, age);
}
for (int i = 0; i < citizen.length; i++) {
if (i != i_selectedCitizen) //hacky to set citizen[0] to a specific place
citizen[i].spawn(citizen[i].i_home);
else citizen[i].spawn(8, 8);

//if (citizen[i].b_randomRun) citizen[i].goTo(int(random(0, pg_map.width)), int(random(0, pg_map.height)), 10); //bad
for (int i = 1; i < citizen.length; i++) {
citizen[i].spawn(citizen[i].i_home);
}
citizen[0].spawn(-500, -500);

//if (citizen[i].b_randomRun) citizen[i].goTo(int(random(0, pg_map.width)), int(random(0, pg_map.height)), 10); //bad

citizen[0].despawn();
selectCitizen(0);
}

@@ -71,15 +71,18 @@ class Citizen extends Entity {
String s_currentAction;
float f_movementSpeed;
float f_FOV = PI / 4.0;
int i_visionDistance = 120;
int i_visionDistance = 80;
int i_lookRaySteps = 10;
int i_id;


int i_perceivedCitizen = -1;
boolean b_perceivesCitizen;

boolean b_randomRun = b_autoPlay;

int i_goHomeHour, i_goHomeMinute;
int i_goOutHour, i_goOutMinute;
PVector dot = new PVector(0, 0);


@@ -105,8 +108,13 @@ class Citizen extends Entity {
rNodes = pathFinder.getRoute();
s_currentAction = "current action here";
c_color = color((int)(random(0, 255)), (int)(random(0, 255)), (int)(random(0, 255)));
c_initialColor = c_color;
c_selected = color(128, 50, 50);
c_stroke = color(255, 255, 255);
i_goHomeHour = (int)random(18, 21);
i_goHomeMinute = (int)random(0, 59);
i_goOutHour = (int)random(6, 9);
i_goOutMinute = (int)random(0, 59);

//if (b_randomRun) goTo(int(random(0, pg_map.width)), int(random(0, pg_map.height)), 10); //bad
}
@@ -125,12 +133,9 @@ class Citizen extends Entity {
}

void update() {
f_angle = v2_direction.heading();

i_collBoundX = (int)f_xPos - (i_diameter/2);
i_collBoundY = (int)f_yPos - (i_diameter/2);
i_collBoundW = i_diameter;
i_collBoundH = i_diameter;
// f_angle = v2_direction.heading(); do i need this here or is it ok in turn()?


if (b_turning) {
turn();
@@ -143,22 +148,64 @@ class Citizen extends Entity {
if (b_talking) {
talk();
}

if (i_hours == i_goHomeHour && i_minutes == i_goHomeMinute) {
b_randomRun = false;
goTo((int)houses.get(i_home).v2_center.x, (int)houses.get(i_home).v2_center.y);
}

if (i_hours == i_goOutHour && i_minutes == i_goOutMinute) { //wake
b_randomRun = true;
i_location = 1;
goTo(int(random(0, pg_map.width)), int(random(0, pg_map.height)));
}

if (i_location == 1 && b_moving == false) { //sleep
float r = red(c_color);
float g = green(c_color);
float b = blue(c_color);

float r_new = (99*r + red(c_initialColor)) / 99.6666;
float g_new = (99*g + green(c_initialColor)) / 99.6666;
float b_new = (99*b + blue(c_initialColor)) / 99.6666;

c_color = color(r_new, g_new, b_new);
}
}

void display() {
pg_map.stroke(c_stroke);

//if (b_selected) {
pg_map.stroke(150, 150, 150, i_visionTransparency);
pg_map.noFill();
//pg_map.fill(127, 127, 127, i_visionTransparency);
if (i_location == 1)
pg_map.arc(f_xPos, f_yPos, i_visionDistance*2, i_visionDistance*2, f_angle+HALF_PI*1.5, f_angle+PI/2*2.5, PIE);
//}

//pg_map.stroke(c_stroke);
pg_map.stroke(c_initialColor);
pg_map.strokeWeight(1);
if (b_selected) {
pg_map.stroke(c_selected);
pg_map.strokeWeight(3);
}
pg_map.fill(c_color);
//if (b_selected) pg_map.fill(c_selected);
pg_map.ellipse(f_xPos, f_yPos, i_diameter, i_diameter);
pg_map.fill(c_stroke);
//pg_map.fill(c_initialColor);
pg_map.textAlign(CENTER);
pg_map.textSize(i_nameSize);
pg_map.text(s_name, f_xPos, f_yPos-10);
if (b_perceivesCitizen) {
pg_map.text("!", f_xPos, f_yPos-20);
int namePos = -10;
if (b_talking) {
pg_map.text("\"Hallo " + citizen[i_lastCitizenTalked].s_name + "\"", f_xPos, f_yPos-10);
namePos = -20;
}

pg_map.text(s_name, f_xPos, f_yPos + namePos);
pg_map.stroke(c_stroke);
pg_map.strokeWeight(1);
if (b_talking) {

pg_map.line(f_xPos, f_yPos, citizen[i_lastCitizenTalked].f_xPos, citizen[i_lastCitizenTalked].f_yPos);
}
}
@@ -166,24 +213,24 @@ class Citizen extends Entity {
void perceive() {
b_perceivesCitizen = false;
i_perceivedCitizen = -1;
if (!b_talking) {
for (int i = -5; i < 6; i++) { //10 rays
float f_rayAngle = (f_angle) + i/TWO_PI;
for (int j = 0; j < 10; j++) { //10 steps of collision detection per ray
for (int k = 1; k < i_lookRaySteps; k ++) {
dot.x = f_xPos-k*((cos(f_rayAngle)*i_visionDistance)/i_lookRaySteps);
dot.y = f_yPos-k*((sin(f_rayAngle)*i_visionDistance)/i_lookRaySteps);
if (b_debug)pg_map.point(dot.x, dot.y);
for (int l = 0; l < citizen.length; l++) {
if (dot.x > citizen[l].i_collBoundX && dot.x < citizen[l].i_collBoundX + citizen[l].i_collBoundW
&& dot.y > citizen[l].i_collBoundY && dot.y < citizen[l].i_collBoundY + citizen[l].i_collBoundH) {
if (l != i_id && !b_perceivesCitizen) {
b_perceivesCitizen = true;
i_perceivedCitizen = l;
// if (!b_talking) {
for (int i = -5; i < 6; i++) { //10 rays
float f_rayAngle = (f_angle) + i/TWO_PI;
for (int j = 0; j < 10; j++) { //10 steps of collision detection per ray
for (int k = 1; k < i_lookRaySteps; k ++) {
dot.x = f_xPos-k*((cos(f_rayAngle)*i_visionDistance)/i_lookRaySteps);
dot.y = f_yPos-k*((sin(f_rayAngle)*i_visionDistance)/i_lookRaySteps);
//if (b_debug)pg_map.point(dot.x, dot.y);
for (int l = 0; l < citizen.length; l++) {
if (dot.x > citizen[l].i_collBoundX && dot.x < citizen[l].i_collBoundX + citizen[l].i_collBoundW
&& dot.y > citizen[l].i_collBoundY && dot.y < citizen[l].i_collBoundY + citizen[l].i_collBoundH) {
if (l != i_id && !b_perceivesCitizen && citizen[l].i_location == 1 && i_location == 1) {
b_perceivesCitizen = true;
i_perceivedCitizen = l;
if (i_lastCitizenTalked != l && citizen[l].i_lastCitizenTalked != i_id) {
turnTo(f_xPos-citizen[l].f_xPos, f_yPos-citizen[l].f_yPos, 2);

if (citizen[l].i_perceivedCitizen == i_id && i_lastCitizenTalked != l && citizen[l].i_lastCitizenTalked != i_id) { //if perceived citizen perceives me and din't talk to me last time
if (citizen[l].i_perceivedCitizen == i_id) { //if perceived citizen perceives me and din't talk to me last time
talkTo(citizen[l]);
citizen[l].talkTo(this);
}
@@ -210,7 +257,7 @@ class Citizen extends Entity {
b_moving = false;
i_lastCitizenTalked = citizen.i_id;

println(s_name + " talking to " + citizen.s_name);
//println(s_name + " talking to " + citizen.s_name);
//c_color = c_color / 10 * 9 + citizen.c_color/10;
}

@@ -220,9 +267,9 @@ class Citizen extends Entity {
float b = blue(c_color);


float r_new = (99*r + red(citizen[i_lastCitizenTalked].c_color)) / 99.6666;
float g_new = (99*g + green(citizen[i_lastCitizenTalked].c_color)) / 99.6666;
float b_new = (99*b + blue(citizen[i_lastCitizenTalked].c_color)) / 99.6666;
float r_new = (19*r + red(citizen[i_lastCitizenTalked].c_color)) / 20;
float g_new = (19*g + green(citizen[i_lastCitizenTalked].c_color)) / 20;
float b_new = (19*b + blue(citizen[i_lastCitizenTalked].c_color)) / 20;

c_color = color(r_new, g_new, b_new);

@@ -231,13 +278,14 @@ class Citizen extends Entity {

//c_color = (c_color + citizen[i_lastCitizenTalked].c_color) / 2;
b_talking = false;
b_moving = b_movingBeforeTalk;
//b_moving = b_movingBeforeTalk;
b_moving = true;
//prevent talking to the same person right after
}
}
boolean b_pathFindKaputt;

void goTo(int x, int y, int prio) {
boolean b_pathFindKaputt;
void goTo(int x, int y) {
//add: go to node? go to house?
int i_goToX = x;
int i_goToY = y;
@@ -282,14 +330,24 @@ class Citizen extends Entity {
b_moving = true;
} else { //implement more intelligent design which calls goTo not in this frame, but in the next 120 frames or so
//also at this point i can move recalculating the nodes into the next frames if no route is found (not only random)..
if (b_randomRun) goTo(int(random(0, pg_map.width)), int(random(0, pg_map.height)), 10);
if (b_randomRun) goTo(int(random(0, pg_map.width)), int(random(0, pg_map.height)));
}
} else {
println("Pathfinding failed");
b_pathFindKaputt = false;
f_xPos = (int)random(0, i_windowW);
f_yPos = (int)random(0, i_windowH);
goTo((int)houses.get(i_home).v2_center.x, (int)houses.get(i_home).v2_center.y);
}
}



void move() {
i_collBoundX = (int)f_xPos - (i_diameter/2);
i_collBoundY = (int)f_yPos - (i_diameter/2);
i_collBoundW = i_diameter;
i_collBoundH = i_diameter;
if (rNodes.length > nextNode) {
float f_xPosNext = rNodes[nextNode].xf();
float f_yPosNext = rNodes[nextNode].yf();
@@ -313,7 +371,7 @@ class Citizen extends Entity {
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)), 10);
goTo(int(random(0, pg_map.width)), int(random(0, pg_map.height)));
}
}
}

+ 6
- 3
Entities.pde View File

@@ -31,13 +31,14 @@ class Entity {
float f_xPos, f_yPos, f_xSpawn, f_ySpawn;
float f_angle;
int i_diameter = 10;

int i_collBoundX, i_collBoundY, i_collBoundW, i_collBoundH;
int i_nameSize = 12;

int i_location; //0: at home. 1: outside. 2: at work. 3: in church. 4: at a friends place .. etc

int i_nameSize = 12;
color c_selected = color(128, 50, 50);
color c_color = color(50, 200, 80);
color c_initialColor;
color c_stroke = color(255, 255, 255);
PVector v2_direction = new PVector(0, 0);

@@ -58,6 +59,7 @@ class Entity {
i_collBoundY = (int)f_yPos - (i_diameter/2);
i_collBoundW = i_diameter;
i_collBoundH = i_diameter;
i_location = 0;
}


@@ -73,6 +75,7 @@ class Entity {
i_collBoundY = (int)f_yPos - (i_diameter/2);
i_collBoundW = i_diameter;
i_collBoundH = i_diameter;
i_location = 1;
}
void despawn() {
b_linked = false;
@@ -96,6 +99,7 @@ class Entity {
}
}
void turn() {
f_angle = v2_direction.heading();
if (!(abs(int(v2_direction.heading() * 1000) - int(v2_turnBuffer.heading()*1000)) < 100)) {
v2_direction = v2_direction.rotate(i_turning*PI/180*f_turnSpeed);
} else {
@@ -104,7 +108,6 @@ class Entity {
}

void display() {

}
}


+ 1
- 0
Map.pde View File

@@ -7,6 +7,7 @@ PImage img_streets;
PGraphics pg_map;
int i_mapOffsetX, i_mapOffsetY, i_mapOffsetStartX, i_mapOffsetStartY;
int i_biggestHouseSize;
int i_mapW, i_mapH;

ArrayList<House> houses = new ArrayList<House>();


+ 116
- 59
Time.pde View File

@@ -1,69 +1,126 @@
import java.util.Date;
import java.util.Calendar;
import java.text.SimpleDateFormat;
//Date date = new Date();
//SimpleDateFormat ft;
//Calendar c = Calendar.getInstance();
Date date = new Date();
SimpleDateFormat dateFormat;
Calendar calendar = Calendar.getInstance();
//24*60 = 1440;

int i_days = 1;
int i_hours;
int i_minutes;
int i_startMinutes;
int i_flexibleTime;
void initTime() {
i_hours = 5;
i_minutes = 0;
i_startMinutes = millis();
}
boolean b_pauseTime;
boolean b_changeTime;
void time() {
//calculate time
if (!b_changeTime) {
if (millis() - i_startMinutes > i_timeTickMS) {
i_startMinutes = millis();
if (!b_pauseTime) {
i_minutes++;
}
}
if (i_minutes >= 60) {
i_hours++;
i_minutes = 0;
}
if (i_hours >= 24) {
i_days++;
i_hours = 0;
}

i_flexibleTime = i_hours*60 + i_minutes;
} else {
i_minutes = i_flexibleTime % 60;
i_hours = (int)i_flexibleTime / 60;
if (i_flexibleTime < 0) {
i_days --;
i_flexibleTime = 1440;
}
if (i_flexibleTime > 1440) {
i_days++;
i_flexibleTime = 0;
}
}

//time events

if ((i_flexibleTime >= getFlexTime(0, 0) && i_flexibleTime < getFlexTime(6, 0)) || i_flexibleTime > getFlexTime(23,0)) {
buttons[6].i_x = i_windowW/2-85;
buttons[6].i_y = i_skipNightButtonY;
textSize(10);
buttons[6].i_tx = buttons[6].i_x + buttons[6].i_w/2 - (int)(textWidth(buttons[6].s_text) /2);
} else {
buttons[6].i_x = -1000;
buttons[6].i_y = -1000;
buttons[6].i_tx = -1000;
}
}



/*
Simple DateFormat Format Codes
G Era designator AD
y Year in four digits 2001
M Month in year July or 07
d Day in month 10
h Hour in A.M./P.M. (1~12) 12
H Hour in day (0~23) 22
m Minute in hour 30
s Second in minute 55
S Millisecond 234
E Day in week Tuesday
D Day in year 360
F Day of week in month 2 (second Wed. in July)
w Week in year 40
W Week in month 1
a A.M./P.M. marker PM
k Hour in day (1~24) 24
K Hour in A.M./P.M. (0~11) 10
z Time zone Eastern Standard Time
' Escape for text Delimiter
" Single quote


Date and Time Conversion Characters
Character Description Example
c Complete date and time Mon May 04 09:51:52 CDT 2009
F ISO 8601 date 2004-02-09
D U.S. formatted date (month/day/year) 02/09/2004
T 24-hour time 18:05:19
r 12-hour time 06:05:19 pm
R 24-hour time, no seconds 18:05
Y Four-digit year (with leading zeroes) 2004
y Last two digits of the year (with leading zeroes) 04
C First two digits of the year (with leading zeroes) 20
B Full month name February
b Abbreviated month name Feb
m Two-digit month (with leading zeroes) 02
d Two-digit day (with leading zeroes) 03
e Two-digit day (without leading zeroes) 9
A Full weekday name Monday
a Abbreviated weekday name Mon
j Three-digit day of year (with leading zeroes) 069
H Two-digit hour (with leading zeroes), between 00 and 23 18
k Two-digit hour (without leading zeroes), between 0 and 23 18
I Two-digit hour (with leading zeroes), between 01 and 12 06
l Two-digit hour (without leading zeroes), between 1 and 12 6
M Two-digit minutes (with leading zeroes) 05
S Two-digit seconds (with leading zeroes) 19
L Three-digit milliseconds (with leading zeroes) 047
N Nine-digit nanoseconds (with leading zeroes) 047000000
P Uppercase morning or afternoon marker PM
p Lowercase morning or afternoon marker pm
z RFC 822 numeric offset from GMT -0800
Z Time zone PST
s Seconds since 1970-01-01 00:00:00 GMT 1078884319
Q Milliseconds since 1970-01-01 00:00:00 GMT 1078884319047
*/
G Era designator AD
y Year in four digits 2001
M Month in year July or 07
d Day in month 10
h Hour in A.M./P.M. (1~12) 12
H Hour in day (0~23) 22
m Minute in hour 30
s Second in minute 55
S Millisecond 234
E Day in week Tuesday
D Day in year 360
F Day of week in month 2 (second Wed. in July)
w Week in year 40
W Week in month 1
a A.M./P.M. marker PM
k Hour in day (1~24) 24
K Hour in A.M./P.M. (0~11) 10
z Time zone Eastern Standard Time
' Escape for text Delimiter
" Single quote
Date and Time Conversion Characters
Character Description Example
c Complete date and time Mon May 04 09:51:52 CDT 2009
F ISO 8601 date 2004-02-09
D U.S. formatted date (month/day/year) 02/09/2004
T 24-hour time 18:05:19
r 12-hour time 06:05:19 pm
R 24-hour time, no seconds 18:05
Y Four-digit year (with leading zeroes) 2004
y Last two digits of the year (with leading zeroes) 04
C First two digits of the year (with leading zeroes) 20
B Full month name February
b Abbreviated month name Feb
m Two-digit month (with leading zeroes) 02
d Two-digit day (with leading zeroes) 03
e Two-digit day (without leading zeroes) 9
A Full weekday name Monday
a Abbreviated weekday name Mon
j Three-digit day of year (with leading zeroes) 069
H Two-digit hour (with leading zeroes), between 00 and 23 18
k Two-digit hour (without leading zeroes), between 0 and 23 18
I Two-digit hour (with leading zeroes), between 01 and 12 06
l Two-digit hour (without leading zeroes), between 1 and 12 6
M Two-digit minutes (with leading zeroes) 05
S Two-digit seconds (with leading zeroes) 19
L Three-digit milliseconds (with leading zeroes) 047
N Nine-digit nanoseconds (with leading zeroes) 047000000
P Uppercase morning or afternoon marker PM
p Lowercase morning or afternoon marker pm
z RFC 822 numeric offset from GMT -0800
Z Time zone PST
s Seconds since 1970-01-01 00:00:00 GMT 1078884319
Q Milliseconds since 1970-01-01 00:00:00 GMT 1078884319047
*/

+ 145
- 38
UI.pde View File

@@ -1,21 +1,58 @@
int i_buttonCount = 7;

Button buttons[] = new Button[5];
Button buttons[] = new Button[i_buttonCount];


int i_debugTextSize = 10;
int i_debugButtonWidth = 100;
int i_debugButtonHeight = i_debugTextSize;
int i_debugButtonCorner = 5;
int i_debugButtonPadding = 20;
int i_debugMenuPadding = 15;
int i_debugMenuX = 15;
int i_debugMenuY = 15;
int i_debugMenuW = i_debugButtonWidth + 2 * i_debugMenuPadding;
int i_debugMenuH;
int i_debugMenuButtonC;

float f_timeBoxCenterX;
float f_timeBoxX;
float f_timeBoxY;
float f_timeBoxW;
float f_timeBoxH = 34;
float f_timeBoxCorner = 6;

int i_uiTransparency = 200;
String s_timeString;
void initUI() {
f_timeBoxCenterX = i_windowW/2;
f_timeBoxY = 10 ;

i_uiX = 0;
i_uiY = 518;
i_uiW = width;
i_uiH = height - i_uiY;

buttons[0] = new Button(15, 50, 100, i_debugTextSize, 5, "Autoplay", 0);
buttons[1] = new Button(15, 70, 100, i_debugTextSize, 5, "Lock Camera", 1);
buttons[2] = new Button(15, 90, 100, i_debugTextSize, 5, "Debug", 2);
buttons[3] = new Button(15, 110, 100, i_debugTextSize, 5, "Control Eyes", 3);
buttons[4] = new Button(15, 130, 100, i_debugTextSize, 5, "Houses Texts", 4);
for (int i = 0; i < i_buttonCount; i++) {
buttons[i] = new Button(i);
}
buttons[0].label("Autoplay");
buttons[1].label("Lock Camera");
buttons[2].label("Debug");
buttons[3].label("Control Eyes");
buttons[4].label("Houses Texts");
buttons[5].label("Pause Time");
buttons[6] = new Button(i_windowW/2-85, i_skipNightButtonY, 170, 50, i_debugButtonCorner, "Nacht überspringen >>", 6);
/*
buttons[0] = new Button(15, 50, 100, i_debugTextSize, i_debugButtonCorner, "Autoplay", 0);
buttons[1] = new Button(15, 70, 100, i_debugTextSize, i_debugButtonCorner, "Lock Camera", 1);
buttons[2] = new Button(15, 90, 100, i_debugTextSize, i_debugButtonCorner, "Debug", 2);
buttons[3] = new Button(15, 110, 100, i_debugTextSize, i_debugButtonCorner, "Control Eyes", 3);
buttons[4] = new Button(15, 130, 100, i_debugTextSize, i_debugButtonCorner, "Houses Texts", 4);
buttons[5] = new Button(15, 150, 100, i_debugTextSize, i_debugButtonCorner, "Pause Time", 5); */
i_debugMenuH = (i_debugMenuButtonC -1) * (i_debugButtonHeight+i_debugButtonPadding) + 2 * i_debugMenuPadding;
}

int i_skipNightButtonY = 50;

int i_uiX, i_uiY, i_uiW, i_uiH;
int i_uiOffsetX, i_uiOffsetY, i_uiOffsetStartX, i_uiOffsetStartY, i_initUiY;
@@ -23,16 +60,22 @@ void drawUI() {

//camera tracking
if (b_cameraLock) {
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);
if (i_selectedCitizen != 0) {
if (b_mapZoom) {
i_mapOffsetX = i_windowW/2-int(citizen[i_selectedCitizen].f_xPos)/2;
i_mapOffsetY = i_windowH/2-int(citizen[i_selectedCitizen].f_yPos)/2;
} else {
i_mapOffsetX = i_windowW/2-int(citizen[i_selectedCitizen].f_xPos);
i_mapOffsetY = i_windowH/2-int(citizen[i_selectedCitizen].f_yPos);
}
}
}

//draw
//debugmenu
stroke(1);
fill(127, 127, 127, 127);
rect(i_debugMenuX, i_debugMenuY, i_debugMenuW, i_debugMenuH);
//buttons
strokeWeight(0);
textSize(i_debugTextSize);
@@ -40,12 +83,19 @@ void drawUI() {
buttons[i].display();
}
//clock
fill(255, i_uiTransparency);
rect(6, 4, 140, 31, 6);
if (b_realTime) {
s_timeString = "Tag " + i_days + ", " + String.format("%02d", hour()) + ":" + String.format("%02d", minute()) + ":" + String.format("%02d", second());
} else {
s_timeString = "Tag " + i_days + ", " + nf(i_hours, 2, 0) + ":" + nf(i_minutes, 2, 0);
}
textSize(30);
textAlign(LEFT);
f_timeBoxW = textWidth(s_timeString)+6;
f_timeBoxX = f_timeBoxCenterX-textWidth(s_timeString) / 2;
fill(255, i_uiTransparency);
rect(f_timeBoxX, f_timeBoxY, f_timeBoxW, f_timeBoxH, f_timeBoxCorner);
fill(0);
text(String.format("%02d", hour()) + ":" + String.format("%02d", minute()) + ":" + String.format("%02d", second()), 10, 30);
text(s_timeString, f_timeBoxX+3, f_timeBoxY - 8 + f_timeBoxH);

//debug
if (b_debug) {
@@ -66,9 +116,11 @@ void drawUI() {
"Name: " + citizen[i_selectedCitizen].s_name,
"Gender: " + citizen[i_selectedCitizen].s_gender,
"Age: " + citizen[i_selectedCitizen].i_age,
"Loation: " + (citizen[i_selectedCitizen].i_location == 0 ? "home / heading home" : "outside"),
"x: " + int(citizen[i_selectedCitizen].f_xPos),
"y: " + int(citizen[i_selectedCitizen].f_yPos),
"Angle: " + citizen[i_selectedCitizen].f_angle,
"Moving: " + citizen[i_selectedCitizen].b_moving,
"Movement speed: " + round(citizen[i_selectedCitizen].f_movementSpeed*100),
"Random Run: " + citizen[i_selectedCitizen].b_randomRun,
"Turning: " + citizen[i_selectedCitizen].b_turning,
@@ -89,7 +141,7 @@ void drawUI() {
if (maxLinesPerColumn > 0) {
int requiredColumns = (debug.length/maxLinesPerColumn)+1;
for (int i = 0; i < requiredColumns; i++) {
while (((line-(maxLinesPerColumn*i)) * i_debugTextSize + i_debugTextSize -1)+i_uiY<height && line < debug.length) {
while (((line-(maxLinesPerColumn*i)) * i_debugTextSize + i_debugTextSize -1)+i_uiY<i_windowH && line < debug.length) {
text(debug[line], 10+(columnWidth*i), i_uiY+(i_debugTextSize*((line-(maxLinesPerColumn*i))+1)));
line++;
}
@@ -147,49 +199,80 @@ void buttonFunctions(int s) {
case(4):
b_housesTexts = !b_housesTexts;
break;
case(5):
b_pauseTime = !b_pauseTime;
break;
case(6):
i_flexibleTime = getFlexTime(6, 0);
i_minutes = 0;
i_hours = 6;
break;
default:
break;
}
}

int getFlexTime(int hour, int minute) {
return (hour*60+minute);
}

class Button {
int i_x, i_y, i_w, i_h, i_c, i_f, i_tx;
int i_x, i_y, i_w, i_h, i_c, i_id, i_tx;
int i_margin = 5;
String s_t;
Button(int x, int y, int w, int h, int corner, String text, int function) {
String s_text;

Button(int id) {
i_id = id;
i_x = i_debugMenuX + i_debugMenuPadding;
i_y = i_debugMenuY + i_debugMenuPadding + (i_debugButtonPadding + i_debugButtonHeight) * i_id;
i_w = i_debugButtonWidth;
i_h = i_debugButtonHeight;
i_c = i_debugButtonCorner;
i_debugMenuButtonC++;
}

void label(String lab) {
s_text = lab;
textSize(10);
i_tx = i_x + (i_w/2) - (int)(textWidth(s_text) /2);
}

Button(int x, int y, int w, int h, int corner, String text, int id) {
i_id = id;
i_x = x;
i_y = y;
i_w = w;
i_h = h;
i_c = corner;
i_f = function;
s_t = text;
i_tx = i_x + (i_w/2) - (int(textWidth(s_t) /2));
s_text = text;
textSize(10);
i_tx = i_x + i_w/2 - (int)(textWidth(s_text) /2);
}
boolean hover() {
if (mouseX > i_x - i_margin && mouseX < i_x+i_w + i_margin && mouseY > i_y - i_margin && mouseY < i_y+i_h + i_margin) return true;
else return false;
}
void click() {
buttonFunctions(i_f);
buttonFunctions(i_id);
}
void display() {
fill(150, 170, 250, 150);
rect(i_x, i_y, i_w, i_h, i_c);
fill(0);
text(s_t, i_tx, i_y + i_debugTextSize);
text(s_text, i_tx, i_y + i_h/2 + i_debugTextSize/2.5);
}
}


boolean b_mouseChangeMapOffset, b_mouseChangeUiHeight;
boolean b_hoverUI;

int i_changeTimeMouseX;
boolean b_selectCitizen;
boolean b_drag;
void mousePressed() {
if (mouseButton == LEFT) {
boolean clickUI = false;


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;
@@ -197,7 +280,7 @@ void mousePressed() {
clickUI = true;
}

for (int i = 0; i < buttons.length; i++) {
for (int i = 0; i < buttons.length; i++) { // click buttones
if (buttons[i].hover()) {
buttons[i].click();
clickUI = true;
@@ -205,17 +288,29 @@ void mousePressed() {
}


if (mouseX > f_timeBoxX && mouseX < f_timeBoxX + f_timeBoxW && mouseY > f_timeBoxY && mouseY < f_timeBoxY + f_timeBoxH) { //drag time
clickUI = true;
i_changeTimeMouseX = mouseX;
b_changeTime = true;
}

if (!clickUI) {
int selectedCitizen = i_selectedCitizen; //leftclick select citizen
b_selectCitizen = false;
for (int i = 0; i < citizen.length; i++) {
if (selectedCitizen != 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) {
b_selectCitizen = true;
selectCitizen(i);
}
}
}
if (!b_cameraLock) {
if(!b_selectCitizen){
selectCitizen(0);
}
if (!b_cameraLock || i_selectedCitizen == 0) {
b_mouseChangeMapOffset = true;
i_mapOffsetStartX = mouseX - i_mapOffsetX;
i_mapOffsetStartY = mouseY - i_mapOffsetY;
@@ -223,7 +318,7 @@ void mousePressed() {
}
}
if (mouseButton == CENTER) {
if (!b_cameraLock) {
if (!b_cameraLock || i_selectedCitizen == 0) {
b_mouseChangeMapOffset = true;
i_mapOffsetStartX = mouseX - i_mapOffsetX;
i_mapOffsetStartY = mouseY - i_mapOffsetY;
@@ -238,33 +333,45 @@ void mousePressed() {
// 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), 10);
citizen[i_selectedCitizen].turnTo(citizen[i_selectedCitizen].f_xPos-constrain(i_mapViewToMap(mouseX, i_mapOffsetX), 0, pg_map.width), citizen[i_selectedCitizen].f_yPos-constrain(i_mapViewToMap(mouseY, i_mapOffsetY), 0, pg_map.height), 4);
if (!citizen[i_selectedCitizen].b_talking) {
citizen[i_selectedCitizen].goTo(constrain(i_mapViewToMap(mouseX, i_mapOffsetX), 0, pg_map.width), constrain(i_mapViewToMap(mouseY, i_mapOffsetY), 0, pg_map.height));
citizen[i_selectedCitizen].turnTo(citizen[i_selectedCitizen].f_xPos-constrain(i_mapViewToMap(mouseX, i_mapOffsetX), 0, pg_map.width), citizen[i_selectedCitizen].f_yPos-constrain(i_mapViewToMap(mouseY, i_mapOffsetY), 0, pg_map.height), 4);
}
}
}


int i_mapViewToMap(int mouse, int offset) {
if (b_mapZoom) return (mouse-offset)*2;
else return mouse-offset;
}

void mouseDragged() {
b_drag = true;
if (b_mouseChangeMapOffset) {
i_mapOffsetX = (mouseX - i_mapOffsetStartX);
i_mapOffsetY = (mouseY - i_mapOffsetStartY);
}
if (b_mouseChangeUiHeight) {
i_uiY = mouseY - i_uiOffsetStartY + i_initUiY;
if (i_uiY > height) i_uiY = height;
i_uiH = height - i_uiY;


if (i_uiY > height) i_uiY = i_windowH;
i_uiH = i_windowH - i_uiY;
//hook buttons to ui panel
}
if (b_changeTime) {
i_flexibleTime += mouseX-i_changeTimeMouseX;
i_changeTimeMouseX = mouseX;
}
}
void mouseReleased() {
b_mouseChangeMapOffset = false;
b_mouseChangeUiHeight = false;
b_changeTime = false;
//if (i_mapOffsetStartX == mouseX-i_mapOffsetX && i_mapOffsetStartY == mouseY-i_mapOffsetY && !b_drag && !b_selectCitizen) {//only click, no drag
// selectCitizen(0);
//}
b_drag = false;
//b_selectCitizen = false;
}



+ 84
- 23
citizen.pde View File

@@ -1,38 +1,70 @@
import processing.net.*;

int i_citizenAmount = 100;
/*
todo
dominanz
wächst mit anzahl der am tag durchgeführten kommunikationen
sinkt mit zeit ohne kommunikation
(durchgeführte kommunikationen nach tag resetten)
beeinflusst wie stark eigene farbe übertragen oder übernommen wird
proportional zur farbintensität? alle grau = weltfrieden though
goTo fast immer haus-spezifisch machen. liste der häuser von citizen mit ähnlicher farbe, werden öfter besucht
ab und zu nach hause gehen
goTo random point on map = spaziergang. passiert vorwiegend sonntags? wochentage?
andere lösung finden ausser teleportieren bei unmöglicher pfadfindung
idee:
processing client - spieler verfolgt einen einzigen citizen
ignore-liste
ziel: möglichst viele zur eigenen farbe bekehren
*/

//settings
boolean b_smallerImage = false; //use a cropped, smaller version of the 1920x1080 image for faster development
boolean b_rundgang = false;

boolean b_smallerImage = false ; //broken
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...

int i_sMapReso = 8; //the higher the smaller the reso, 2 is best quality but takes some time to download

float f_walkSpeedMin = 1;
float f_walkSpeedMax = 2;
int i_timeTickMS = 200; //milliseconds how long until next minute ticks on clock

boolean b_cameraLock = false;
boolean b_autoPlay = false;
float f_walkSpeedMin = 2;
float f_walkSpeedMax = 3;

float f_nodeResolution = 0.2; //defines density of path-finding nodes, multiplied with resolution
int i_pathAlgorithm = 4;


boolean b_cameraLock = true;
boolean b_autoPlay = false;
boolean b_realTime = false;
boolean b_controlEyeWithMouse;
boolean b_housesTexts;
boolean b_debug = false;
boolean b_drawNodes = false;


boolean b_debug = true;
boolean b_drawNodes = false;
boolean b_housesTexts = false;

float f_nodeResolution = 0.2; //defines density of path-finding nodes, multiplied with resolution
int i_pathAlgorithm = 4;
int i_debugTextSize = 10;
int i_mapW, i_mapH;
int i_windowW, i_windowH;
int i_viewportW, i_viewportH;

int i_windowW, i_windowH, i_viewportW, i_viewportH;

Server server;
Client client;

void rundgang() {
i_debugMenuX = -200;
}


void setup() {
//fullScreen();
size(700, 600);
server = new Server(this, 5210);
//blendMode(MULTIPLY);
@@ -51,6 +83,8 @@ void setup() {
i_mapW = pg_map.width;
i_mapH = pg_map.height;

if (b_rundgang) rundgang();
initTime();
initHouses();
initPathFinding();
initWeather();
@@ -67,6 +101,8 @@ void pre() {
i_uiY = height - i_uiH;
i_uiW = width;
i_uiH = height - i_uiY;
f_timeBoxCenterX = width/2;
f_timeBoxY = 10 ;
}
}
String s_fromClient;
@@ -74,22 +110,46 @@ int i_mapLevelTransferC;
int i_makeThemGoC;
void draw() {
background(127);
for (int i = 0; i < i_citizenAmount*3; i++){ //so bad
clientCommunication();
}

clientCommunication();
time();

if (b_makeThemGo) {
citizen[i_makeThemGoC].goTo(int(random(0, pg_map.width)), int(random(0, pg_map.height)), 10);
citizen[i_makeThemGoC].goTo(int(random(0, pg_map.width)), int(random(0, pg_map.height)));
i_makeThemGoC ++;
if (i_makeThemGoC >= citizen.length) {
b_makeThemGo = false;
i_makeThemGoC = 0;
}
println(i_makeThemGoC);
}

pg_map.beginDraw();
pg_map.background(127);

//pg_map.tint(50,50,200,255);

int nightC = 0;
if (i_flexibleTime > 300 && i_flexibleTime < 550) {
nightC = (int)map(i_flexibleTime, 300, 550, 50, 255);
}
if (i_flexibleTime <= 300 || i_flexibleTime >= 1300) {
nightC = 50;
}
if (i_flexibleTime >= 550 && i_flexibleTime <= 1000) {
nightC = 255;
}
if (i_flexibleTime > 1000 && i_flexibleTime < 1300) {
nightC = (int)map(i_flexibleTime, 1000, 1300, 255, 50);
}

pg_map.tint(nightC, nightC, (int)map(nightC, 50, 255, 150, 255), 255);
i_visionTransparency = (int)map(nightC, 50, 255, 0, 150);
//150-450 //morgen
//1000-1300 //abend


if (b_debug) pg_map.image(img_houses, 0, 0, img_houses.width, img_houses.height);
else pg_map.image(img_map, 0, 0, img_houses.width, img_houses.height);

@@ -111,17 +171,18 @@ 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();
if (b_debug)
citizen[i].debug();
citizen[i].update();
if (i != i_selectedCitizen)
citizen[i].display();
if (b_debug)
citizen[i].debug();
}
}
if (b_controlEyeWithMouse) {
citizen[i_selectedCitizen].turnTo(citizen[i_selectedCitizen].f_xPos-(float)constrain(i_mapViewToMap(mouseX, i_mapOffsetX), 0, pg_map.width), citizen[i_selectedCitizen].f_yPos-(float)constrain(i_mapViewToMap(mouseY, i_mapOffsetY), 0, pg_map.height), 0) ;
}
citizen[i_selectedCitizen].display();

if (i_selectedCitizen != 0) citizen[i_selectedCitizen].display();

pg_map.endDraw();
image(pg_map, i_mapOffsetX, i_mapOffsetY, i_mapW, i_mapH);

Loading…
Cancel
Save