I have this code:
Code:
class BALL {
float xpos, ypos; // position
float vx, vy ;//viteza
float initX, initY;
BALL(int ix, int iy) {
initX = ix;
initY = iy;
init();
}
void init(){
xpos = initX;
ypos = initY;
vx= 4 + random(3); //viteza pe orizontala
if (random(-1,1)<0) vx = -vx;
vy = 5 + random(5); //viteza pe verticala
if (myScore.lastPoint == 1) vy = -vy;
}
void update() {
boolean hit = false;
boolean playerOne=false;
if (ypos < height/2) playerOne = true; // playerOne=true daca bila e in jumatatea de sus
for(int i=0;i<numPads;i++){
if (xpos>pads[i].xpos-padWidth/2 && xpos<pads[i].xpos+padWidth/2 && abs(ypos-pads[i].ypos)<15) { // S-A LOVIT DE UN PAD
if(playerOne) vy = abs(vy); // ii skimb directia, ceva mai shmeker decit vy= -vy
else vy = -abs(vy);
vy *= 1.02;
if (abs(vx/vy)>1) vx *= 0.8; // daca miscarea e prea orizontala, o mai temperez
else vx += random(-3,3); // daca nu, o fut un pic
hit = true;
}
}
if (xpos>width-8 || xpos<8) vx = -vx; //perete lateral
if ( (ypos>height-4 || ypos<12) && !hit) { // s-a dat gol
if (playerOne) {
myScore.p2points++;
myScore.lastPoint = 1;
} else {
myScore.p1points++;
myScore.lastPoint = 2;
}
delay(600);
init();
}
xpos += vx;
ypos += vy;
image(imgBall, round(xpos)-8, round(ypos)-8);
}
}
and this class
Code:
class SCORE {
int p1points=0, p2points=0, limit = 5; // LIMIT e limita pina la care se joaca
int lastPoint = 0; // 0 la initializare, 1 daca ultimul punct cistigat e al lui P1, 2, daca al lui P2
boolean winner=false;
SCORE() {
}
void update(){
if (p1points > limit || p2points > limit){
p1points = 0;
p2points = 0;
winner = true;
} else {
draw(); // desenez scorul si invers, pt amindoi jucatorii ;) ain't I sweet
pushMatrix();
rotate(PI);
translate(-width,-height);
draw();
popMatrix();
}
}
void draw() {
int y = height-100, x=20, spacing=20;
fill(200);
textAlign(LEFT);
text("P1 Points: "+p1points, x, y); y+=spacing;
text("P2 Points: "+p2points, x, y);
}
}
everything's fine if I remove the " if (myScore.lastPoint == 1) vy = -vy; " part (last line in INIT() )
All other myScore references, like "myScore.p1points, etc, are ok. It doesn't seem to like the lastPoint variable.
What's wrng with it ?