/////////////////////////////////////////////
///////////milu Ganlixingzi///////////////
//////////10.2.2017//////////////////////
////////////////////////////////////
void setup() {
size(400, 400);
rectMode(CORNERS);
ellipseMode(CENTER);
drawGameMachine();
drawScreen();
drawButton();
}
void draw(){
noCursor();
drawGameMachine();
drawScreen();
drawButton();
paddle();
trouble();
ball();
paddleConstraint();
updateBall();
rect(mouseX,mouseY,10,10);
}
void drawGameMachine() {
rectMode(CORNERS);
ellipseMode(CENTER);
frameRate(60);
background(#2DD5A4);
noStroke();
// shadow of game
fill(#6B695F);
rect(110, 300, 280, 350, 15);
//SHADOW/BACK OF SCREEN
rect(110, 70, 140, 320, 15);
//SHADOW/BACK OF GameMachine
fill(#B5B2A1);
rect(120, 60, 280, 340, 15);
//inside GameMachine
fill(#8C8A7D);
rect(130, 70, 270, 180);
}
void drawScreen() {
fill(#27F237);
rect(145, 80, 250, 170);
}
void drawButton() {
fill(#E81025);
ellipse(260, 230, 20, 20);
ellipse(240, 250, 20, 20);
//shadow
fill(#E85078);
ellipse(260, 230, 15, 15);
ellipse(240, 250, 15, 15);
fill(#003961);
ellipse(160, 220, 22, 22); //top button
ellipse(140, 240, 22, 22); //bottom button
ellipse(180, 240, 22, 22); //left button
ellipse(160, 260, 22, 22); //right button
//shadow
fill(#0071C1);
ellipse(160, 220, 17, 17); //top button
ellipse(140, 240, 17, 17); //bottom button
ellipse(180, 240, 17, 17); //left button
ellipse(160, 260, 17, 17); //right button
//TO BLOCK OUT THE SHARP EDGES OF THE QUAD.
fill(#0071C1);
rect(220, 330, 220, 350);
}
//new//////////////////////////////////////////////////////////////
//BORDER SPACING
int net=10;
//TROUBLE VARIABLES
float troubleGravity = 5;
//BALL VARIABLES
float gravity = .1;
float ySpeed = 1;
//BALL STARTING Y
float ballY = 80;
//BALL STARTING X
float ballX = 145;
//BALL RADIUS
int bR = 10;
//LEFT OR RIGHT MOMENTUM
float ballMove = 3;
//RANDOM COLOURS
color ballC;
//PADDLE VARIABLES
float paddleHeight = 10;
float paddleWidth = 20;
float paddleX = 200;
float paddleY = 300;
float PSpacing = 10;
//rect(145, 80, 250, 170);
void updateBall() {
ballX = ballX + ballMove;
ballY += ySpeed;
ySpeed += gravity;
if (ballY <= 0 == true) {
ballY = 1;
ySpeed = -ySpeed*0.6;
}
//Ball collides with walls
if (ballX >= 250-bR || ballX < 135 + bR) {
//ySpeed = ySpeed*-1;
ballMove = -ballMove;
}
if (ballY >= 170 == true) {
ballY = 150;
ySpeed = -ySpeed*0.95;
}
if (ballY <= 80 == true) {
ballY = 90;
ySpeed = -ySpeed*0.95;
}
//BALL COLLIDES WITH TOP OR BOTTOM OF PADDLE
//Bottom
if (ballY - bR <= mouseY+(paddleHeight/2)
//Top
&& ballY + bR >= mouseY - (paddleHeight/2)
//Ball is to the right of the left edge of the paddle
&& ballX - bR >= mouseX - (paddleWidth) - PSpacing
//Ball is to the left of the right edge of the paddle
&& ballX +bR <= mouseX +(paddleWidth) + PSpacing) {
ySpeed = -ySpeed;
ballC = color (random(113,255), 255, random(113, 255));
}
}
void ball() {
//ellipseMode(RADIUS);
rectMode(CORNER);
fill (ballC);
rect(ballX, ballY, bR, bR);
}
void paddleConstraint() {
paddleX=mouseX;
paddleY=mouseY;
if (mouseX < 145+paddleWidth/2) {
paddleX = 145;
//KEEP PADDLE ON SCREEN (MODELED AFTER MARTY DANIELS' CODE)
} else if (mouseX > 230 - (paddleWidth/2)) {
paddleX = 230 - (paddleWidth/2);
}
if (mouseY < 80) {
paddleY = 80;
//KEEP PADDLE ON SCREEN (MODELED AFTER MARTY DANIELS' CODE)
} else if (mouseY > 160) {
paddleY = 160 ;
}
//else {
// paddleX = mouseX;
//}
}
//DRAW PADDLE
void paddle() {
rectMode(CORNER);
//colour
fill(44, 222, 208);
rect(paddleX, paddleY, 30, 10);
}
void trouble() {
if (keyPressed == true) {
gravity = troubleGravity;
} else {
gravity = 0.3;
}
}