/*________________________________________________ * TAG 2.0 v6 * Jonathan Hey * May 2007 * jono.hey+at+gmail.com * * CURRENT ISSUES * - use color variables * - trails are a mess * * ADVANCED TAG * 2.0 Changes * - added tag sound * - added start screen * - player select * - locate player on startscreen * - added player trails * - added in game music - on/off (BACKSPACE) * - fixed players getting stuck at the side * - add tag animation * - add scoreboard * - added bullies that track the nearest player * - added faces * * To add * - wall detection in its own method * - add special grab arm * - use threading * - thicker trails * - use alpha in trails *________________________________________________*/ // for background PGraphics back; PGraphics rectangle; PImage playground; // for sound import krister.Ess.*; AudioChannel tag; AudioChannel woohoo; AudioChannel gameMusic; boolean music = true; String musicState = "on"; // Gameplay parameters int numberOfPlayers = 4; int difficulty = 1; // related to number and speed of bullies String difficultyText = "Walk in the park"; int numberOfBullies = 0; int myWidth = 600; int myHeight = 400; float growSpeed = 0.15; float shrinkSpeed = 1.0; int tagbackTime = 2; // in seconds int recoveryTime = 2; // in seconds float winningSize = 90; int kidInitialSize = 20; int bullyInitialSize = kidInitialSize*2; int bullyLowerSizeLimit = kidInitialSize; int bullyUpperSizeLimit = bullyLowerSizeLimit*2; // start positions int kid1x = myWidth-50; int kid1y = myHeight-50; int kid2x = 50; int kid2y = myHeight-50; int kid3x = 50; int kid3y = 50; int kid4x = myWidth-50; int kid4y = 50; // bully start positions int bullyx = myWidth/2; int bullyy = myHeight/2; // for no tagback tagback int framerate = 50; int tagbackLimit = tagbackTime*framerate; int justTagged = 0; //the player number who just tagged int firstTag = 0; //to mark the first tag - only to solve the 0 player shrinking // for beaten up recovery time int recoveryLimit = recoveryTime*framerate; // for showing location int fadeTime = 1; int fadeLimit = fadeTime*framerate; // basic setup Kid[] kids = new Kid[numberOfPlayers]; Bully[] bullies = new Bully[numberOfBullies]; int gameState = 0; int IT; // IT is the player number who is currently IT // kid colors color kid1Blue = color(0,0,205); color kid2Green = color(50,205,50); color kid3Red = color(255,0,0); color kid4Black = color(0,0,0); // keys (player 1 keys are always cursors) char kid2Left = 'v'; char kid2LeftCaps = 'V'; char kid2Right = 'n'; char kid2RightCaps = 'N'; char kid2Up = 'g'; char kid2UpCaps = 'G'; char kid2Down = 'b'; char kid2DownCaps = 'B'; char kid3Left = 'a'; char kid3LeftCaps = 'A'; char kid3Right = 'd'; char kid3RightCaps = 'D'; char kid3Up = 'w'; char kid3UpCaps = 'W'; char kid3Down = 's'; char kid3DownCaps = 'S'; char kid4Left = 'j'; char kid4LeftCaps = 'J'; char kid4Right = 'l'; char kid4RightCaps = 'L'; char kid4Up = 'i'; char kid4UpCaps = 'I'; char kid4Down = 'k'; char kid4DownCaps = 'K'; PFont titleFont; PFont smallFont; void setup() { titleFont = loadFont("BaskOldFace-25.vlw"); smallFont = loadFont("BaskOldFace-16.vlw"); textFont(titleFont, 25); // active and size 25 textAlign(LEFT); // for background back = createGraphics(myWidth, myHeight, P3D); rectangle = createGraphics(50,50,P3D); playground = loadImage("playground_600x400.jpg"); // for sound Ess.start(this); tag = new AudioChannel("tag.wav"); tag.volume(2); woohoo = new AudioChannel("woohoo.wav"); gameMusic = new AudioChannel("bennyhill_music.wav"); gameMusic.volume(3); size(600, 400); draw_background(); smooth(); frameRate(framerate); set_random_IT(); // create Kids and bullies create_kids(); setITs(IT); create_bullies(); gameState = 0; loop(); } void draw() { switch(gameState){ case 0: //start screen draw_startscreen(); for (int i = 0; i < kids.length; i++){ kids[i].display(); } break; case 1: //playing draw_background(); // move and display kids for (int i = 0; i < kids.length; i++){ // don't move them if they're beaten up if (!kids[i].getBeatenUp()){ kids[i].move(); } kids[i].display(); kids[i].increment_tag_timer(); kids[i].increment_recovery_timer(); } // move and display bullies for (int i=0; i1){ kids[1] = new Kid( kid2x, kid2y, kidInitialSize, 1); kids[1].setColors(50,205,50); if(numberOfPlayers>2){ kids[2] = new Kid( kid3x, kid3y, kidInitialSize, 2); kids[2].setColors(255,0,0); if(numberOfPlayers>3){ kids[3] = new Kid( kid4x, kid4y, kidInitialSize, 3); kids[3].setColors(0,0,0); } } } } void create_bullies(){ for (int i = 0; i1){ kids[1].setSize(kidInitialSize); kids[1].setLocation(kid2x, kid2y); kids[1].setColors(50,205,50); if(numberOfPlayers>2){ kids[2].setSize(kidInitialSize); kids[2].setLocation(kid3x, kid3y); kids[2].setColors(255,0,0); if(numberOfPlayers>3){ kids[3].setSize(kidInitialSize); kids[3].setLocation(kid4x, kid4y); kids[3].setColors(0,0,0); } } } } void set_random_IT(){ IT=int(random(-0.4,(numberOfPlayers-0.51))); } void draw_background() { background(playground); // add a dark layer on top - CAUSES SLOWDOWN BUT IS NICE /* back.beginDraw(); back.background(102,102,102,80); back.endDraw(); image(back, 0, 0); */ // add text fill(255, 255, 255); textAlign(LEFT); textFont(titleFont, 25); text("Got the halo? Run!\nNo halo? Get them!", myWidth/2, myHeight/6); } void draw_startscreen() { background(playground); fill(255, 255, 255); textAlign(LEFT); textFont(titleFont, 25); text("Can you keep the halo?\nWatch for the bullies.", myWidth/4, myHeight/6); if (numberOfPlayers == 1){ text("It's just me.\nBring it on.", myWidth/4, myHeight/2); textFont(smallFont, 16); text("cursors", kid1x-kids[0].getSize()/2, kid1y+kids[0].getSize()/2+20); } else if (numberOfPlayers == 2){ text("It's a duel.\nMay the best person win.", myWidth/4, myHeight/2); textFont(smallFont, 16); text("cursors", kid1x-kids[0].getSize()/2, kid1y+kids[0].getSize()/2+20); text("v,n,g,b", kid2x-kids[1].getSize()/2, kid2y+kids[1].getSize()/2+20); } else if (numberOfPlayers == 3){ text("It's a party.\nThere's "+numberOfPlayers+" of us.", myWidth/4, myHeight/2); textFont(smallFont, 16); text("cursors", kid1x-kids[0].getSize()/2, kid1y+kids[0].getSize()/2+20); text("v,n,g,b", kid2x-kids[1].getSize()/2, kid2y+kids[1].getSize()/2+20); text("a,d,w,s", kid3x-kids[2].getSize()/2, kid3y+kids[2].getSize()/2+20); } else if (numberOfPlayers == 4){ text("It's a party.\nThere's "+numberOfPlayers+" of us.", myWidth/4, myHeight/2); textFont(smallFont, 16); text("cursors", kid1x-kids[0].getSize()/2, kid1y+kids[0].getSize()/2+20); text("v,n,g,b", kid2x-kids[1].getSize()/2, kid2y+kids[1].getSize()/2+20); text("a,d,w,s", kid3x-kids[2].getSize()/2, kid3y+kids[2].getSize()/2+20); text("j,l,i,k", kid4x-kids[3].getSize()/2, kid4y+kids[3].getSize()/2+20); } textFont(smallFont, 16); text("Enter to start\nUse 1,2,3,4 to select number of players\nBackspace toggles music: "+musicState+"\nU to up the difficulty: " + difficultyText, myWidth/4, (3*myHeight)/4); //textSize(16); //text("Kid 1: cursors \nKid 2: x,v,d,c \nKid 3: q,e,2,w \nKid 4: j,l,i,k", myWidth/8, (3*myHeight)/4); } void draw_scoreboard(int y, int h){ int scoreBoardy = y; int playerSpacing = int(myWidth/(numberOfPlayers+1)); int scoreBoardHeight = h; strokeWeight(4); stroke(180,180,180); fill(255,255,255,90); rect(0,scoreBoardy,myWidth,scoreBoardHeight); for (int i=0; i=winningSize){ kids[IT].addWin(); gameMusic.stop(); woohoo.play(1); gameState = 2; } } void setITs(int iAmIT){ for (int i=0; i=2){ //Player 2 if ((key == kid2Up) || (key == kid2UpCaps)) { kids[1].setVelocity(0,-1); } if ((key == kid2Down) || (key == kid2DownCaps)) { kids[1].setVelocity(0,1); } if ((key == kid2Right) || (key == kid2RightCaps)) { kids[1].setVelocity(1,0); } if ((key == kid2Left) || (key == kid2LeftCaps)) { kids[1].setVelocity(-1,0); } if (numberOfPlayers >=3){ //Player 3 if ((key == kid3Up) || (key == kid3UpCaps)) { kids[2].setVelocity(0,-1); } if ((key == kid3Down) || (key == kid3DownCaps)) { kids[2].setVelocity(0,1); } if ((key == kid3Right) || (key == kid3RightCaps)) { kids[2].setVelocity(1,0); } if ((key == kid3Left) || (key == kid3LeftCaps)) { kids[2].setVelocity(-1,0); } //Player 4 if (numberOfPlayers >= 4){ if ((key == kid4Up) || (key == kid4UpCaps)) { kids[3].setVelocity(0,-1); } if ((key == kid4Down) || (key == kid4DownCaps)) { kids[3].setVelocity(0,1); } if ((key == kid4Right) || (key == kid4RightCaps)) { kids[3].setVelocity(1,0);; } if ((key == kid4Left) || (key == kid4LeftCaps)) { kids[3].setVelocity(-1,0); } } // end 4 player } //end 3 player } // end 2 player } // keys for start screen: gameState 0 if (gameState == 0){ //To start initially if ((keyCode == ENTER)||(keyCode == RETURN)){ gameState=1; if (music){ gameMusic.play(5); } } if (keyCode == BACKSPACE){ if (music){ music = false; musicState = "off"; } else { music = true; musicState = "on"; } } if ((key == 'u') || (key == 'U')){ /* difficulty levels 1 = walk in the park 2 = Regular 3 = Spicy 4 = Fiendish */ if (difficulty<4){ difficulty = difficulty+1; } else if (difficulty == 4){ difficulty = 1; } if (difficulty == 1){ numberOfBullies = 0; bullyLowerSizeLimit = kidInitialSize; difficultyText = "Walk in the park"; } else if (difficulty == 2){ numberOfBullies = 1; bullyLowerSizeLimit = int(kidInitialSize*1.5); difficultyText = "Regular"; } else if (difficulty == 3){ numberOfBullies = 2; bullyLowerSizeLimit = int(kidInitialSize*2); difficultyText = "Spicy"; } else if (difficulty == 4){ numberOfBullies = 3; bullyLowerSizeLimit = int(kidInitialSize*2.5); difficultyText = "Fiendish"; } bullyUpperSizeLimit = bullyLowerSizeLimit*2; reset_game_and_startscreen(); } //select players on start screen if ((key == '1') || (key == '!')){ numberOfPlayers = 1; growSpeed = 0.2; winningSize = 100; reset_game_and_startscreen(); } if ((key == '2') || (key == '@')){ numberOfPlayers = 2; growSpeed = 0.2; winningSize = 100; reset_game_and_startscreen(); } if ((key == '3') || (key == '#')){ numberOfPlayers = 3; growSpeed = 0.2; winningSize = 80; reset_game_and_startscreen(); } if ((key == '4') || (key == '$')){ numberOfPlayers = 4; growSpeed = 0.15; winningSize = 90; reset_game_and_startscreen(); } // show player locations on key presses if ((keyCode == LEFT)||(keyCode == RIGHT)||(keyCode == UP)||(keyCode == DOWN)){ kids[0].reset_show_location_color(); kids[0].setLocationTimer(0); } if ((key == kid2Left)||(key == kid2LeftCaps)||(key == kid2Right)||(key == kid2RightCaps)||(key == kid2Up)||(key == kid2UpCaps)||(key == kid2Down)||(key == kid2DownCaps)){ kids[1].reset_show_location_color(); kids[1].setLocationTimer(0); } if ((key == kid3Left)||(key == kid3LeftCaps)||(key == kid3Right)||(key == kid3RightCaps)||(key == kid3Up)||(key == kid3UpCaps)||(key == kid3Down)||(key == kid3DownCaps)){ kids[2].reset_show_location_color(); kids[2].setLocationTimer(0); } if ((key == kid4Left)||(key == kid4LeftCaps)||(key == kid4Right)||(key == kid4RightCaps)||(key == kid4Up)||(key == kid4UpCaps)||(key == kid4Down)||(key == kid4DownCaps)){ kids[3].reset_show_location_color(); kids[3].setLocationTimer(0); } } }