class Kid { float xPos, yPos; float initialSize, size; float[] v = new float[2]; float moveSpeed = 5; boolean IT = false; int playerNumber = 0; int numberOfWins = 0; // not IT color int R = 0; int G = 0; int B = 255; // IT color int ITR = 255; int ITG = 255; int ITB = 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; // 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 grow(float g){ size = size + g; //println("growing "+ size); } void shrink(float s){ if (size>initialSize){ size = size - s; //println("shrinking!"); } } void changeColor(){ ITG = ITG-int(colorIncrement); } void addWin(){ numberOfWins = numberOfWins + 1; } //-------------------------------------- //GET methods //-------------------------------------- // returnd the xPos and yPos values of the Kid float[] getPos(float[] positionVals) { positionVals[0] = xPos; positionVals[1] = yPos; return positionVals; } float getSize(){ return size; } int getPlayerNumber(){ return playerNumber; } int getTagback(){ return tagback; } int getNumberOfWins(){ return numberOfWins; } color getColor(){ return pixelTrailColor; } //-------------------------------------- //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; } //println("tagback "+playerNumber+":"+tagback); } void reset_IT_colors(){ ITR = 255; ITG = 255; ITB = 0; } void update_pixel_trail(){ // updates the colors of the pixels in a cross around the center //center pixels[int(yPos)*width+int(xPos)] = color(R+50,G+50,B+50, 40); pixels[int(yPos)*width+int(xPos+1)] = color(R,G,B, 5);// center right pixels[int(yPos)*width+int(xPos-1)] = color(R,G,B, 5);// center left // complete other parts of 9 square pixels[int(yPos-1)*width+int(xPos-1)] = color(R,G,B, 2);// top left pixels[int(yPos-1)*width+int(xPos)] = color(R,G,B, 5);// top center pixels[int(yPos-1)*width+int(xPos+1)] = color(R,G,B,2);// top right pixels[int(yPos+1)*width+int(xPos-1)] = color(R,G,B, 2);// bottom left pixels[int(yPos+1)*width+int(xPos)] = color(R,G,B, 5);// bottom center pixels[int(yPos+1)*width+int(xPos+1)] = color(R,G,B, 2);// bottom right // far edges of cross pixels[int(yPos)*width+int(xPos+2)] = color(R,G,B, 98);// center extreme right pixels[int(yPos)*width+int(xPos-2)] = color(R,G,B, 98);// center extreme left pixels[int(yPos+2)*width+int(xPos)] = color(R,G,B, 98);// bottom extreme center pixels[int(yPos-2)*width+int(xPos)] = color(R,G,B, 98);// top extreme center } 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,20); strokeWeight(2); stroke(ITR, ITG, ITB); 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() { if (IT == true){ //fill(ITR, ITG, ITB); //stroke(ITR-10, ITG, ITB); fill(R,G,B); strokeWeight(8); stroke(haloColor); } else if (IT == false){ strokeWeight(2); fill(R, G, B); stroke(R-20, G-20, B-20); } ellipse(xPos, yPos, size, size); textAlign(CENTER); textFont(smallFont, 16); fill(255,255,255,90); text(playerNumber+1, xPos, yPos-(size/2)-10); textAlign(LEFT); draw_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(); } } // add a face to the players void draw_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 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); } }