/* built with Studio Sketchpad:
* https://sketchpad.cc
*
* observe the evolution of this sketch:
* https://studio.sketchpad.cc/sp/pad/view/ro.fHLU38DWbFG/rev.484
*
* authors:
* Benjamin Y
* license (unless otherwise specified):
* creative commons attribution-share alike 3.0 license.
* https://creativecommons.org/licenses/by-sa/3.0/
*/
/*
This sketch builds on a prior work, "Game: DASH Pong", created by Benjamin Y & [unnamed author]
http://studio.sketchpad.cc/sp/pad/view/ro.9Uhs4CTQ9ZXnj/rev.6187
*/
/*Ponggit 1.6 Baygreen Studio
* Sketchpad
* This sketch is featured in the
* Gallery. Please respect this
* programmer! Don't mess with this
* code & create bugs, please.
* However, you can create a clone.
* This is a game of DASH Pong,
* that uses user interaction &
* background drawing. Benjamin
* Y is the author of this sketch.
* Happy playing & editing!
*/
void setup(){
//size: 400x400
size(400, 400);
frameRate(75);
stroke(0);
ballx = 200;
bally = 200;
ballxV = random(-2.5, 2.5)+random(-2.5, 2.5);
ballyV = random(-2.5, 2.5)+random(-2.5, 2.5);
py = 350;
num = 175;
lvl = 1;
lvlB = 1;
lvlT = 5;
lvlI = 1/5;
//trail variables
old1x = 0;
old1y = 0;
old2x = 0;
old2y = 0;
old3x = 0;
old3y = 0;
old4x = 0;
old4y = 0;
cpuX = 200;
myX = 200;
stop = 0;
h = false;
int[] scores = new int[4];
gameNum = 0;
arialBlack = createFont("Arial Black", 15);
courierNew = createFont("Courier New", 20);
georgia = createFont("Georgia", 20);
mvBoli = createFont("MV Boli", 16);
bigMvBoli = createFont("MV Boli", 20);
batang = createFont("Batang", 20);
tahoma = createFont("Tahoma", 20);
centuryGothic = createFont("Century Gothic", 20);
bookmanOldStyle = createFont("Bookman Old Style", 20);
textFont(mvBoli);
colorMode(RGB);
}
void draw(){
background(0, 51, 0);
noStroke();
myX = mouseX;
//enviornment
textFont(centuryGothic);
fill(0, 128, 0);
stroke(255);
strokeWeight(2.2);
rect(0, 50, 400, 300);
strokeWeight(2);
fill(0, 201, 0);
rect(150, 150, 100, 100);
stroke(255);
rect(100, 50, 200, 50);
rect(100, 300, 200, 50);
line(150, 200, 250, 200);
fill(255, 255, 255);
arc(200, py, 10, 10, PI, TWO_PI);
fill(255, 255, 255);
arc(200, 400-py, 10, 10, 0, PI);
noFill();
fill(255, 128, 128);
ellipse(200, 200, 40, 40);
fill(255, 51, 51);
arc(200, py, 40, 40, PI, TWO_PI);
arc(200, 400-py, 40, 40, 0, PI);
fill(255, 255, 255);
line(0, 200, 400, 200);
line(200, 50, 200, 350);
text('Mouse X = Paddle X', 100, 375);
ellipse(200, 200, 10, 10);
fill(0, 0, 128);
textFont(mvBoli);
//text("No making bugs without telling me\n in my code, please.", 100, 360);
noStroke();
avg = (ballxV*3 + ballyV)/2;
//ball
ellipse(ballx, bally, 15, 15);
//trail
ellipse(old1x, old1y, 3.872, 3.872);
ellipse(old2x, old2y, 1.967, 1.967);
ellipse(old3x, old3y, 1.402, 1.402);
ellipse(old4x, old4y, 1.184, 1.184);
ballx += ballxV * lvl;
bally += ballyV * lvl;
if (stop == 0){
if (mousePressed == true){
lvl += lvlI;
if (lvl > lvlT){
lvl = lvlB;
}
}
if(bally > height){
ballyV = -ballyV;
}
if(bally < 0) {
ballyV = -ballyV;
}
if(ballx > width) {
ballxV = -ballxV;
}
if(ballx < 0) {
ballxV = -ballxV;
}
//algorithm for C.P.U.
diff = ballx - cpuX;
if ((diff > 0.25) && (diff < -0.25)) {
cpuX += diff;
} else {
if (ballx < cpuX) {
cpuX -= 10;
} else if (ballx > cpuX) {
cpuX += 10;
}
}
//paddle
fill(255, 255, 51);
ellipse(myX, py, 50, 20);
//bounce off paddle
if(((ballx > myX - 10) && (ballx <= myX + 50)) && ((bally > py - 10) && (bally <= py + 10))) {
ballyV = -ballyV;
num += 16;// increment score
}
fill(255, 128, 51);
ellipse(cpuX, 400-py, 50, 20);
//bounce off other paddle
if(((ballx > cpuX - 10) && (ballx <= cpuX + 50)) && ((bally > (400-py) - 10) && (bally <= (400-py) + 10))) {
ballyV = -ballyV;
num -= 1;// increment score
}
//check if on bottom of screen
if(bally > height) {
ballx = random(0, 400);
bally = random(0, 400);
ballxV += random(-0.1*lvl, 0.1*lvl);
ballyV += random(-0.1*lvl, 0.1*lvl);
if (bally >= py-40) {
ballx = random(0, 400);
bally = random(0, 400);
}
if (bally <= 400-py+40) {
bally = random(0, 400);
ballx = random(0, 400);
}
num -= 1;// decrement score
}
if(bally < 0) {
ballx = random(0, 400);
bally = random(0, 400);
ballxV += random(-0.1*lvl, 0.1*lvl);
ballyV += random(-0.1*lvl, 0.1*lvl);
if(bally >= py+40) {
ballx = random(0, 400);
bally = random(0, 400);
}
if (bally <= 400-py+40) {
bally = random(0, 400);
ballx = random(0, 400);
}
num += 1;// decrement score
}
ballxV += random(-0.01*lvl*(num/2), 0.01*lvl*(num/2));
ballyV += random(-0.01*lvl*(num/2), 0.01*lvl*(num/2));
//ballxV += random(-5, 5)
//ballyV += random(-5, 5)
//place score on right corner
fill(255, 255, 255);
text(num, 20, 375);
//place author's name
text('By Benjamin Yang', 200, 360);
//place player's names
text('Player 1', 200, 325);
text('CPU', 200, 75);
sD = 200-num;
// place difficulty
text((lvl*2+avg+sD)/12, 20, 20);
//string str = "P1: Left = Left, Right = Right, : Ctrl = Left, Alt= Right"
text("Ponggit 1.6 Baygreen", 150, 20, -50);
if (h == true){
fill(255, 255, 0);
ellipse(ballx, py, 25, 25);
}
old1x = ballx;
old1y = bally;
old2x = old1x;
old2y = old1y;
old3x = old2x;
old3y = old2y;
old4x = old3x;
old4y = old3y;
}
if (num >= 525) {
fill(255, 0, 51);
textFont(bigMvBoli);
text("YOU WON PONGGIT!", 100, 200, -1000);
textFont(mvBoli);
stop = 1;
//size: 400x400
if (gameNum != 3){
scores[gameNum+1] = num;
gameNum += 1;
}
size(400, 400);
frameRate(50);
noStroke();
ballx = 200;
bally = 200;
ballxV = -5;
ballyV = 5;
py = 350;
num = 0;
lvl = 2;
lvlB = 1;
lvlT = 5;
lvlI = 1/5;
cpuX = 200;
stop = 0;
h = false;
} else if (num < -100) {
fill(255, 0, 51);
textFont(bigMvBoli);
text("BETTER PONG NEXT TIME!", 75, 200, -1000);
textFont(mvBoli);
stop = 1;
//size: 400x400
if (gameNum != 3){
scores[gameNum+1] = num;
gameNum += 1;
}
size(400, 400);
frameRate(50);
noStroke();
ballx = 200;
bally = 200;
ballxV = -5;
ballyV = 5;
py = 350;
num = 0;
lvl = 2;
lvlB = 1;
lvlT = 5;
lvlI = 1/5;
cpuX = 200;
stop = 0;
h = false;
}
}
/*void keyPressed(){
if (key == CODED){
if (keyCode == RIGHT) {
myX += 10
} else if(keyCode == LEFT) {
myX -= 10
}
}
}*/
//end