/* Creator: Andy Dang Intro to Media Computation Sept 30, 2017 Instructor: Nicolas Hesler Assignment #2 This is a program I made for the interactive toy. I made a two player game were players mash a certain key ("o" and "w"). While the player mashes balloons at the bottom of the keys grow bigger and bigger till it pops. */ //Variables for all the player mechanics float playerOne; float playerTwo; float playerOneScore; float playerTwoScore; float time; //Variable for the Start Button float startX = 150, startY = 190, startW = 100, startH = 50; //Booleans for the various states the game checks when it goes through each transition boolean playerState1 = false; boolean playerState2 = false; boolean winState1 = false; boolean winState2 = false; boolean startButton = false; boolean showMainMenu = false; boolean doCountDown = false; boolean begin = false; void setup() { size(400, 400); frameRate(60); smooth(2); } void draw() { //Opens to the main menu if false if (showMainMenu == false) { mainMenu(); } //Opens to the countdown once the user clicks the start button if (doCountDown == true) { countdown(); } //Loads the core game once every check is true if (startButton == true && doCountDown == true && begin == true) { background(200, 200, 200); drawPlayerOne(); drawPlayerTwo(); scoreCounter(); balloonOne(); balloonTwo(); } } //Draws out the entire main Menu void mainMenu() { //Rectangle to help with the repition of the text being drawn over and over again rectMode(CORNERS); stroke(0); fill(200, 200, 200); rect(0, 400, 400, 0); //Instructions textSize(30); fill(0); text("MASH", 160, 80); textSize(15); text("The Two Player Game", 120, 100); textSize(10); text("Player One will be the key w.", 130, 120); text("Player Two will be the key o.", 130, 140); text("The first person to pop their balloon wins!", 100, 160); textSize(30); //Start Button rectMode(CORNER); fill(200, 200, 200); rect(startX, startY, startW, startH); fill(0); text("START", 154, 225); } //The countdown after the start button is pressed void countdown() { if (doCountDown == true) { time++ ; //Time is incremented so that when it reaches a certain value it will "countdown" by show //different numbers. if (time >= 1) { rectMode(CORNERS); fill(200, 200, 200); rect(0, 400, 400, 0); fill(0); textSize(100); text("3", 160, 300); } if (time >= 60) { rectMode(CORNERS); fill(200, 200, 200); rect(0, 400, 400, 0); fill(0); textSize(100); text("2", 160, 300); } if (time >= 120) { rectMode(CORNERS); fill(200, 200, 200); rect(0, 400, 400, 0); fill(0); textSize(100); text("1", 160, 300); } if (time == 180) { begin = true; startButton = true; showMainMenu = true; } } } //The parameters of the start button. If the Mouse is within the box of the start you can click it void mouseClicked() { if (mouseX>startX && mouseX <startX+startW && mouseY>startY && mouseY <startY+startH && showMainMenu == false && doCountDown == false) { doCountDown = true; fill(200, 200, 200); rect(0, 400, 400, 0); } } //Drawings for the Player 1 void drawPlayerOne() { noStroke(); rectMode(CORNERS); fill(0, 0, 0, 60); rect(100, 230, 180, 140); fill(255); rect(90, 220, 170, 130); stroke(0); strokeWeight(3); fill(255); rect(100, 200, 160, 140); line(100, 200, 90, 220); line(160, 200, 170, 220); line(160, 140, 170, 130); line(100, 140, 90, 130); strokeWeight(4); line(90, 130, 170, 130); line(170, 130, 170, 220); line(170, 220, 90, 220); line(90, 220, 90, 130); textSize(50); fill(0); text("W", 110, 190); } //Drawings for Player 2 void drawPlayerTwo() { noStroke(); rectMode(CORNERS); fill(0, 0, 0, 60); rect(240, 230, 320, 140); fill(255); rect(230, 220, 310, 130); stroke(0); strokeWeight(3); fill(255); rect(240, 200, 300, 140); line(300, 140, 310, 130); line(240, 140, 230, 130); line(240, 200, 230, 220); line(300, 200, 310, 220); strokeWeight(4); line(310, 130, 230, 130); line(310, 130, 310, 220); line(230, 130, 230, 220); line(230, 220, 310, 220); textSize(50); fill(0); text("O", 250, 190); } //Checks to see if the ready state of playing is true also changes the player state to increment //Player 1 animation and check void keyPressed() { if (keyCode == 'W' && startButton == true && begin == true) { noStroke(); fill(200, 200, 200); rect(80, 240, 190, 120); fill(255); rect(100, 230, 180, 140); stroke(0); strokeWeight(3); fill(255); rect(110, 210, 170, 150); line(110, 210, 100, 230); line(170, 210, 180, 230); line(170, 150, 180, 140); line(110, 150, 100, 140); strokeWeight(4); line(100, 140, 180, 140); line(180, 140, 180, 230); line(180, 230, 100, 230); line(100, 230, 100, 140); textSize(50); fill(0); text("W", 120, 200); playerState2 = true; } //Player 2 animation and check if (keyCode =='O' && startButton == true && begin == true) { noStroke(); fill(200, 200, 200); rect(220, 240, 330, 120); fill(255); rect(240, 230, 320, 140); stroke(0); strokeWeight(3); fill(255); rect(250, 210, 310, 150); line(310, 150, 320, 140); line(250, 150, 240, 140); line(250, 210, 240, 230); line(310, 210, 320, 230); strokeWeight(4); line(320, 140, 240, 140); line(320, 140, 320, 230); line(240, 140, 240, 230); line(240, 230, 320, 230); textSize(50); fill(0); text("O", 260, 200); playerState1 = true; } } //This is the check for the key presses and increment. I had to make sure that the button when it was released //or else the player could hold down the button to gain ballon size void keyReleased() { //Once again checking the game state at different points in the "animations" to make sure no key presses if (key == 'w' && winState1 == false && startButton == true && begin == true ) { playerState1 = false; playerOneScore++; } if (key == 'o' && winState2 == false && startButton == true && begin == true) { playerState2 = false; playerTwoScore++; } } //Small animation of the balloon increasing in size void balloonOne() { if (startButton == true) { strokeWeight(2); fill(random(200), random(200), random(200), 70); ellipse(139, 320, 20, 20); //Counts the score of the Player One and if they reach a certain score the balloon will change if (playerOneScore >=10) { fill(200, 200, 200); noStroke(); ellipse(139, 290, 80, 80); stroke(0); fill(random(200), random(200), random(200), 70); strokeWeight(2); ellipse(139, 315, 30, 30); } if (playerOneScore >30) { fill(200, 200, 200); noStroke(); ellipse(139, 290, 80, 80); stroke(0); fill(random(200), random(200), random(200), 70); strokeWeight(2); ellipse(139, 310, 40, 40); } if (playerOneScore >=50) { fill(200, 200, 200); noStroke(); ellipse(139, 290, 80, 80); stroke(0); fill(random(200), random(200), random(200), 70); strokeWeight(2); ellipse(139, 305, 50, 50); } if (playerOneScore >=70) { fill(200, 200, 200); noStroke(); ellipse(139, 290, 80, 80); stroke(0); fill(random(200), random(200), random(200), 70); strokeWeight(2); ellipse(139, 300, 60, 60); } //Once the player wins the win state is set to true and the other player has no way to win if (playerOneScore >=100) { fill(200, 200, 200); noStroke(); ellipse(139, 290, 80, 80); stroke(0); strokeWeight(2); line(130, 310, 125, 302.5); line(140, 310, 140, 300); line(150, 310, 155, 302.5); winState1 = true; winState2 = false; } strokeWeight(2); line(133, 329, 130, 335); line(130, 335, 136, 333); line(136, 333, 139, 340); line(139, 340, 142, 333); line(142, 333, 148, 335); line(148, 335, 146, 329); } } //Balloon state of player 2 based on key presses. void balloonTwo() { if (startButton == true) { strokeWeight(2); fill(random(200), random(200), random(200), 70); ellipse(259, 320, 20, 20); if (playerTwoScore >=10) { fill(200, 200, 200); noStroke(); ellipse(259, 290, 80, 80); stroke(0); fill(random(200), random(200), random(200), 70); strokeWeight(2); ellipse(259, 315, 30, 30); } if (playerTwoScore >30) { fill(200, 200, 200); noStroke(); ellipse(259, 290, 80, 80); stroke(0); fill(random(200), random(200), random(200), 70); strokeWeight(2); ellipse(259, 310, 40, 40); } if (playerTwoScore >=50) { fill(200, 200, 200); noStroke(); ellipse(259, 290, 80, 80); stroke(0); fill(random(200), random(200), random(200), 70); strokeWeight(2); ellipse(259, 305, 50, 50); } if (playerTwoScore >=70) { fill(200, 200, 200); noStroke(); ellipse(259, 290, 80, 80); stroke(0); fill(random(200), random(200), random(200), 70); strokeWeight(2); ellipse(259, 300, 60, 60); } if (playerTwoScore >=100) { fill(200, 200, 200); noStroke(); ellipse(259, 290, 80, 80); stroke(0); strokeWeight(2); line(250, 310, 245, 302.5); line(260, 310, 260, 300); line(270, 310, 275, 302.5); winState1 = false; winState2 = true; } stroke(0); line(253, 329, 250, 335); line(250, 335, 256, 333); line(256, 333, 259, 340); line(259, 340, 262, 333); line(262, 333, 268, 335); line(268, 335, 266, 329); } } //The score counter determines who is the winner. Once either condition is met the counter is then //counted down so that the loser has no way to overwrite the other winner. void scoreCounter() { textSize(10); //Once the condition is met screen text appears on the screen and the game is over if (playerOneScore >= 100 && winState1 == true && winState2 == false && begin == true) { textSize(20); fill(random(255), random(255), random(255)); text("PLAYER 1 WINS", 135, 80); playerTwoScore--; } if (playerTwoScore >= 100 && winState2 == true && winState1 == false && begin == true) { textSize(20); fill(random(255), random(255), random(255)); text("PLAYER 2 WINS", 135, 80); playerOneScore--; } }