xxxxxxxxxx
//variables
var xPosition = 0;
var yPosition = 0;
var headxPos1 = 0;
var headyPos1 = 0;
var bodyxPos1 = 0;
var bodyyPos1 = 0;
var hand1xPos1 = 0;
var hand1yPos1 = 0;
var hand2xPos1 = 0;
var hand2yPos1 = 0;
var foot1xPos1 = 0;
var foot1yPos1 = 0;
var foot2xPos1 = 0;
var foot2yPos1 = 0;
var bodyr = 242;
var bodyg = 0;
var bodyb = 137;
//Variables for Distance
var afroxPos1 = 330;
var afroyPos1 = 180;
var afropuffxPos1 = 27;
var afropuffyPos1 = 200;
var afropuffxPos2 = 100;
var afropuffyPos2 = 200;
var wapxPos1 = 200;
var wapyPos1 = 190;
var straighthairxPos1 = 420;
var straighthairyPos1 = 130;
var bobxPos1 = 560;
var bobyPos1 = 130;
var ponytailxPos1 = 760;
var ponytailyPos1 = 160;
var ponytailxPos2 = 750;
var ponytailyPos2 = 170;
var d1;
var d2;
var d3;
var d4;
var d5;
var d6;
var timer = 0;
var timerFunction;
var iFunction;
var didcharacterhitPosition;
var didUserWin;
var winningFunction;
var didUserLose;
var losingFunction;
//Variable for Objects
var confetti;
var confetti1;
var confetti2;
var confetti3;
var confetti4;
var confetti5;
var confetti6;
var confetti7;
var confetti8;
function setup() {
createCanvas(800, 400);
headxPos1 = 200;
headyPos1 = 195;
bodyxPos1 = 200;
bodyyPos1 = 300;
hand1xPos1 = 175;
hand1yPos1 = 330;
hand2xPos1 = 220;
hand2yPos1 = 330;
foot1xPos1 = 175;
foot1yPos1 = 370;
foot2xPos1 = 220;
foot2yPos1 = 370;
body = ellipse(bodyxPos1, bodyyPos1, 100, 125);
setTimeout(timerFunction, 3000);
iFunction = setInterval(intervalFunction, 1000);
time = 0;
confetti = new Confetti();
confetti1 = new Confetti();
confetti2 = new Confetti();
confetti3 = new Confetti();
confetti4 =new Confetti();
confetti5 =new Confetti();
confetti6=new Confetti();
confetti7=new Confetti();
confetti8= new Confetti();
winningFunction();
losingFunction();
}
function draw() {
frameRate(2);
background(134, 211, random(254));
//afropuffs
fill(0)
ellipse(afropuffxPos1, afropuffyPos1, 90, 100)
ellipse(afropuffxPos2, afropuffyPos2, 90, 100);
//afro
fill(0);
ellipse(afroxPos1, afroyPos1, 120, 120);
//top knot
fill(0)
ellipse(200, 120, 70, 70);
ellipse(200, 150, 85, 85);
ellipse(200, 190, 90, 90);
//Signtext
fill(242, 0, 137);
textSize(50);
text('Hair Salon', 265, 50);
//afropuffs text
fill(242, 0, 137);
textSize(25);
text('afro puffs', 20, 135);
//wap text
fill(242, 0, 137);
textSize(25);
text('WAP', 170, 130);
//afro
fill(242, 0, 137);
textSize(25);
text('afro', 315, 120);
//straight hair
fill(0);
rect(straighthairxPos1, straighthairyPos1, 100, 200);
//straight hair text
fill(242, 0, 137);
textSize(25);
text('straight hair', 400, 115);
//bob
fill(0);
rect(bobxPos1, bobyPos1, 100, 130);
//bobtext
fill(242, 0, 137);
textSize(25);
text('bob', 595, 125);
//ponytail bun
fill(0);
ellipse(ponytailxPos1, ponytailyPos1, 60, 80);
rect(ponytailxPos2, ponytailyPos2, 45, 300);
//ponytail text
fill(242, 0, 137);
textSize(25);
text('ponytail', 700, 110);
//head
fill(84, 11, 14);
ellipse(headxPos1, headyPos1, 85, 85);
//body
fill(bodyr, bodyg, bodyb);
ellipse(bodyxPos1, bodyyPos1, 100, 125);
//hand1
fill(84, 11, 14);
ellipse(hand1xPos1, hand1yPos1, 25);
//hand2
fill(84, 11, 14);
ellipse(hand2xPos1, hand2yPos1, 25);
//foot1
fill(84, 11, 14);
ellipse(foot1xPos1, foot1yPos1, 50);
//foot2
fill(84, 11, 14);
ellipse(foot2xPos1, foot2yPos1, 50);
//WINNING IF STATEMENT
d1 = dist(headxPos1, headyPos1, afropuffxPos1 + 30, afropuffyPos1);
d2 = dist(headxPos1, headyPos1, wapxPos1, wapyPos1);
d3 = dist(headxPos1, headyPos1, afroxPos1, afroyPos1);
d4 = dist(headxPos1, headyPos1, straighthairxPos1, straighthairyPos1);
d5 = dist(headxPos1, headyPos1, bobxPos1, bobyPos1);
d6 = dist(headxPos1, headyPos1, ponytailxPos1, ponytailyPos1);
if (timer == 10) {
if (d1 < 20) {
print("HIT");
fill(242,0,137);
textSize(40);
text('We love your Puff!',250,370);
winningFunction();
} else if (d2 < 20) {
fill(242,0,137);
textSize(30);
text('WAP or Wet Afro Products!',250,380);
winningFunction();
} else if (d3 < 20) {
fill(242,0,137);
textSize(30);
text('When in Doubt Wear your Hair OUT!',200,370);
winningFunction();
} else if (d4 < 90) {
fill(242,0,137);
textSize(30);
text('School Pictures Here We Come!',200,370);
winningFunction();
} else if (d5 < 90) {
fill(242,0,137);
textSize(40);
text('Okay James Brown!',200,370);
fill(242, 0, 137)
textSize(15);
text('BONUS POINT' ,280,310);
winningFunction();
} else if (d6 < 20) {
fill(242,0,137);
textSize(40);
text('Inches!',250,370);
winningFunction();
} else {
losingFunction();
}
}
// end of timer code
else {
//directions text
fill(242, 0, 137);
textSize(20);
text('Choose a Hairstyle Before Time Runs Out', 200, 80);
text('Try Reaching the Bob for a Bonus Point!', 250, 360);
text('Timer',40,80);
text(timer,110,80);
}
}
//special functions
//key press interactions
function keyPressed() {
if (keyCode === UP_ARROW) {
hand1yPos1 = hand1yPos1 - 10;
headyPos1 = headyPos1 - 10;
bodyyPos1 = bodyyPos1 - 10;
hand2yPos1 = hand2yPos1 - 10;
foot1yPos1 = foot1yPos1 - 10;
foot2yPos1 = foot2yPos1 - 10;
} else if (keyCode === DOWN_ARROW) {
hand1yPos1 = hand1yPos1 + 10;
headyPos1 = headyPos1 + 10;
bodyyPos1 = bodyyPos1 + 10;
hand2yPos1 = hand2yPos1 + 10;
foot1yPos1 = foot1yPos1 + 10;
foot2yPos1 = foot2yPos1 + 10;
} else if (keyCode === LEFT_ARROW) {
hand1xPos1 = hand1xPos1 - 10;
hand2xPos1 = hand2xPos1 - 10;
headxPos1 = headxPos1 - 10;
bodyxPos1 = bodyxPos1 - 10;
foot1xPos1 = foot1xPos1 - 10;
foot2xPos1 = foot2xPos1 - 10;
} else if (keyCode === RIGHT_ARROW) {
hand1xPos1 = hand1xPos1 + 10;
hand2xPos1 = hand2xPos1 + 10;
headxPos1 = headxPos1 + 10;
bodyxPos1 = bodyxPos1 + 10;
foot1xPos1 = foot1xPos1 + 10;
foot2xPos1 = foot2xPos1 + 10;
}
}
function winningFunction() {
confetti1.move();
confetti1.show();
confetti2.move();
confetti2.show();
confetti3.move();
confetti3.show();
confetti4.move();
confetti4.show();
confetti5.move();
confetti5.show();
confetti6.move();
confetti6.show();
confetti7.move();
confetti7.show();
confetti8.move();
confetti8.show();
fill(242, 0, 137);
textSize(150);
text('You Won', 120, 250);
}
function losingFunction() {
background (255,0,0);
fill(255);
textSize(100);
text('YOU LOST', 150, 250);
textSize(30);
text('Try Again!', 350, 300);
}
//mousepressed interactions
function mousePressed() {
bodyr = random(255);
bodyg = random(255);
bodyb = random(255);
}
function intervalFunction() {
print(timer);
timer += 1;
if (timer == 10) {
print("Done");
clearInterval(iFunction);
}
}
//Object Blueprints
class Confetti {
//variables
constructor() {
this.X = random(800);
this.Y = random(400);
this.color = color(random(255), random(255), random(255));
this.speed = random(5, -5);
}
show() {
fill(this.color);
rect(this.X, this.Y, 50, 30);
}
move() {
this.Y = this.Y + this.speed;
this.X = this.X + 1;
}
}