I am trying to bounce a ball off a rect and i get the error, unexpected token:pmouseX. I don't understand why something like pmouse can b unexpected
in
Programming Questions
•
7 months ago
//global variables for ball
Ball myBall;
float bx; //ball's x loc
float by; //ball's y loc
float bp=1; //ball's path
int b=15; //ball's radius
float d=0; //ball's direction
float vx; //velocity of ball over x axis
float vy; //velocity of ball over y axis
//global variables for pad
int pW=50; //pad's width
int pH=10; //pad's height
int pL=25; //pad's loc in reference to screen
void setup(){
size(700, 700); //screen size
rectMode(RADIUS); //1st 2 parameters=shape's center point,
//3rd & 4th parameters=half shapes's width and height
//ellipseMode(RADIUS);
noStroke();
smooth();
myBall = new Ball(b); //creates new ball
myBall.x = width/2; //ball's beginning x loc
myBall.y = height/2; //ball's beginning y loc
vx = random(20)-5; //specifies velocity over x axis
vy = random(20)-5; //specifies velocity over y axis
}
void draw(){
background(127); //colors screen
myBall.display(); //runs code for ball
myBall.x += vx; //applies velocity to ball's x loc
myBall.y += vy; //applies velocity to ball's y loc
int m1 = 0; //these variables determine when trajectory of ball changes
int m2 = width;
int m3 = 0;
int m4 = height;
if (myBall.x + b > m2) { //these if/then statements determine path of trajectory
myBall.x = m2 - b;
vx *= -1;
}
else if (myBall.x - b < m1) {
myBall.x = m1 + b;
vx *= -1;
}
else if (myBall.y + b > m4) {
myBall.y = m4 - b;
vy *= -1;
}
else if (myBall.y - b < m3) {
myBall.y = m3 + b;
vy *= -1;
}
float pX=constrain(mouseX, pW, width-pW); //control position of pad
float px=height-pL-pH-b; //tests pad
if(bx == px
&& by>pX-pW-b
&& by<pX+pW+b){
bp *=-1;
if(mouseX !=pmouseX{
d=(mouseX-pmouseX)/2.0;
if(d>5){d=5;}
if(d<5){d=5;}
}
}
if(bx<b && d == -1){ //if ball hits, reverse direction
d *= -1;
}
if(by>width-b){
d=d * -1;
}
if(by<b){
d=d * -1;
}
fill(255); //draws ball
ellipse(bx, by, b, b);
fill(127); //draws rect
rect(height-pL, pX, pW, pH);
}
1