class person { int no, spyon; boolean following = false, animated = false, dragging = false; boolean hiding = false, spying = false, moving = false, discovered = false; float angle, spyangle; float sight = sightangle; //PI*0.66; float x, y, linkx, linky, aimx, aimy, stepx, stepy; boolean over = false; boolean linking = false; float speed = generalspeed, movedist = 100, spymax = distval2, spymin = distval1; int hidetime = hidingtime, counter = 0, waittime = 2, peakout = 0; //int anicounter = 0, animax; String nam; void restart() { dragging = false; hiding = false; moving = false; discovered = false; over = false; spying = false; } person(String na, int sp, int n, int xp, int yp) { spyon = sp; no = n; x = xp; y = yp; following = (spyon==-1) ? false : true; angle = random(2*PI); nam = na; linkx = 70 + ((no/6)%2)*50 + no%6*80; linky = 50 + int(no/6) * 60; } void check() { int d = 20; over = (mouseX/scaler>=x-d && mouseX/scaler<=x+d && mouseY/scaler>=y-d && mouseY/scaler<=y+d) ? true : false; } void linkcheck() { int d = 20; over = (mouseX/scaler>=linkx-d && mouseX/scaler<=linkx+d && mouseY/scaler>=linky-d && mouseY/scaler<=linky+d) ? true : false; if(over && !linking && mousePressed && (mouseButton==LEFT) && !globallinking) { linking = true; globallinking=true; } else if(!mousePressed && linking) { boolean noone = true; for(int i=0; i w-b || x+stepx < b || y+stepy > h-3*b || y+stepy < b) { moving = false; } else { x+=stepx; y+=stepy; } if(abs(aimx-x) <= speed && abs(aimy-y) <= speed) { x=limitx(aimx); y=limity(aimy); moving=false; } } else if(hiding) { counter++; if(counter>hidetime) { hiding=false; peakout++; } } else if(!spying) { //searchmode angle+=turnspeed; calc_spyangle(); //check if spyon is in sight-angle thedist = (abs(spyangle - angle))%(2*PI); if( (thedist < sight/2 || thedist > 2*PI-sight/2)) { spying = true; } } else if(spying) { calc_spyangle(); //move angle towards spyon thedist = ((spyangle - angle))%(2*PI); if(thedist > sight/6 || thedist < 2*PI-sight/6) { //angle+= (thedist>0) ? -0.01 : 0.01; //angle += (thedist)/10; angle = spyangle; } //check if spyon is looking in your direction thedist = (abs(spyangle - all[spyon].angle - PI ))%(2*PI); if( (thedist < sight/2 || thedist > 2*PI-sight/2) && !all[spyon].hiding && !all[spyon].moving && !all[spyon].dragging) { //println("discovered! "+spyangle+" "+all[spyon].angle); hiding = true; spying = false; counter = 0; if(!discovered) { discovered = true; peakout=0; } else { if(peakout>waittime) { reposition(spyangle); } } } else discovered = false; if(spying) { if(dist(x,y,all[spyon].x,all[spyon].y) >= spymax) { movetowards(all[spyon].x,all[spyon].y); } else if(dist(x,y,all[spyon].x,all[spyon].y) <= spymin) { moveaway(all[spyon].x,all[spyon].y); } } } } else { angle+=turnspeed; } } } /* void animate(int a) { animated = true; animax = a; anicounter = 0; }*/ float limitx(float x1) { if(x1w-b) return w-b; else return x1; } float limity(float y1) { if(y1h-3*b) return h-3*b; else return y1; } void movetowards(float x1, float y1) { moving = true; if(hiding) hiding=false; aimx = limitx(x1); aimy = limity(y1); float aimangle = (atan((aimy-y)/(aimx-x))); if((aimx-x)<0) aimangle = PI+aimangle; stepy = sin(aimangle)*speed; stepx = cos(aimangle)*speed; aimx = limitx(all[spyon].x - cos(aimangle)*(spymax+spymin)/2-stepx); aimy = limity(all[spyon].y - sin(aimangle)*(spymax+spymin)/2-stepy); } void moveaway(float x1, float y1) { moving = true; if(hiding) hiding=false; aimx = limitx(x1); aimy = limity(y1); float aimangle = (atan((aimy-y)/(aimx-x))); if((aimx-x)<0) aimangle = PI+aimangle; stepy = -sin(aimangle)*speed; stepx = -cos(aimangle)*speed; aimx = limitx(all[spyon].x - cos(aimangle)*(spymax+spymin)/2-stepx); aimy = limity(all[spyon].y - sin(aimangle)*(spymax+spymin)/2-stepy); } void reposition(float spa) { moving = true; float aimangle = (random(10)>5) ? spa + PI/2 : spa - PI/2; aimx = limitx(x+cos(aimangle)*movedist); aimy = limity(y+sin(aimangle)*movedist); stepy = sin(aimangle)*speed; stepx = cos(aimangle)*speed; } void reset(int xp, int yp) { x = xp; y = yp; restart(); angle = random(2*PI); } void calc_spyangle() { //calculate distance and angle of person to spy on float dx = all[spyon].x - x; float dy = all[spyon].y - y; spyangle = (atan(dy/dx)); if(dx<0) spyangle = PI+spyangle; if(spyangle<0) spyangle+=2*PI; else if(spyangle>2*PI) spyangle-=2*PI; } void linkdraw() { noStroke(); pushMatrix(); translate(linkx, linky); if(over) fill(255,180,0); else fill(255,120,0); triangle(-10,10,10,10,0,-5); pushMatrix(); translate(0,-5); ellipse(0,0,10,10); fill(255); arc(0,0,8,8,0,PI); popMatrix(); text(nam,-5,17); popMatrix(); noFill(); stroke(255,50); if(linking) { line(all[no].linkx,all[no].linky, mouseX, mouseY); } else { if(following) line(all[no].linkx,all[no].linky, all[spyon].linkx, all[spyon].linky); } } void draw() { noStroke(); pushMatrix(); translate(x,y); //body if(dragging) fill(100,100,255); else if(spying && moving) if(over) fill(200,50,50); else fill(200,50,100); else if(spying) if(over) fill(255,100,255); else fill(255,0,255); else if(hiding) if(over) fill(150,50,0); else fill(170,60,0); else if(over) fill(255,180,0); else fill(255,120,0); triangle(-10,10,10,10,0,-5); //face if(!hiding) { pushMatrix(); translate(0,-5); ellipse(0,0,10,10); fill(255); rotate(angle-PI/2); if(!moving) arc(0,0,8,8,0,PI); popMatrix(); } else { fill(200,50,0); ellipse(0,0,10,10); } fill(255); text(nam,-5,17); popMatrix(); //sight if(over) { pushMatrix(); translate(x,y); fill(255,30); noStroke(); if(!moving && !dragging) arc(0,0,200,200,angle-sight/2,angle+sight/2); popMatrix(); if(following) { noFill(); stroke(255,50); int chaser = no; int victim = spyon; for(int i=0; i<=p-1; i++) formerlist[i]=100; formerlist[0]=chaser; formerlist[1]=victim; int listpos = 2; boolean looper = false; boolean cont = true; line(all[chaser].x,all[chaser].y, all[victim].x, all[victim].y); if (mousePressed && (mouseButton == LEFT)) { while(cont) { if(looper) cont = false; line(all[chaser].x,all[chaser].y, all[victim].x, all[victim].y); chaser = victim; victim = all[victim].spyon; for(int i=0; i<=p-1; i++) { if(victim == formerlist[i]) looper = true; } if(victim == -1) cont = false; if(victim==no) looper = true; formerlist[listpos]=victim; listpos++; } } } } } }