[2D PacMan Game Project] *closed*

Thought I’d like to bring my project to this community after a few hours of actually thinking how i’m going to do it.

Updates done:

  • AudioSystem via Java (2 tracks atm: Menu, Game)
  • Basic HighDetail PacMan sprites, (not a black circle dumped with yellow…)
  • Same above for NPC sprites + some animation for ghostys
  • Menu Screen
  • GameMap border collision detection
  • Depending on the last direction of travel, PacMan’s image changes accordingly
  • Left, right, up, down movement of course no other way
  • We now have waka waka collision detection: (below)

Still TODO:

  • Adding NPC’s
  • Full Maps
  • Adding waka waka candy sound effects
  • Keeping track of each rounds accumulated score
  • Tons more just getting started!

Pictures:

Main Menu Screen:

(PacMan’s chasing the ghost, and with each lap the ghost gains more foot room on PacMan, constantly increasing their speeds =D)

Game Map Screen:

(Not much here yet, just drew a basic border map, lives, score).

Waka Waka’s added + collision detection with le PacMan:

Hope to get some positive feedback on this one.
I feel that NPCs was the biggest part of PacMan, I still have yet to do that, looking forward to it.
Any update ideas or things that you think should be added to my TODO list, please comment with them.

You want comment of current progress or suggestions?

you may wanna watch the “making of” of the google pac-man

Google I/O 2011: The Secrets of Google Pac-Man: A Game Show

Well i overdid it last night: (waka waka detection got messed up)
Here’s the coding (probably remove this later today):

NEED HELP:
Here is what is currently detecting if the ‘PacMan’, is over the waka:


	public static void handleWaka(Graphics g, int x, int y) {
		int wx = x;
		int wy = y;
		int px = PacMan.getX();
		int py = PacMan.getY();
		if (
			(px> 60 && px < 80)
				) {
			System.out.println("W00t: X: "+x+". Y: "+y);	
			gotWaka(g, x, y);
			PacMan.setScore(PacMan.getScore() + 1);
		}
	}

(At the moment only detecting if he’s in the first row).

Here is the piece of coding that calls that ‘handleWaka’ method (Draws them also):


	public static int[] wakas = new int[580];

	public static void drawWakas(Graphics g) {
		final Graphics2D g2d = (Graphics2D) g;
		int space = 30;
		for (int i = 70; i < wakas.length; i += space ) {
			wakas[i] = i;
			drawWaka(g, 70, i);
			handleWaka(g, i, i);
		}
	}

What I need help with is a method of drawing the waka wakas candy (row by row), and also storing their coordinates, (or presorting them in a int[] array).

Here’s what I did for the map. I made a 2D array that stored the walls and bullets, and cycled through it in a constructor for the class “Level”, and when it detects a pellet it adds a new one to the pellet list along with x and z coordinates, same with the walls.

Example:

