Help With pacman Game!!

DevX Home    Today's Headlines   Articles Archive   Tip Bank   Forums   

Results 1 to 3 of 3

Thread: Help With pacman Game!!

  1. #1
    Join Date
    Apr 2005

    Help With pacman Game!!

    Hey whats up i haev just started my pacman game as an applet in Java. I'l give u some background info on how i am doing it. I made an array and assigned numebers inside the array to images
    //1 2 3 4 5 6 7 8 9 10 11 12 13 14 15
    {05,04,05,05,05,04,05,05,05,05,04,05,05,04,05},//3 {05,04,05,04,04,04,04,04,04,04,04,04,05,04,05},//4
    {05,04,05,04,05,05,05,04,05,05,05,04,05,04,05},//5 {05,04,05,04,05,04,04,04,04,04,05,04,05,04,05},//6

    for(int y=0; y<board[x].length; y++){
    drawPic = getImage(getCodeBase(), "pacman" + board [x][y] + ".jpg");
    drawX = x*40;
    drawY = y*40;
    g.drawImage(drawPic,drawX,drawY, this);

    Now im going to use keyevents to move pacman and im going to do it like this.
    I will have keypressed and when this happens depending on what key was pressed i will + or - to the current column pacman is in after!! testing if the next space is not a wall. Now i need a global variable to track pacmans current possitio and this will be an int. I also need 2 ints to track his row/column il call them pacRow, pacColumn, and pacman il call pacMan.

    I am stumped though as to how to add to columns and rows inside an array. Can someone please help me with this.!! i haev all the logic i just need the code.

    thanks alot


  2. #2
    Join Date
    Feb 2004
    I am stumped though as to how to add to columns and rows inside an array. Can someone please help me with this.!! i haev all the logic i just need the code.
    I'm not sure exactly what you mean here. I'm not what adding the columns and rows in the array is for. If you want to keep track of pacmans position you just need two variables, say X and Y. You don't need an array.

    If I was doing it i'd have a class called PacMan and it would have those two variables (along with any other information on PacMan), and when he moved i'd just change the variables accordingly.

    If you explain better what adding the numbers in the array is for I might be able to help more.

  3. #3
    Join Date
    Nov 2004


    A PackMan and a PackManGrid, and a little more. Here I am just
    presenting some loose thought on how to go about this.

    class PackManGrid extends JPanel implements KeyListener {
        public static int [][] gridImgIndex={
          // your image index matrix
        PackMan pm=null;
        ArrayList gridImages=null; 
        public PackManGrid  (ArrayList gridImages /* ?? */) {
          pm=new PackMan(this);
          initiatePackMan(); // ?
        public void keyPressed(KeyEvent ev) {
           GridPos gp=getNewGridPos(ev); // ?
           if (pm.goto(gp) {
              // do moved-logic
           } else  {
              // do atWall logics
    class GridPos {
      public int x=-1;
      public int y=-1;
    class PackMan extends GridPos {
      PackManGrid pmg=null;
      public PackMan (PackManGrid pmg/*and probably more params*/) {
      public boolean goto(GridPos newPos) {
        if (pmg.isValid(newPos) {
          pmg.repaint();  //e.g.  if PackManGrid is implemented as a JPanel extension 
          return true;
         return false;

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
HTML5 Development Center
Latest Articles
Questions? Contact us.
Web Development
Latest Tips
Open Source

   Development Centers

   -- Android Development Center
   -- Cloud Development Project Center
   -- HTML5 Development Center
   -- Windows Mobile Development Center