Please Help Code
in
Programming Questions
•
1 year ago
I am new to processing and am trying to create a ping pong style program. However even with the great resources i only have a very basic version. I also want to include an instruction tab and a reset tab. Can anyone help me beef it up a little. I'm trying to use only mouse controls. Thanks.
---what I have for the instructions tab
---what I have for the instructions tab
- class Instructions
{
float w,h,xPos,yPos;
PFont instructions;
boolean boxed;
Instructions()
{
instructions=createFont("Helvetica",20);
w=130;
h=30;
xPos=120;
yPos=25;
boxed=false;
}
void boxed()
{
/* if(motionX<=xPos&&motionX>=xPos&&motionY>=yPos&&motionY<=yPos+h&&motionPressure>=.09)
{
popup=true;
}
else
{
boxed=false;
}
*/
if (boxed==true)
{
fill(255,200);
rect(0,0,400,800);
fill(0,200);
textSize(20);
text("Play Pong",130,200);
text("Against Yourself",105,300);
text("Like Forrest Gump",133,400);
text("To Beat China",105,450);
}
}
void display()
{
noStroke();
fill(200);
rect(xPos,yPos,w,h);
fill(0);
textSize(20);
text("instructions",xPos+10,yPos+22);
}
}
---What I have for the actual ping pong program.
- boolean gameStart = false;
float x = 150;
float y = 150;
float VelX = random(3, 5);
float VelY = random(3, 5);
int leftColor = 255;
int rightColor = 255;
int diam;
int rectSize = 150;
float diamHit;
PFont myText;
void setup() {
size(500, 500);
noStroke();
smooth();
ellipseMode(CENTER);
myText=createFont("Helvetica",48);
}
void draw()
{
background(0);
fill(255);
diam = 20;
ellipse(x, y, diam, diam);
fill(leftColor);
rect(0, 0, 20, height);
fill(rightColor);
rect(width-30, mouseY-rectSize/2, 10, rectSize);
if (gameStart) {
x = x + VelX;
y = y + VelY;
if ( x > width-30 && x < width -20 && y > mouseY-rectSize/2 && y < mouseY+rectSize/2 ) {
VelX = VelX * -1;
x = x + VelX;
rightColor = 0;
fill(155,155,0);
diamHit = random(75,150);
ellipse(x,y,diamHit,diamHit);
rectSize = rectSize-10;
rectSize = constrain(rectSize, 10,150);
}
else if (x < 25) {
VelX = VelX * -1.1;
x = x + VelX;
leftColor = 0;
}
else {
leftColor = 128;
rightColor = 128;
}
if (x > width)
{
gameStart = false;
x = 150;
y = 150;
VelX = random(3, 5);
VelY = random(3, 5);
rectSize = 150;
}
if ( y > height || y < 0 )
{
VelY = VelY * -1;
y = y + VelY;
}
}
}
void mousePressed()
{
gameStart = !gameStart;
}
1