/*________________________________________________ * 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; PImage playground; PImage playgroundDark; // for sound import krister.Ess.*; AudioChannel tag; AudioChannel woohoo; AudioChannel gameMusic; AudioChannel beatUp; AudioChannel bell; AudioChannel cheers; boolean music = true; String musicState = "on"; // Gameplay parameters int gameMode = 1; // two modes 1: catch the big guy, 2: short recess String gameModeText = "Catch the big guy"; 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 recessTime = 20; // in seconds (without slowdown) int tagbackTime = 2; // in seconds int recoveryTime = 2; // in seconds float winningSize = 90; int kidInitialSize = 30; int bullyInitialSize = kidInitialSize*2; int bullyLowerSizeLimit = kidInitialSize; int bullyUpperSizeLimit = bullyLowerSizeLimit*2; int framerate = 50; boolean allOutWinner = false; // has anyone one the first to 3 int firstTo = 3; // playing first to n // 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 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 recess time int recessLimit = recessTime*framerate; int recess = recessLimit; // the actual recess timer that changes // 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'; // for text 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); playground = loadImage("playground_600x400.jpg"); playgroundDark = loadImage("playground_600x400_dark.jpg"); // for sound Ess.start(this); tag = new AudioChannel("tag.wav"); woohoo = new AudioChannel("woohoo.wav"); gameMusic = new AudioChannel("bennyhill_music.wav"); beatUp = new AudioChannel("beatup.wav"); cheers = new AudioChannel("cheers.wav"); bell = new AudioChannel("bell.wav"); tag.volume(2); beatUp.volume(2); cheers.volume(2); bell.volume(2); gameMusic.volume(2); size(600, 400); draw_background(); smooth(); frameRate(framerate); set_random_IT(); // create Kids and bullies create_kids(); setITs(IT); create_bullies(); // set the scene cheers.play(1); 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); } } } for (int i=0;i=winningSize){ kids[IT].addWin(); gameMusic.stop(); woohoo.play(1); check_all_out_winner(); gameState = 2; } } void check_winner_mode2(){ if (recess==0){ kids[IT].addWin(); gameMusic.stop(); woohoo.play(1); bell.play(1); recess = recessLimit; check_all_out_winner(); gameState = 2; } } void check_all_out_winner(){ if (kids[IT].getNumberOfWins()>=firstTo){ allOutWinner = true; } } 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); } } // cycle the gameMode if ((key == 'm') || (key == 'M')){ if (gameMode == 1){ gameMode = 2; gameModeText = "Saved by the bell"; println("Timed Mode"); } else if (gameMode == 2){ gameMode = 1; gameModeText = "Catch the big guy"; println("Grow mode"); } } // toggle music 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); } } }