class Kid { float xPos, yPos; float initialSize, size; float[] v = new float[2]; float moveSpeed = 5; boolean IT = false; boolean beatenUp = false; int playerNumber = 0; int numberOfWins = 0; // not IT color int R = 0; int G = 0; int B = 255; // IT color int tagAnimationColorR = 255; int tagAnimationColorG = 255; int tagAnimationColorB = 0; color pixelTrailColor = color(R,G,B); color haloColor = color(255,255,0); float winningChange; float numberSteps; float colorIncrement; // tagback and fade timing int tagback = tagbackLimit+1; // beaten up recovery time int recovery = recoveryLimit+1; // for showing the location int locationTimer = fadeLimit+1; int initialShowLocationColorR = 255; int initialShowLocationColorG = 255; int initialShowLocationColorB = 255; int showLocationColorR = initialShowLocationColorR; int showLocationColorG = initialShowLocationColorG; int showLocationColorB = initialShowLocationColorB; color showLocationColor = color(showLocationColorR, showLocationColorG, showLocationColorB); //the touching distance to each other player float[] touching_distance = new float[numberOfPlayers]; // Constructor Kid(int x, int y, int s, int p) { xPos = x; yPos = y; initialSize = s; size = initialSize; playerNumber = p; winningChange = winningSize - initialSize; numberSteps = winningChange/growSpeed; colorIncrement = 255/numberSteps; if (colorIncrement<1){colorIncrement=1;} // covers for rounding to 0 } //SET methods //-------------------------------------- void setVelocity(int velocX, int velocY){ v[0] = velocX*moveSpeed; v[1] = velocY*moveSpeed; } void setColors (int r, int g, int b){ R = r; G = g; B = b; pixelTrailColor = color(R,G,B); } void setLocation(int x, int y){ xPos = x; yPos = y; } void setSize (float s){ size = s; } void setNotIT (){ IT = false; } void setIT (){ IT = true; } void setLocationTimer(int t){ locationTimer = t; } void setShowLocationColor(int r, int g, int b){ showLocationColor = color(r, g, b); } void reset_show_location_color(){ showLocationColor = color(initialShowLocationColorR, initialShowLocationColorG, initialShowLocationColorB); showLocationColorR = initialShowLocationColorR; showLocationColorG = initialShowLocationColorG; showLocationColorB = initialShowLocationColorB; } // in case it comes in handy void setMoveSpeed(int s){ moveSpeed = s; } void setTagback(int t){ tagback = t; } void setRecovery(int r){ recovery = r; } void grow(float g){ size = size + g; //println("growing "+ size); } void shrink(float s){ if (size>initialSize){ size = size - s; //println("shrinking!"); } } /* removing the color changing during tag void changeColor(){ ITG = ITG-int(colorIncrement); }*/ void addWin(){ numberOfWins = numberOfWins + 1; } void setBeatenUp(){ beatenUp = true; } void setNotBeatenUp(){ beatenUp = false; } //-------------------------------------- //GET methods //-------------------------------------- // returnd the xPos and yPos values of the Kid float[] getPos(float[] positionVals) { positionVals[0] = xPos; positionVals[1] = yPos; return positionVals; } float getx(){ return xPos; } float gety(){ return yPos; } float getSize(){ return size; } int getPlayerNumber(){ return playerNumber; } int getTagback(){ return tagback; } int getRecovery(){ return recovery; } int getNumberOfWins(){ return numberOfWins; } color getColor(){ return pixelTrailColor; } boolean getBeatenUp(){ return beatenUp; } //-------------------------------------- //CALCULATING methods //-------------------------------------- void check_distances(){ float xDist = 0; float yDist = 0; float hypothenuse = 0; for (int i = 0; i < kids.length; i++){ //println("kid length in check distances: "+kids.length); float[] posKid2 = new float[2]; float[] kidComparePos = kids[i].getPos(posKid2); //println("Kid "+i+"= x("+kidComparePos[0]+"), y("+kidComparePos[1]+")"); xDist = xPos-kidComparePos[0]; yDist = yPos-kidComparePos[1]; hypothenuse = sqrt(pow(xDist,2)+pow(yDist,2)); touching_distance[i] = hypothenuse - size/2 - kids[i].getSize()/2; //println("touching_distance["+i+"] ="+touching_distance[i]); } } int check_for_tag(int whoIsIT){ check_distances(); for(int i=0; itagbackLimit)){ tag.play(1); justTagged = whoIsIT; //set the player who tagged as justTagged whoIsIT = i; //then set the person who is now IT //play a mini tag animation kids[whoIsIT].tag_animation(); // set the IT player to go faster kids[whoIsIT].setMoveSpeed(8); // fix the player who just tagged someone kids[justTagged].setTagback(0); //kids[justTagged].reset_IT_colors(); kids[justTagged].setMoveSpeed(5); if (firstTag==0){firstTag=1;} } } return whoIsIT; } //OTHER methods //-------------------------------------- void increment_tag_timer(){ if(tagback<=tagbackLimit){ tagback = tagback+1; } } void increment_recovery_timer(){ if(recovery<=recoveryLimit){ recovery = recovery+1; if(recovery==recoveryLimit+1){ setNotBeatenUp(); } } //print(recovery+" "); } /*void reset_IT_colors(){ ITR = 255; ITG = 255; ITB = 0; }*/ void draw_trail(){ back.beginDraw(); //back.noStroke(); back.fill(0xFFFF0000); back.ellipse( xPos, yPos, size, size ); back.endDraw(); image(back, xPos, yPos); } void tag_animation(){ fill(255, 255, 255,80); strokeWeight(2); stroke(tagAnimationColorR, tagAnimationColorG, tagAnimationColorB); ellipse(xPos, yPos, size+10, size+10); } void move() { // checks on bumping into the side when moving if (((xPos+v[0]+(size/2))<=myWidth) && (0<=(xPos-(size/2)+v[0]))){ xPos = xPos + v[0]; } if(((yPos+v[1]+(size/2))<=myHeight) && (0<=(yPos-(size/2)+v[1]))){ yPos = yPos + v[1]; } // allow movement back in if they grow over the side if (((xPos + (size/2))>=myWidth)&&(v[0]<0)){ xPos = xPos + v[0]; } if (((xPos -(size/2))<=0)&&(v[0]>0)){ xPos = xPos + v[0]; } if (((yPos + (size/2))>=myHeight)&&(v[1]<0)){ yPos = yPos + v[1]; } if (((yPos -(size/2))<=0)&&(v[1]>0)){ yPos = yPos + v[1]; } } void display() { // draw halo if they're IT if (IT == true){ strokeWeight(8); stroke(haloColor); } else if (IT == false){ strokeWeight(2); stroke(R-20, G-20, B-20); } // make them a different color if they're beaten up if (getBeatenUp()){ fill(R-100, G-100, B-100); ellipse(xPos, yPos, size, size); draw_beaten_up_face(); } else if (!getBeatenUp()){ fill(R,G,B); ellipse(xPos, yPos, size, size); draw_happy_face(); } //draw_trail(); // for showing the location of the players if (locationTimer<=fadeLimit){ show_location(); locationTimer = locationTimer+1; update_show_location_color(); } else if (locationTimer>fadeLimit){ reset_show_location_color(); } } // for drawing the players wherever you want void display(int x, int y, int s){ if (IT == true){ fill(R,G,B); strokeWeight(8); stroke(haloColor); } else if (IT == false){ fill(R,G,B); strokeWeight(2); stroke(R-20, G-20, B-20); } ellipse(x, y, s, s); if (IT == true){ draw_happy_face(x, y, s); } else { draw_unhappy_face(x,y,s); } } // add a face to the players void draw_happy_face(){ int eyeSize; float radius = size/2; if (int(size/10)<1){ eyeSize = 1; } else{ eyeSize = int(size/10); } // smile stroke(255,255,255); strokeWeight(eyeSize/2); noFill(); arc(xPos, yPos, size/2, size/2, PI/8, 7*PI/8); // eyes noStroke(); fill(255,255,255); ellipse((xPos+(radius/3)), (yPos-(radius/3)), eyeSize, eyeSize); noStroke(); fill(255,255,255); ellipse((xPos-(radius/3)), (yPos-(radius/3)), eyeSize, eyeSize); } // for drawing the faces at a specific location (called by the overloaded display method) void draw_happy_face(int x, int y, int s){ int eyeSize; float radius = s/2; if (int(s/10)<1){ eyeSize = 1; } else{ eyeSize = int(s/10); } // smile stroke(255,255,255); strokeWeight(eyeSize/2); noFill(); arc(x, y, s/2, s/2, PI/8, 7*PI/8); // eyes noStroke(); fill(255,255,255); ellipse((x+(radius/3)), (y-(radius/3)), eyeSize, eyeSize); noStroke(); fill(255,255,255); ellipse((x-(radius/3)), (y-(radius/3)), eyeSize, eyeSize); } void draw_unhappy_face(){ int eyeSize; float radius = size/2; if (int(size/10)<1){ eyeSize = 1; } else{ eyeSize = int(size/10); } // smile stroke(255,255,255); strokeWeight(eyeSize/2); noFill(); arc(xPos, yPos+size/2, 3*size/4, size/2, PI+PI/4, PI+3*PI/4); // eyes noStroke(); fill(255,255,255); ellipse((xPos+(radius/3)), (yPos-(radius/3)), eyeSize, eyeSize); noStroke(); fill(255,255,255); ellipse((xPos-(radius/3)), (yPos-(radius/3)), eyeSize, eyeSize); } // for drawing the faces at a specific location (called by the overloaded display method) void draw_unhappy_face(int x, int y, int s){ int eyeSize; float radius = s/2; if (int(s/10)<1){ eyeSize = 1; } else{ eyeSize = int(s/10); } // smile stroke(255,255,255); strokeWeight(eyeSize/2); noFill(); arc(x, y+2*s/5, 3*s/4, s/2, PI+PI/4, PI+3*PI/4); // eyes noStroke(); fill(255,255,255); ellipse((x+(radius/3)), (y-(radius/3)), eyeSize, eyeSize); noStroke(); fill(255,255,255); ellipse((x-(radius/3)), (y-(radius/3)), eyeSize, eyeSize); } void draw_beaten_up_face(){ int strokeWidth = 1; float radius = size/2; color beatenUpFeatures = color(180,180,180); if (int(size/10)<1){ strokeWidth = 1; } else{ strokeWidth = int(size/10); } // mouth stroke(beatenUpFeatures); strokeWeight(strokeWidth/2); noFill(); line(xPos-(radius/3),yPos+(radius/2), xPos+(radius/3),yPos+(radius/2)); // eyes stroke(beatenUpFeatures); //Left eye //top line line(xPos-(radius/2),yPos-(radius/3),xPos-(radius/4),yPos); // bottom line line(xPos-((2*radius)/3),yPos,xPos-(radius/4),yPos); //Right eye //top line line(xPos+(radius/2),yPos-(radius/3), xPos+(radius/4),yPos); // bottom line line(xPos+((2*radius)/3),yPos, xPos+(radius/4),yPos); } // for showing the location of the players void show_location() { noFill(); strokeWeight(2); stroke(showLocationColor); ellipse(xPos, yPos, size+10, size+10); } void update_show_location_color(){ showLocationColorR = showLocationColorR-5; showLocationColorG = showLocationColorG-5; showLocationColorB = showLocationColorB-5; setShowLocationColor(showLocationColorR, showLocationColorG, showLocationColorB); } }