/*
Jacob Dinis
"Potion Making 101"
Use the potion ingredients to chnage the colour of the potion!
Each ingredient changes the potion slightly.
Use many of one ingredient to change the witch's expression.
KXIcore credit: Khan-ali Ibrahim
October 11 2016
*/
// Initialize number of bubbles
int numberOfBubbles = 6;
// Initialize class for bubbles
Bubble[] bubbles = new Bubble[numberOfBubbles];
// Initialize class for Witch
Draw_Witch Witch1;
//Initialize colour variables
color red = 0;
color green = 0;
color blue = 0;
//Initialize KXI core class
KXIcore core;
void setup() {
//set up canvas size
size(800, 600);
//Turn off stroke
noStroke();
// Start for loop
for (int i = 0; i < bubbles.length; i++) {
//Spawn 6 bubbles at random positions within the screen
bubbles[i] = new Bubble(random(0, 800), random(0, 600), 2);
}
//Call class to draw witch
Witch1 = new Draw_Witch();
//Set rect and ellpise modes
rectMode(CORNERS);
ellipseMode(RADIUS);
}
void draw() {
//initilize core
core = new KXIcore(mouseX, mouseX, mousePressed);
//set framerate to provide best movement
frameRate(60);
//Set background colour
background(102, 200, 120);
//Set fill black transparent
fill(0, 150);
//Draw bounding rectangles for colour picker and reset buttons
rect(350, 600, 775, 525, 10);
rect(0, -30, 800, 50, 10);
rect(325, 90, 475, 260, 10);
// Use Kxicore to set up mouse detection on switches
//If mouse is over red button add to red value
if (core.mouseOverCorner(350, 100, 450, 150)) {
red += 3;
}
//If mouse is over green button add to green value
if (core.mouseOverCorner(350, 150, 450, 200)) {
green += 3;
}
//If mouse is over blue button add to blue value
if (core.mouseOverCorner(350, 200, 450, 250)) {
blue += 3;
}
//If mouse is over reset button drain all three values
if (core.mouseOverCorner(0, -30, 800, 50)) {
red -= 3;
green -= 3;
blue -= 3;
}
//Update and Draw for the six bubbles
for (int i = 0; i < bubbles.length; i++) {
bubbles[i].display();
bubbles[i].update();
}
//draw witch
Witch1.display();
//Change the witche's face based on values of colours
//Red will turn the witch happy if its over 200 value
if (red > 200) {
stroke(0);
line(215, 450+((float) Math.sin(frameCount * 0.02) * 10), 200, 460+((float) Math.sin(frameCount * 0.02) * 10));
line(185, 450+((float) Math.sin(frameCount * 0.02) * 10), 200, 460+((float) Math.sin(frameCount * 0.02) * 10));
noStroke();
//Green will turn the witch sad if its over 200 value
}
else if (green > 200) {
stroke(0);
line(185, 460+((float) Math.sin(frameCount * 0.02) * 10), 215, 460+((float) Math.sin(frameCount * 0.02) * 10));
noStroke();
//Blue is neutral, it wont do much.
} else {
stroke(0);
line(215, 460+((float) Math.sin(frameCount * 0.02) * 10), 200, 450+((float) Math.sin(frameCount * 0.02) * 10));
line(185, 460+((float) Math.sin(frameCount * 0.02) * 10), 200, 450+((float) Math.sin(frameCount * 0.02) * 10));
noStroke();
}
//Draw potion bottle
fill(255, 230, 179);
rect(585, 130+((float) Math.sin(frameCount * 0.01) * 10), 615, 160+((float) Math.sin(frameCount * 0.01) * 10));
fill(255, 75);
ellipse(600, 300+((float) Math.sin(frameCount * 0.01) * 10), 100, 100);
rect(575, 210+((float) Math.sin(frameCount * 0.01) * 10), 625, 150+((float) Math.sin(frameCount * 0.01) * 10));
//Set fill to white and draw text indicating what the player can interact with
fill(255);
textSize(32);
text("Select an ingredient!", 400, 580);
text("Reset", 350, 35);
//Draw the liquid in the bottle
rotate(TAU);
fill(red, green, blue);
arc(600, 300+((float) Math.sin(frameCount * 0.01) * 10), 100, 100, 0, PI);
// Draw the rectangles for the colour buttons
fill(255, 0, 0);
rect(350, 100, 450, 150);
fill(0, 255, 100);
rect(350, 150, 450, 200);
fill(0, 100, 255);
rect(350, 200, 450, 250);
}class Bubble {
//initialize variables for bubbles
float bubblePositionX;
float bubblePositionY;
float bubbleVelocityV;
//Set class for bubbles
Bubble(float x, float y, float v) {
bubblePositionX = x;
bubblePositionY = y;
bubbleVelocityV = v;
}
void display() {
//Draw bubble
ellipseMode(RADIUS);
fill(240, 60);
noStroke();
ellipse(bubblePositionX, bubblePositionY, 30, 30);
}
void update() {
//Move the bubble upwards
bubblePositionY = bubblePositionY - bubbleVelocityV;
//If the bubble reaches the top of the scree nreset to y = 0
if (bubblePositionY < 0 - 100) {
bubblePositionY = 600;
}
}
}class Draw_Witch {
void display() {
//Set fill to gray
fill(175);
//Draw witch hair
triangle(200, 100+((float) Math.sin(frameCount * 0.02) * 10), 50, 500+((float) Math.sin(frameCount * 0.02) * 10), 350, 500+((float) Math.sin(frameCount * 0.02) * 10));
triangle(50, 500+((float) Math.sin(frameCount * 0.02) * 10), 350, 500+((float) Math.sin(frameCount * 0.02) * 10), 190, 550+((float) Math.sin(frameCount * 0.02) * 10));
//Set fill black
fill(0);
//Draw body
rect(100, 525+((float) Math.sin(frameCount * 0.02) * 10), 300, 700+((float) Math.sin(frameCount * 0.02) * 10));
//set ellipse mode
ellipseMode(RADIUS);
//Det fill peachy
fill(255, 230, 207);
//Draw face
ellipse(200, 400+((float) Math.sin(frameCount * 0.02) * 10), 100, 100);
//Set rectangle mode to corners
rectMode(CORNERS);
//Draw neck
rect(175, 450+((float) Math.sin(frameCount * 0.02) * 10), 225, 527+((float) Math.sin(frameCount * 0.02) * 10));
//Draw shirt neck
triangle(175, 525+((float) Math.sin(frameCount * 0.02) * 10), 225, 525+((float) Math.sin(frameCount * 0.02) * 10), 200, 575+((float) Math.sin(frameCount * 0.02) * 10));
//Set fill to gray
fill(175);
//draw bangs
rect(100, 385+((float) Math.sin(frameCount * 0.02) * 10), 300, 325+((float) Math.sin(frameCount * 0.02) * 10));
//set fill to black
fill(0);
//Draw hat base
ellipse(200, 325+((float) Math.sin(frameCount * 0.02) * 10), 200, 50);
//Draw hat spike
triangle(200, 100+((float) Math.sin(frameCount * 0.02) * 10), 275, 300+((float) Math.sin(frameCount * 0.02) * 10), 125, 300+((float) Math.sin(frameCount * 0.02) * 10));
//Draw eyes
ellipse(250, 410+((float) Math.sin(frameCount * 0.02) * 10), 5, 10);
ellipse(150, 410+((float) Math.sin(frameCount * 0.02) * 10), 5, 10);
//Set stroke to black
stroke(0);
//Draw eyelashes
line(140, 400+((float) Math.sin(frameCount * 0.02) * 10), 150, 412+((float) Math.sin(frameCount * 0.02) * 10));
line(260, 400+((float) Math.sin(frameCount * 0.02) * 10), 250, 412+((float) Math.sin(frameCount * 0.02) * 10));
//Turn stroke back off
noStroke();
//Set fill to pink
fill(255, 200, 200);
//Draw cheeks
ellipse(140, 450+((float) Math.sin(frameCount * 0.02) * 10), 20, 20);
ellipse(260, 450+((float) Math.sin(frameCount * 0.02) * 10), 20, 20);
//Set fill to skin colour
fill(255, 230, 207);
//Draw hair detail
triangle(125, 375+((float) Math.sin(frameCount * 0.02) * 10), 120, 385+((float) Math.sin(frameCount * 0.02) * 10), 130, 385+((float) Math.sin(frameCount * 0.02) * 10));
}
}class KXIcore {
//float mouseX,
// mouseY;
//boolean mousePressed;
KXIcore(int x, int y, boolean p) {
//mouseX = x;
//mouseY = y;
//mousePressed = p;
}
boolean mouseOverCorner(float leftX, float leftY, float rightX, float rightY) {
if (mouseX > leftX && mouseX < rightX && mouseY > leftY && mouseY < rightY) {
return true;
} else {
return false;
}
}
boolean mouseClickCorner(float leftX, float leftY, float rightX, float rightY) {
if (mouseClickCorner(leftX, leftY, rightX, rightY) && mousePressed) {
return true;
} else {
return false;
}
}
boolean mouseOverCenter(float centerX, float centerY, float sizeX, float sizeY) {
float leftSide = centerX - (sizeX/2);
float rightSide = centerX + (sizeX/2);
float topSide = centerY - (sizeY/2);
float bottomSide = centerY + (sizeY/2);
if (mouseX > leftSide && mouseX < rightSide && mouseY > topSide && mouseY < bottomSide) {
return true;
} else {
return false;
}
}
boolean mouseClickCenter(float centerX, float centerY, float sizeX, float sizeY) {
if (mouseOverCenter(centerX, centerY, sizeX, sizeY) && mousePressed) {
return true;
} else {
return false;
}
}
}