//Welcome to Ice-Cream Stacker
//The object of this toy is to stack ice cream scoops onto the cone
//Use keys A and D to move the cone from left to right
//Stack the ice cream to the top and you win!
//Created by: Martin Gallagher
//Credit to Sunny and CJ O'Heany for helping me problem solve
//and show me certian code functions
//Place the variables here
int coneDirect=0;
int scoopCount=0;
//set scoop colour
int scoopColourR;
int scoopColourG;
int scoopColourB;
//colour/flavour 1 chocolate
int colourR1=97;
int colourG1=53;
int colourB1=12;
//make colour/flavour 2 vanilla
int colourR2=255;
int colourG2=229;
int colourB2=161;
//make colour/flavour 3 strawberry
int colourR3=255;
int colourG3=116;
int colourB3=129;
//make colour/flavour 4 mint
int colourR4=140;
int colourG4=255;
int colourB4=176;
float scoopY=0;
float scoopX;
//Caught RGB values
int RV1 = 0;
int GV1 = 0;
int BV1 = 0;
//second scoop stacked colour change
int RV2 = 0;
int GV2 = 0;
int BV2 = 0;
//third scoop stacked colour change
int RV3 = 0;
int GV3 = 0;
int BV3 = 0;
//fourth scoop stacked colour change
int RV4 = 0;
int GV4 = 0;
int BV4 = 0;
//fifth scoop stacked colour change
int RV5 = 0;
int GV5 = 0;
int BV5 = 0;
//sixth scoop stacked colour change
int RV6 = 0;
int GV6 = 0;
int BV6 = 0;
//seventh scoop stacked colour change
int RV7 = 0;
int GV7 = 0;
int BV7 = 0;
//win and loose conditions
boolean respawn=true;
boolean caught=false;
boolean win=false;
////////
void setup() {
//Set screen size
size(400, 400);
noStroke();
frameRate(60);
}
//draw loop and framerate
void draw() {
if (win==false) {
// println(mouseX + ", " + mouseY);
//frameRate(40);
//wall
background(112, 195, 255);
//make countertop and ledge
rectMode(CORNERS);
fill(277, 277, 277);
rect(0, 290, 400, 370);
fill(191, 191, 191);
rect(0, 370, 400, 400);
//cone
drawCone();
offScreen();
respawnScoop();
if (caught==false) {
getScoop();
}
}
}
//Draw the player/cone
void drawCone() {
fill(255, 199, 122);
rectMode(CENTER);
rect(coneDirect, 310, 40, 20);
rect(coneDirect, 320, 20, 40);
if (scoopCount>= 1) {
fill(RV1, GV1, BV1);
ellipse(coneDirect, 290, 40, 40);
}
if (scoopCount>= 2) {
fill(RV2, GV2, BV2);
ellipse(coneDirect, 250, 40, 40);
}
if (scoopCount>=3) {
fill(RV3, GV3, BV3);
ellipse(coneDirect, 210, 40, 40);
}
if (scoopCount>=4) {
fill(RV4, GV4, BV4);
ellipse(coneDirect, 170, 40, 40);
}
if (scoopCount>=5) {
fill(RV5, GV5, BV5);
ellipse(coneDirect, 130, 40, 40);
}
if (scoopCount>=6) {
fill(RV6, GV6, BV6);
ellipse(coneDirect, 90, 40, 40);
}
if (scoopCount==7) {
win=true;
println("YOU WIN");
}
}
//make ice cream scoop colour
void makeScoopColour() {
int colour=(int)random(0, 5);
if (colour ==1) {
scoopColourR=colourR1;
scoopColourG=colourG1;
scoopColourB= colourB1;
} else if (colour==2) {
scoopColourR=colourR2;
scoopColourG=colourG2;
scoopColourB= colourB2;
} else if (colour==3) {
scoopColourR=colourR3;
scoopColourG=colourG3;
scoopColourB= colourB3;
} else if (colour==4) {
scoopColourR=colourR4;
scoopColourG=colourG4;
scoopColourB= colourB4;
}
scoopX=random(20, 380);
}
//program the controls
void keyPressed() {
//to move the ice cream cone
if (key == 'a' || key == 'A' || keyCode == LEFT) {
coneDirect += -10;
}
if (key == 'd' || key == 'D' || keyCode == RIGHT) {
coneDirect += 10;
}
}
//to stop the ice cream cone when the button is released
void keyReleased() {
// Stop the square from moving when the key pressed is released
if (key == 'a' || key == 'A' || keyCode == LEFT) {
coneDirect += 0;
} else if (key == 'd' || key == 'D' || keyCode == RIGHT) {
coneDirect += 0;
}
}
void getScoop() {
fill(scoopColourR, scoopColourG, scoopColourB);
ellipse(scoopX, scoopY, 40, 40);
scoopY++;
//catching/stacking the scoops
if (scoopX <=coneDirect+10 && scoopX >=coneDirect-10 && scoopY == 300+scoopCount*-40) {
caught = true;
respawn=true;
scoopCount ++;
if (scoopCount == 1) {
RV1 = scoopColourR;
GV1 = scoopColourG;
BV1 = scoopColourB;
}
if (scoopCount == 2) {
RV2 = scoopColourR;
GV2 = scoopColourG;
BV2 = scoopColourB;
}
if (scoopCount == 3) {
RV3 = scoopColourR;
GV3 = scoopColourG;
BV3 = scoopColourB;
}
if (scoopCount == 4) {
RV4 = scoopColourR;
GV4 = scoopColourG;
BV4 = scoopColourB;
}
if (scoopCount == 5) {
RV5 = scoopColourR;
GV5 = scoopColourG;
BV5 = scoopColourB;
}
if (scoopCount == 6) {
RV6 = scoopColourR;
GV6 = scoopColourG;
BV6 = scoopColourB;
}
if (scoopCount == 7) {
RV7 = scoopColourR;
GV7 = scoopColourG;
BV7 = scoopColourB;
}
}
}
//have ice cream keep falling after they leave the screen
void offScreen() {
if (scoopY>height) {
respawn=true;
}
}
//make the scoops fall after one leaves the screen
void respawnScoop() {
if (respawn==true) {
scoopY = 0;
makeScoopColour();
caught = false;
respawn=false;
}
}