OOP error.
in
Programming Questions
•
1 year ago
I am practicing OOP because I am new to programming and I just finished working on a code that will create a randomly placed block that changes color when it hits a wall, but I can't figure out what the error is.
It says, "syntax error, maybe missing a right parenthesis." Any help or advice would be greatly appreciated.
Thanks.
Here is my code:
It says, "syntax error, maybe missing a right parenthesis." Any help or advice would be greatly appreciated.
Thanks.
Here is my code:
void setup() {
size(600, 600);
stroke(0);
smooth();
The Problem is in my constructors somewhere...
block1 = new Block((random(255), random(255), random(255)), random(xsize, width-xsize), random(ysize, height-ysize), random(1, 3), random(1, 3));
block2 = new Block((random(255), random(255), random(255)), random(xsize, width-xsize), random(ysize, height-ysize), random(1, 3), random(1, 3));
block3 = new Block((random(255), random(255), random(255)), random(xsize, width-xsize), random(ysize, height-ysize), random(1, 3), random(1, 3));
block4 = new Block((random(255), random(255), random(255)), random(xsize, width-xsize), random(ysize, height-ysize), random(1, 3), random(1, 3));
block5 = new Block((random(255), random(255), random(255)), random(xsize, width-xsize), random(ysize, height-ysize), random(1, 3), random(1, 3));
block6 = new Block((random(255), random(255), random(255)), random(xsize, width-xsize), random(ysize, height-ysize), random(1, 3), random(1, 3));
}
void draw() {
background(255);
block1.movement();
block2.movement();
block3.movement();
block4.movement();
block5.movement();
block6.movement();
block1.display();
block2.display();
block3.display();
block4.display();
block5.display();
block6.display();
}
class Block() {
color c;
float xpos, ypos, xspeed, yspeed;
Block(color Tempc, float Tempx, float Tempy, float Tempxs, float Tempys) {
Tempc = c;
Tempx = xpos;
Tempy = ypos;
Tempxs = xspeed;
Tempys = yspeed;
}
void movement() {
xpos = xpos + xspeed;
if (xpos+20 > 600 || xpos-20 < 0) {
xspeed *= -1;
fill(random(255), random(255), random(255));
}
ypos = ypos + yspeed;
if (ypos+20 > 200 || ypos-20 < 0) {
yspeed *= -1;
fill(random(255), random(255), random(255));
}
}
void display() {
float xsize, ysize;
xsize = width/10;
ysize = height/10;
rectMode(CENTER);
rect(xpos, ypos, xsize, ysize);
}
}
1