//////////////////////////
// First Round Knockout //
//////////////////////////
//Intro to Media Computation
//Instructor: Nicolas Hesler
//An interactive toy by: Jake O'Toole P01
//INSTRUCTIONS
//You have 20 seconds to knockout the opponent by making three clean punches
//the opponents health is represented by the colour of his face
//wait for the opponents face to become vulnerable
//If the opponent is on the right side of the ring, use right mouse click to throw a right hook
//If the opponent is on the left side of the ring, use left mouse click to throw a left hook
//don't cheat and spam the mouse button, pace your punches for a challenge
//Press 'b' to play as Mike Tyson
//declaring variables
//glove variables
float rgloveWobble;
float lgloveWobble;
float gloveHeight;
//random variables
float t;
float t2;
//opponents health variable
int headColour;
//mode variables
boolean miketysonMode;
boolean clicked;
//timer variable
int timeInterval;
int time;
//add custom font
PFont font;
//initializing variables
void setup() {
lgloveWobble = 0;
rgloveWobble = 0;
gloveHeight = 0;
t = 0;
t2 = 0;
headColour = 0;
miketysonMode = false;
clicked = false;
timeInterval = 20;
noCursor();
//setting canvas size
size(400, 400);
frameRate(60);
smooth();
//setting shape modes
ellipseMode(CENTER);
}
//main function
void draw() {
//firstly drawing the background assets behind everything
drawBackground();
//drawing the opponent infront of the background
drawOpponent();
//drawing your hands in front of the opponent
initializeGloves();
//mike tyson mode, on or off
mtMode();
timer();
koScreen();
}
//declaring function that will draw the background
void drawBackground() {
background(0);
rectMode(CORNERS);
// audience
//loop the camera flashes 5 times (5 ellipse on screen at once)
for (int i = 0; i < 5; i++) {
//camera flash
fill(255);
ellipse(random(width), random(height), 15, 15);
}
//ropes
stroke(255, 0, 0);
strokeWeight(4);
//red
line(175, 140, 0, 142);
line(225, 140, 400, 142);
//white
stroke(255);
line(175, 200, 0, 204);
line(225, 200, 400, 204);
line(175, 320, 0, 338);
line(225, 320, 400, 338);
//blue
stroke(0, 0, 255);
line(175, 260, 0, 272);
line(225, 260, 400, 272);
//pad
strokeWeight(2);
fill(255, 0, 0);
stroke(255);
rect(175, 120, 225, 330, 6);
rect(195, 330, 205, 360, 2);
//ring floor
strokeWeight(1);
fill(0, 0, 255);
quad(0, 380, 200, 350, 400, 380, 200, 400);
noStroke();
rect(0, 380, 400, 400);
stroke(0);
strokeWeight(2);
line(0, 383, 200, 353);
line(200, 353, 400, 383);
}
//declaring function that will draw the opponent
void drawOpponent() {
//presets for drawing opponent
strokeWeight(2);
rectMode(CENTER);
//perlin noise at specified coordinates x and y
float x = noise(t);
float y = noise(t2);
//variable that represents y and can be used globally
gloveHeight = gloveHeight + y;
//variable that will adjust speeds of random values
t = t +0.02;
t2 = t2 +0.05;
//creating random value ranges
x = map(x, 0, 1, 100, 300);
y = map(y, 0, 1, 130, 200);
//when a right punch is thrown and the enemies hands are down, aswell as they are on the right side
//of the ring, the health goes down/ head changes colour
if (clicked && y>167 && x>200 && mouseButton == RIGHT) {
headColour+=1;
clicked=false;
//same as right punch except for a left punch, mouseButton changed to left
} else if (clicked && y>167 && x<200 && mouseButton == LEFT) {
headColour+=1;
clicked=false;
//if the mouse is clicked and none of the conditionals have been filled, nothing happens, opponent
//does not lose health
} else if (clicked) {
clicked=false;
}
//head
if (headColour==0) {
fill(0, 255, 0);
ellipse(x, 140, 50, 50);
} else if (headColour==1) {
fill(255, 255, 0);
ellipse(x, 140, 50, 50);
} else if (headColour==2) {
fill(255, 0, 0);
ellipse(x, 140, 50, 50);
} else if (headColour==3) {
stroke(255);
fill(0, 0, 0);
ellipse(x, 140, 50, 50);
}
stroke(0);
fill(255);
//body
fill(255, 224, 189);
rect(x, 220, 80, 80, 8);
//arms
rect(x+20, y+50, 20, 60, 6);
rect(x-20, y+50, 20, 60, 6);
//legs
rect(x-20, 320, 20, 100, 6);
rect(x+20, 320, 20, 100, 6);
fill(0, 0, 255);
//shorts
rect(x-20, 290, 40, 60);
rect(x+20, 290, 40, 60);
rect(x+20, y+20, 20, 20);
rect(x-20, y+20, 20, 20);
//gloves
ellipse(x+35, y, 10, 10);
ellipse(x-35, y, 10, 10);
ellipse(x+20, y, 30, 30);
ellipse(x-20, y, 30, 30);
}
//declaring function that will draw first person hands
void initializeGloves() {
//right glove wrist
stroke(100, 0, 0);
fill(200, 0, 0);
//quad(270, 340, 310, 330, 330, 380, 290, 390);
quad(270, 340, 310, 330, 330, 380, 290, 390);
//left glove wrist
quad(90, 330, 130, 340, 110, 390, 70, 380);
//right glove palm
quad(250, 306, 300, 280, 310, 325, 270, 335);
//left palm
quad(100, 280, 150, 306, 130, 335, 90, 325);
//right glove fist
noStroke();
ellipse(260, rgloveWobble-65, 85, 80);
//left fist
ellipse(140, lgloveWobble-65, 85, 80);
//right glove thumb
stroke(100, 0, 0);
ellipse(240, rgloveWobble-60, 40, 40);
//left thumb
ellipse(160, lgloveWobble-60, 40, 40);
}
//declaring function for the extra mode with quick punches
void miketysonPunches() {
//when right mouse is pressed a right hand punch is thrown by increasing the y values of the glove ellipses
if (mousePressed && (mouseButton == RIGHT)) {
rgloveWobble = 290+(50)*sin(frameCount);
} else
rgloveWobble = 340+(5)*sin(frameCount*0.06);
{
}
//when left mouse is pressed a left hand punch is thrown by increasing the y values of the glove ellipses
if (mousePressed && (mouseButton == LEFT)) {
lgloveWobble = 290+(50)*sin(frameCount);
} else
lgloveWobble = 340+(5)*sin(frameCount*0.06);
}
void regularPunches() {
if (mousePressed && (mouseButton == RIGHT)) {
rgloveWobble = 290+(70)*sin(10);
} else
rgloveWobble = 340+(5)*sin(frameCount*0.06);
{
}
if (mousePressed && (mouseButton == LEFT)) {
lgloveWobble = 290+(70)*sin(10);
} else
lgloveWobble = 340+(5)*sin(frameCount*0.06);
}
//declaring function that switches between modes
void mtMode() {
//when b is pressed, the game mode is switched back and forth
if (keyPressed) {
if (key == 'b' || key == 'B') {
miketysonMode =! miketysonMode;
}
}
//switch punching modes
if (miketysonMode == true) {
miketysonPunches();
} else if (miketysonMode == false) {
regularPunches();
}
}
void mouseClicked() {
//creating a variable to use globally
clicked = true;
}
//declaring function for a victory screen
void koScreen() {
//this will happen when/if the user makes the final punch
if (headColour>2) {
//redraws the background over everything
drawBackground();
//custom font loaded
font = loadFont ("LithosPro-Black-70.vlw");
//text created, sized and placed at the right coords
textFont(font);
textSize (150);
fill(255, 255, 0);
text ("KO", 80, 250);
}
}
//Declaring the function that creates a 20 second timer
void timer() {
//time of 20 seconds is created
time = timeInterval-int(millis()/1000);
font = loadFont ("LithosPro-Black-70.vlw");
textFont(font);
fill(255, 255, 0);
//if the time is above 0, time is displayed at the top of canvas
if (time >= 0) {
textSize(30);
text(time, 175, 40);
//if the timer runs down to 0
} else if (time < 1) {
drawBackground();
font = loadFont ("LithosPro-Black-70.vlw");
textFont(font);
textSize (60);
fill(255, 255, 0);
text ("TOO SLOW", 20, 230);
}
}