Pacman with processing help

I'm trying to make a pacman game in which he eats the dots and he is lined up to the grid. can anybody please help? So far

I want him to collide with the boxes and I can't figure out why he isn't lined up with the grid. Any help would be greatly appreciated. This is my first java project.

I have:

Code java:

final static int B = 40, H = 25, SPD = 1;
final static byte[][] area = new byte[B][H];
int x = 1, y = 1, z = 0;
float rot = 0;
void setup() {
size(256, 256);
smooth();
frameRate(11);
for (int i = 0; i!=B; i++) for (int j = 0; j!=H; j++)
area[i][j] = (byte) random(5);
}
void draw() {
background(0);
for (int i=0; i!=B; i++) for (int j=0; j !=H; j++) {
if (area[i][j] == 1) {
fill(-1);
ellipse(20*i + 10, 20*j + 10, 10, 10);
}
else if (area[i][j] == 1) {
fill(#0000FF);
rect(20*i, 20*j, 20, 20);
}
else if (area[i][j] == 5) {
fill(0200);
ellipse(20*i + 10, 20*j + 10, 10, 10);
}
else if (area[i][j] == 4) {
fill(150, 255, 255);
rect(20*i, 20*j, 20, 20);
}
}
fill(#FFFF00);
if (z == 0) {
z = 1;
arc(20*x, 10*y, 20, 20, QUARTER_PI + rot, TWO_PI - QUARTER_PI + rot);
}
else if (z == 1) {
z = 2;
arc(20*x, 10*y, 20, 20, QUARTER_PI -.4 + rot, TWO_PI-QUARTER_PI + .4 +rot);
}
else {
z = 0;
arc(20*x, 10*y, 20, 20, 0 + rot, TWO_PI + rot);
}
}
void demolish (int x, int y) {
if (x>=0 & y<H) {
switch(area[x][y]) {
case 1:
case 2:
case 3:
area[x][y]=0;
}
}
}
void move(int x1, int y1) {
x1 = (x1 + B)%B;
y1 = (x1 + H)%H;
switch(area[x1][y1]) {
case 1:
area[x1][y1] = 0;
break;
case 2:
case 3:
x1 = x;
y1 = y;
break;
case 4:
for (int i=-1; i<2; i++) for (int j=-1; j<2; j++)
demolish(x1+i, y1+j);
}
x = x1;
y = y1;
}
void keyPressed() {
if (key != CODED) return;
final int k = keyCode;
if (k == RIGHT) {
x += SPD;
if (area[x][y] == 1) area[x][y] = 12;
rot=0;
}
else if (k == LEFT) {
x -= SPD;
rot = PI;
}
else if (k == UP) {
y -= SPD;
rot = -HALF_PI;
}
else if (k == DOWN) {
y += SPD;
rot = HALF_PI;
}
}

Re: Pacman with processing help

Please edit your post and wrap your code with code tags:

[code=java]

YOUR CODE HERE

[/code]

to get highlighting and preserve formatting.

Do you have any specific questions about the code?

Re: Pacman with processing help

Yes. How do I make pacman collide with the boxes and interact with the dots. Again this is my first jaa game.

Re: Pacman with processing help

Quote:

How do I make pacman collide with the boxes and interact with the dots

Those are high level, not specific questions.

Have it move and detect when it collides with the objects.

Can you post a complete program that compiles and executes for testing?

Re: Pacman with processing help

Please post the whole code and commenting on what you think each method is doing would be appreciated.