int[][] level = {
			{0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,},
			{0,1,1,1,1,1,1,1,1,1,1,1,1,0,0,1,1,1,1,1,1,1,1,1,1,1,1,0,},
			{0,1,0,0,0,0,1,0,0,0,0,0,1,0,0,1,0,0,0,0,0,1,0,0,0,0,1,0,},
			{0,1,0,0,0,0,1,0,0,0,0,0,1,0,0,1,0,0,0,0,0,1,0,0,0,0,1,0,},
			{0,1,0,0,0,0,1,0,0,0,0,0,1,0,0,1,0,0,0,0,0,1,0,0,0,0,1,0,},
			{0,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,0,},
			{0,1,0,0,0,0,1,0,0,1,0,0,0,0,0,0,0,0,1,0,0,1,0,0,0,0,1,0,},
			{0,1,0,0,0,0,1,0,0,1,0,0,0,0,0,0,0,0,1,0,0,1,0,0,0,0,1,0,},
			{0,1,1,1,1,1,1,0,0,1,1,1,1,0,0,1,1,1,1,0,0,1,1,1,1,1,1,0,},
			{0,0,0,0,0,0,1,0,0,0,0,0,2,0,0,2,0,0,0,0,0,1,0,0,0,0,0,0,},
			{2,2,2,2,2,0,1,0,0,0,0,0,2,0,0,2,0,0,0,0,0,1,0,2,2,2,2,2,},
			{2,2,2,2,2,0,1,0,0,2,2,2,2,2,2,2,2,2,2,0,0,1,0,2,2,2,2,2,},
			{2,2,2,2,2,0,1,0,0,2,2,2,2,2,2,2,2,2,2,0,0,1,0,2,2,2,2,2,},
			{2,2,2,2,2,0,1,0,0,2,2,2,2,2,2,2,2,2,2,0,0,1,0,2,2,2,2,2,},
			{2,2,2,2,2,0,1,2,2,2,2,2,2,2,2,2,2,2,2,2,2,1,0,2,2,2,2,2,},
			{2,2,2,2,2,0,1,0,0,2,2,2,2,2,2,2,2,2,2,0,0,1,0,2,2,2,2,2,},
			{2,2,2,2,2,0,1,0,0,2,2,2,2,2,2,2,2,2,2,0,0,1,0,2,2,2,2,2,},
			{2,2,2,2,2,0,1,0,0,2,2,2,2,2,2,2,2,2,2,0,0,1,0,2,2,2,2,2,},
			{2,2,2,2,2,0,1,0,0,2,2,2,2,2,2,2,2,2,2,0,0,1,0,2,2,2,2,2,},
			{0,0,0,0,0,0,1,0,0,2,0,0,0,0,0,0,0,0,2,0,0,1,0,0,0,0,0,0,},
			{0,1,1,1,1,1,1,1,1,1,1,1,1,0,0,1,1,1,1,1,1,1,1,1,1,1,1,0,},
			{0,1,0,0,0,0,1,0,0,0,0,0,1,0,0,1,0,0,0,0,0,1,0,0,0,0,1,0,},
			{0,1,0,0,0,0,1,0,0,0,0,0,1,0,0,1,0,0,0,0,0,1,0,0,0,0,1,0,},
			{0,1,1,1,0,0,1,1,1,1,1,1,1,2,2,1,1,1,1,1,1,1,0,0,1,1,1,0,},
			{0,0,0,1,0,0,1,0,0,1,0,0,0,0,0,0,0,0,1,0,0,1,0,0,1,0,0,0,},
			{0,0,0,1,0,0,1,0,0,1,0,0,0,0,0,0,0,0,1,0,0,1,0,0,1,0,0,0,},
			{0,1,1,1,1,1,1,0,0,1,1,1,1,0,0,1,1,1,1,0,0,1,1,1,1,1,1,0,},
			{0,1,0,0,0,0,0,0,0,0,0,0,1,0,0,1,0,0,0,0,0,0,0,0,0,0,1,0,},
			{0,1,0,0,0,0,0,0,0,0,0,0,1,0,0,1,0,0,0,0,0,0,0,0,0,0,1,0,},
			{0,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,0,},
			{0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,}
		};

        public Level(Main main)
	{
		this.main = main;
		
		for (int x = 0; x < 28; x++)
		{
			for (int y = 0; y < 31; y++)
			{
				mapData = level[y][x];
				
				if (mapData == 0)
				{
					Wall wall = new Wall(main);
					wall.setX(x);
					wall.setY(y);
					main.wallList.add(wall);
				}
				
				if (mapData == 1)
				{
					Pellet pellet = new Pellet(main);
					pellet.setX(x);
					pellet.setY(y);
					main.pelletList.add(pellet);
				}
				
				if (mapData == 3)
				{
					main.player.px = x * 13;
					main.player.py = y * 13;
				}
			}
		}
	}

Since the screen is going to be longer and wider than the array from above, I multiply the coordinates by 13 (the size of my sprites) to make them go in the right places. When I do collision detection with the walls, I draw rectangles around each piece of wall by cycling through the list, multiplying the x and y by 13 again to get the correct location, and using 13 as the height and width. Same thing with the pellets, except since they are only 4*4, I use 4 as the height and width instead of 13.

See it in action here, or here if that one is blocked.

p.s. I wish I had your art skills! So far my sprites were just ripped from the original game :x

-Nathan