xxxxxxxxxx
int[][] grid,tar;
ArrayList<Person> people;
int cols=8,rows=8,Cx=0,Cy=0,numpeople=1,funP=0;
boolean add=true,start=false;
float m=.658856,fun=0,s=55;
void setup(){
size(900,650);
background(0);
people=new ArrayList();
grid= new int[cols][rows];
tar= new int[cols][rows];
for (int i = 0; i < cols; i++) {
for (int j = 0; j < rows; j++) {
grid[i][j] = 0;
tar[i][j] = 0;
}
}
grid[Cx][Cy]=1;
fun=0;
}
void draw(){
background(0);
stroke(255);
strokeWeight(1);
fill(0);
if(start==true){
rect((width/2)-((cols/2)*(s))-s+65,(height/2)-((rows/2)*(s))-s,(cols+2)*s,(rows+2)*s);
line((width/2)-((cols/2)*(s))-s+65,(height/2)-((rows/2)*(s))-s,(width/2)+((cols/2)*(s))+s+65,(height/2)+((rows/2)*(s))+s);
line((width/2)+((cols/2)*(s))+s+65,(height/2)-((rows/2)*(s))-s,(width/2)-((cols/2)*(s))-s+65,(height/2)+((rows/2)*(s))+s);
line(width/2+65,(height/2)-((rows/2)*(s))-s,width/2+65,(height/2)+((rows/2)*(s))+s);
line((width/2)-((cols/2)*(s))-s+65,height/2,(width/2)+((cols/2)*(s))+s+65,height/2);
for (int i = 0; i < cols; i++) {
for (int j = 0; j < rows; j++) {
stroke(255);
fill(0);
rect((width/2)+((i*s))-((cols/2)*s)+65,(height/2)+(j*s)-((rows/2)*s),s,s);
noStroke();
if(grid[i][j]==1){
fill(0,0,200);
ellipse((width/2)+((i*s))-((cols/2)*s)+(s/2)+65,(height/2)+(j*s)-((rows/2)*s)+(s/2),s*.6,s*.6);
}
else if(grid[i][j]==2){
fill(200,0,0);
ellipse((width/2)+((i*s))-((cols/2)*s)+(s/2)+65,(height/2)+(j*s)-((rows/2)*s)+(s/2),s*.6,s*.6);
funP++;
}
}
}
if(add==true){
if(frameCount%120==0){ //120
for(int i=0;i<numpeople;i++){
if(full()==false){
people.add(new Person());
}
}
}
for(int i=0;i<people.size();i++){
people.get(i).update(i);
}
if(frameCount%900==0){
numpeople++;
}
}
fill(0);
noStroke();
rect(0,0,125,(height-30));
stroke(255);
strokeWeight(5);
rect(3,100*m,105,(height-105*m));
strokeWeight(1);
fill(255,0,0);
textSize(22.5);
textAlign(LEFT);
text("Fun Meter",3*m,85*m);
noStroke();
fill(200,0,0);
fun=funP*(16);
if((fun-5)<(height-105*m)){
rect(6,(height-fun-7),100,fun);
add=true;
funP=0;
}
else{
add=false;
noStroke();
fill(200,0,0);
rect(6,(height-500),100,500-7);
fill(0);
rect(110,0,width,height);
fill(255);
textSize(80*m);
textAlign(CENTER,CENTER);
text("You Failed\nPeople had too much fun",width/2,height/2.5);
textSize(40*m);
text("Click to try again",width/2,height*.6);
}
}
else{
textAlign(CENTER,CENTER);
stroke(0);
textSize(45*m);
fill(0);
rect(0,0,width,height);
fill(255);
text("People are trying to have fun in the fountain.\nYou the Fun Police must keep the fun level under control."+
"\nDo this by getting people out of the fountain.\nClick to start.",width/2,height/2);
}
}
boolean full(){
int t=0;
for(int i=0;i<cols;i++){
for(int j=0;j<rows;j++){
if(tar[i][j]==1){
t++;
}
}
}
return t==((rows*cols)-1);
}
void keyPressed(){
if(keyCode==UP && Cy>0 && add==true){
grid[Cx][--Cy]=1;
tar[Cx][Cy]=2;
grid[Cx][Cy+1]=0;
tar[Cx][Cy+1]=0;
}
if(keyCode==DOWN && Cy<(rows-1) && add==true){
grid[Cx][++Cy]=1;
tar[Cx][Cy]=2;
grid[Cx][Cy-1]=0;
tar[Cx][Cy-1]=0;
}
if(keyCode==LEFT && Cx>0 && add==true){
grid[--Cx][Cy]=1;
tar[Cx][Cy]=2;
grid[Cx+1][Cy]=0;
tar[Cx+1][Cy]=0;
}
if(keyCode==RIGHT && Cx<(cols-1) && add==true){
grid[++Cx][Cy]=1;
tar[Cx][Cy]=2;
grid[Cx-1][Cy]=0;
tar[Cx-1][Cy]=0;
}
}
void mouseClicked(){
if(start==false){
start=true;
}
if(add==false){
people=new ArrayList();
grid= new int[cols][rows];
for (int i = 0; i < cols; i++) {
for (int j = 0; j < rows; j++) {
grid[i][j] = 0;
}
}
grid[Cx][Cy]=1;
fun=0;
numpeople=1; funP=0;
add=true;
}
}
class Person{
PVector start=new PVector(),cur=new PVector(),target=new PVector();
float lerp=0,rate=.0075;
int f=0,f1=0;
Person(){
int b=int(random(1,5));
boolean d=true;
lerp=0;
f=(int)random(0,cols);
f1=(int)random(0,rows);
while(d==true){
if(grid[int(f)][int(f1)]==0 && tar[int(f)][int(f1)]==0){
d=(!d);
tar[f][f1]=1;
}
else{
f=(int)random(0,cols);
f1=(int)random(0,rows);
}
}
if(b==1){
start=new PVector(0,random(height));
}else if(b==2){
start=new PVector(width,random(height));
}else if(b==3){
start=new PVector(random(width),0);
}else if(b==4){
start=new PVector(random(width),height);
}
target=new PVector(((width/2)+(f*s)-((cols/2)*s)+(s/2)+65),((height/2)+(f1*s)-((rows/2)*s)+(s/2)));
}
void update(int i){
cur=PVector.lerp(start,target,lerp);
if(abs(cur.x-target.x)<2 && abs(cur.x-target.x)<2){
people.remove(i);
grid[f][f1]=2;
}else if(abs(cur.x-((width/2)+(Cx*s)-((cols/2)*s)+(s/2)+65))<(s*.3) && abs(cur.y-((height/2)+(Cy*s)-((rows/2)*s)+(s/2)))<(s*.3)){
people.remove(i);
tar[f][f1]=0;
}else{
stroke(0);
fill(200,0,0);
ellipse(cur.x,cur.y,(s*.6),(s*.6));
}
if(lerp<1.0){
lerp+=rate;
}
}
}