import krister.Ess.*; int framerate = 30; int tagbackTime = 2; // in seconds int tagbackLimit = tagbackTime*framerate; int IT = 0; // IT is the player number who is IT. All others are not IT int ITx = 0; int ITy = 0; int myWidth = 400; int myHeight = 400; int justTagged = 0; // justTagged is the player who just tagged int tagback1 = tagbackLimit+1; // tagbacks are the counters for no tag back time int tagback2 = tagbackLimit+1; int tagback3 = tagbackLimit+1; int tagback4 = tagbackLimit+1; //coordinates of players int x1 = myWidth-50;; int y1 = myHeight-50; int x2 = 50; int y2 = myHeight-50; int x3 = 50; int y3 = 50; int x4 = myWidth-50; int y4 = 50; int gameState = 1; //IT colors int ITR = 255; int ITG = 0; int ITB = 0; //not IT colors int notItR = 0; int p1R = 0; int p2R = 0; int p3R = 0; int p4R = 0; int notItG = 255; int p1G = 0; int p2G = 0; int p3G = 0; int p4G = 0; int notItB = 255; int p1B = 0; int p2B = 0; int p3B = 0; int p4B = 0; AudioChannel tag; AudioChannel music; void setup(){ size(400, 400); // size of the window background(102); //background color Ess.start(this); tag = new AudioChannel("tag.wav"); tag.volume(7); IT = int(random(1,4.45)); println("it = " + IT); PFont titleFont; titleFont = loadFont("ShowcardGothic-Reg-48.vlw"); textFont(titleFont, 25); // active and size 25 textAlign(LEFT); frameRate(framerate); } public void stop() { Ess.stop(); super.stop(); } void draw() { switch (gameState) { case 0: // startMenu println("we're in the start menu"); break; case 1: // playing //println("we're in playing"); draw_background(); draw_players(); check_for_tag(); increment_tagback_timers(); break; } } void increment_tagback_timers() { if (tagback1 <= tagbackLimit){ tagback1 = tagback1 + 1; println("tagback1 = " + tagback1); } else if (tagback2 <= tagbackLimit){ tagback2 = tagback2 + 1; println("tagback2 = " + tagback2); } else if (tagback3 <= tagbackLimit){ tagback3 = tagback3 + 1; println("tagback3 = " + tagback3); } else if (tagback4 <= tagbackLimit){ tagback4 = tagback4 + 1; println("tagback4 = " + tagback4); } } // Drawing players void draw_players() { if (IT == 1) { //println ("first IF"); p1R = ITR; p1G = ITG; p1B = ITB; p2R = notItR; p2G = notItG; p2B = notItB; p3R = notItR; p3G = notItG; p3B = notItB; p4R = notItR; p4G = notItG; p4B = notItB; } else if (IT == 2) { //println ("second IF"); p1R = notItR; p1G = notItG; p1B = notItB; p2R = ITR; p2G = ITG; p2B = ITB; p3R = notItR; p3G = notItG; p3B = notItB; p4R = notItR; p4G = notItG; p4B = notItB; } else if (IT == 3) { //println ("third IF"); p1R = notItR; p1G = notItG; p1B = notItB; p2R = notItR; p2G = notItG; p2B = notItB; p3R = ITR; p3G = ITG; p3B = ITB; p4R = notItR; p4G = notItG; p4B = notItB; } else if (IT == 4) { //println ("fourth IF"); p1R = notItR; p1G = notItG; p1B = notItB; p2R = notItR; p2G = notItG; p2B = notItB; p3R = notItR; p3G = notItG; p3B = notItB; p4R = ITR; p4G = ITG; p4B = ITB; } // Alter tagback colors while you're untouchable if (tagback1 < tagbackLimit){ p1R = ITR-(tagback1*3); p1G = ITG+75+(tagback1*3); p1B = ITB+75+(tagback1*3); } if (tagback2 < tagbackLimit){ p2R = ITR-(tagback2*3); p2G = ITG+75+(tagback2*3); p2B = ITB+75+(tagback2*3); } if (tagback3 < tagbackLimit){ p3R = ITR-(tagback3*3); p3G = ITG+75+(tagback3*3); p3B = ITB+75+(tagback3*3); } if (tagback4 < tagbackLimit){ p4R = ITR-(tagback4*3); p4G = ITG+75+(tagback4*3); p4B = ITB+75+(tagback4*3); } // Draw all the players fill(p1R, p1G, p1B); rect(x1, y1, 10, 10); fill(p2R, p2G, p2B); rect(x2, y2, 10, 10); fill(p3R, p3G, p3B); rect(x3, y3, 10, 10); fill(p4R, p4G, p4B); rect(x4, y4, 10, 10); } void draw_background() { background(102); fill(255, 255, 255); textSize(25); text("Red is it! \nNot red? RUN!", myWidth/2, myHeight/6); textSize(16); text("p1: cursors \np2: x,v,d,c \np3: q,e,2,w \np4: j,l,i,k", myWidth/8, (3*myHeight)/4); } // Tag check void check_for_tag(){ if (IT == 1){ ITx = x1; ITy = y1; if ((ITx == x2) && (ITy == y2) && (tagback2 > tagbackLimit)){ IT = 2; tag.play(1); tagback1=0; } if ((ITx == x3) && (ITy == y3) && (tagback3 > tagbackLimit)){ IT = 3; tag.play(1); tagback1=0; } if ((ITx == x4) && (ITy == y4) && (tagback4 > tagbackLimit)){ IT = 4; tag.play(1); tagback1=0; } } else if (IT == 2){ ITx = x2; ITy = y2; if ((ITx == x1) && (ITy == y1) && (tagback1 > tagbackLimit)){ IT = 1; tag.play(1); tagback2=0; } if ((ITx == x3) && (ITy == y3) && (tagback3 > tagbackLimit)){ IT = 3; tag.play(1); tagback2=0; } if ((ITx == x4) && (ITy == y4) && (tagback4 > tagbackLimit)){ IT = 4; tag.play(1); tagback2=0; } } else if (IT == 3){ ITx = x3; ITy = y3; if ((ITx == x1) && (ITy == y1) && (tagback1 > tagbackLimit)){ IT = 1; tag.play(1); tagback3 = 0; } if ((ITx == x2) && (ITy == y2) && (tagback2 > tagbackLimit)){ IT = 2; tag.play(1); tagback3 = 0; } if ((ITx == x4) && (ITy == y4) && (tagback4 > tagbackLimit)){ IT = 4; tag.play(1); tagback3 = 0; } } else if (IT == 4){ ITx = x4; ITy = y4; if ((ITx == x1) && (ITy == y1) && (tagback1 > tagbackLimit)){ IT = 1; tag.play(1); tagback4 = 0; } if ((ITx == x2) && (ITy == y2) && (tagback2 > tagbackLimit)){ IT = 2; tag.play(1); tagback4 = 0; } if ((ITx == x3) && (ITy == y3) && (tagback3 > tagbackLimit)){ IT = 3; tag.play(1); tagback4 = 0; } } } // Keys void keyPressed(){ //Player 1 if (keyCode == UP) { y1= y1-10; } if (keyCode == DOWN) { y1= y1+10; } if (keyCode == RIGHT) { x1= x1+10; } if (keyCode == LEFT) { x1= x1-10; } //Player 2 if ((key == 'd') || (key == 'D')) { y2= y2-10; } if ((key == 'c') || (key == 'C')) { y2= y2+10; } if ((key == 'v') || (key == 'V')) { x2= x2+10; } if ((key == 'x') || (key == 'x')) { x2= x2-10; } //Player 3 if ((key == '2') || (key == '@')) { y3= y3-10; } if ((key == 'w') || (key == 'W')) { y3= y3+10; } if ((key == 'e') || (key == 'E')) { x3= x3+10; } if ((key == 'q') || (key == 'Q')) { x3= x3-10; } //Player 4 if ((key == 'i') || (key == 'I')) { y4= y4-10; } if ((key == 'k') || (key == 'K')) { y4= y4+10; } if ((key == 'l') || (key == 'L')) { x4= x4+10; } if ((key == 'j') || (key == 'J')) { x4= x4-10; } }