//Interactive toy by Gabriel Guilbeault
//It's a simple game
//Player can move their square and collect rectangles
//When a rectangle is collected it is added to the size of the square. The goal is to become massive
//Thanks to Benny for helping me out with issues on lines 77 - 82, and to the internet for helping me out with the background gradient issue
int squarePosX;
int squarePosY;
int score;
int r = 255;
int g = 134;
int b = 150;
int strokeWeight = 3;
float cubeX;
float cubeY;
void setup() {
size(400, 400);
noCursor();
frameRate(60);
textSize(20);
squarePosX = 50;
squarePosY = 50;
cubeX = 200;
cubeY = 200;
score = 0;
}
void draw() {
//background gradient (for aesthetic... and loops)
for (int i = 0; i< width; i++)
{
stroke(r, i, b);
line(0, i, width, i);
}
food();
//make a score counter
text (score, 40, 40);
//snake... needs to grow with the score (point of the ""game"")
fill(255, 134, 197);
rect(squarePosX, squarePosY, 20+(score*5), 20+(score*5));
//feedback for the user
if (score == 5) {
println("You are getting massive");
}
if (score == 10) {
println("You are almost massive");
}
if (score == 15) {
println("You are massive!");
}
if (score == 20) {
println("You are scaring me...");
}
if (score == 25) {
println("You are too massive!!!");
}
}
//make food that you can collect
void food() {
rectMode(CENTER);
fill(255, 197, 39);
rect(cubeX, cubeY, 20, 20);
if (squarePosX >= cubeX -20 && squarePosX <=cubeX +20 && squarePosY >= cubeY -20 && squarePosY <= cubeY+20) {
cubeX = random (width);
cubeY = random (height);
score = score + 1;
}
}
//make it so that the snake moves when you use the arrow keys
void keyPressed() {
if (key == CODED) {
if (keyCode == LEFT) {
squarePosX-= 10;
} else if (keyCode == RIGHT) {
squarePosX+= 10;
} else if (keyCode == UP) {
squarePosY-= 10;
} else if (keyCode == DOWN) {
squarePosY+= 10;
}
}
}