We are about to switch to a new forum software. Until then we have removed the registration on this forum.
Okay, so I'm trying to make a game. This is what I have so far:
long lT = 0;
boolean againstWall = false;
char wallPoint = 'n';
void setup() {
size(1000,500);
lT = millis();
}
float playermxpos = 5;
float playermypos = 5;
color wall1 = #CD5000;
void draw() {
background(51);
float player1xpos = playermxpos + 5;
float player1ypos = playermypos + 3;
float player2xpos = playermxpos + 3;
float player2ypos = playermypos + 5;
//<playersetup>
if (keyPressed) {
if (key == CODED) {
if (millis() - lT >= 50) {
int code = keyCode;
switch (code) {
case UP:
playermypos = playermypos - 10;
break;
case DOWN:
playermypos = playermypos + 10;
break;
case LEFT:
playermxpos = playermxpos -10;
break;
case RIGHT:
playermxpos = playermxpos + 10;
break;
default:
break;
}
}
lT = millis();
}}
noStroke();
fill(255, 201, 0);
rect(player2xpos, player2ypos, 10, 6);
rect(player1xpos, player1ypos, 6, 10);
//</playersetup>
//<wallsetup>
class Wall {
float xpos, ypos, col;
Wall (float xp, float yp, float c) {
xpos = xp;
ypos = yp;
col = c;
}
switch (col) { //<----------------------------------extra curly brace is right here!
case 1:
fill(wall1);
break;
default:
fill(wall1);
break;
}
rect(xpos, ypos, 10, 10);
if (ypos == playermypos) {
for (int x = -10; x < 11; x = x + 20) {
if (xpos + x == playermxpos) {
againstWall = true;
if (x == -10) {
wallPoint = 'w';
} else {
wallPoint = 'e';
}
}
}
}
if (xpos == playermxpos) {
for (int y = -10; y < 11; y = y + 20) {
if (ypos + y == playermypos) {
againstWall = true;
if (y == -10) {
wallPoint = 'n';
} else {
wallPoint = 's';
}
}
}
}
}
Wall w001 = new Wall(
}
However, at this point when I try to run it, it says that there is a missing curly brace (found one too many { characters without a } to match it) right here:
class Wall {
float xpos, ypos, col;
Wall (float xp, float yp, float c) {
xpos = xp;
ypos = yp;
col = c;
}
switch (col) { //right here
case 1:
fill(wall1);
break;
default:
fill(wall1);
break;
}
rect(xpos, ypos, 10, 10);
This isn't the first time Processing has found an extra { that isn't actually there, and it's getting rather annoying. Please help! I really like Processing (much better than having three docs just for one page (html, css, jquery)) but if it keeps doing this I don't know what to do!
Thanks, Me
Answers
You have 29 left parenthesis and just 28 right parenthesis (line 93). Plus it seems you are trying to declare a class inside your draw() function in which you've placed a switch() block, a rect() call and two if() blocks without a wrapping function or constructor block, which is most probably the cause of your problem. Is this your actual code?
All lines from #58 up to #93 are methodless, orphans!
You gotta place them inside some method scope!
Okay, I fixed that, but now it says "the type game.WALL must implement the inherited abstract method game.Wall" I, have no idea what this means.
You've defined an
interface
and doesn't know what it's for??? ~:>Any class which
implements
aninterface
must contain all methods listed inside that!Your
interface
Wall has the followingabstract
method wallSetup().Since
class
WALLimplements
Wallinterface
, it must also contain an implemented wallSetup() method! #:-SP.S.: By convention, neither classes nor interfaces use all-caps names! :-w
Oh. I thought I had already done that. So I fixed it, but now it says "the constructor game.Wall(int,int,int) is undefined". More help?
P.S. From now on I'm going to be adding the code that has the problem, and nothing else, because I don't think that going through the entire code is very time-saving. If you want the entire code at any point, tell me and I will do so soon. Thanks.
this is your constructor
but the } is missing
instead it goes on with
there must be
or so before switch !
Did you wrote this or copied it ?
no wait
this is your constructor?
must be the same name as the class and without void
directly afterwards I read
void Wall (int xp, int yp, int c) {
bad.
Better give it another name like wallDisplay or display
You have:
void Wall (int xp, int yp, int c)
A constructor has no type. It should be:
Wall (int xp, int yp, int c)