# need help with pacman game!!

• 10-21-2009, 09:03 AM
Newbie_Javaer
need help with pacman game!!
1.how to draw a corridor for pacman in corridor class??:confused:
(the code is given below)

corridor class:

import java.awt.*;

public class Corridor {
private int startX, startY, length;
private boolean isHorizontal;

public Corridor(int x, int y, int length, boolean isHorizontal) {

}

}
//-------------------------------------------------------------------
//-------------------------------------------------------------------
// METHOD FOR CHECKING IF PARAMETER POSITION, x, y,
// IS ON THE CORRIDOR
//-------------------------------------------------------------------
public boolean isOnCorridor(int x, int y) {

return false;
}
//-------------------------------------------------------------------
//-------------------------------------------------------------------
// METHOD FOR DRAWING A SINGLE CORRIDOR OBJECT
//-------------------------------------------------------------------
public void drawCorridor(Graphics g) {

}
}

constants:

import java.awt.*;

public class A3Constants {
private static final int CORRIDORS_TOP = 40;
private static final int CORRIDORS_LEFT = 40;
private static final int CORRIDORS_MAX_LENGTH = 510;

public static final int OUTER_EDGE = 10;
public static final int INNER_EDGE = 10;
public static final int BOTTOM_EDGE = 60;
public static final int WINDOW_WIDTH = CORRIDORS_MAX_LENGTH + OUTER_EDGE * 2 + INNER_EDGE * 2;
public static final int WINDOW_HEIGHT = CORRIDORS_MAX_LENGTH + OUTER_EDGE * 2 + INNER_EDGE * 2 + BOTTOM_EDGE;

public static final int[] HORIZONTAL_CORRIDORS_DATA = {
200,200,150,
200,300,150,
50,500,450
};

public static final int[] VERTICAL_CORRIDORS_DATA = {
300,150,150,
350,250,250,
250,450,50
};

//-------------------------------------------------------------------
// There are 3 values to define one corridor, therefore the number
// of corridors is equal to the length divide by 3.
//-------------------------------------------------------------------
public static final int NUMBER_OF_HORIZONTAL_CORRIDORS = HORIZONTAL_CORRIDORS_DATA.length / 3;
public static final int NUMBER_OF_VERTICAL_CORRIDORS = VERTICAL_CORRIDORS_DATA.length / 3;
public static final int TOTAL_NUMBER_OF_CORRIDORS = NUMBER_OF_HORIZONTAL_CORRIDORS + NUMBER_OF_VERTICAL_CORRIDORS;
• 10-21-2009, 09:20 AM
r035198x
Please use code tags when posting code.
You didn't say specifically what the problem with the code is. What exactly do you need help with?
• 10-22-2009, 02:44 PM
Lizzip
Firstly, you need a width of the corridor.

Then, for the isOnCorridor function, you're needing collision detection. Something along the lines of if pacmanX > corridorWallMinX and pacmanX < corridorWallMaxX and pacmanY > corridorWallMinY and pacmanY < corridorWallMaxY, return true. True being that pacman is in the corridor.

Other than that im not really sure whats going on or what exactly your problem here is