gbadev.org forum archive

This is a read-only mirror of the content originally found on forum.gbadev.org (now offline), salvaged from Wayback machine copies. A new forum can be found here.

Beginners > Strange Bug?

#56515 - biubid_boy - Sun Oct 09, 2005 7:06 am

Hi. I'm using the following code in my pacman clone to make the enemy chase the pacman.

Code:

if (xpacman < xenemy) {
      xenemy--;
      if (xenemy <= xMin || (xenemy == xpacman + 8 && yenemy == ypacman) || (xenemy == xpacman && yenemy == ypacman + 8) || (xenemy == xpacman - 8 && yenemy == ypacman) || (xenemy == xpacman && yenemy == ypacman - 8)) {
                 xpacman = 120;
                 ypacman = 80; } 
   }
   
   if (xpacman > xenemy) {
      xenemy++; 
      if (xenemy >= xMax || (xenemy == xpacman + 8 && yenemy == ypacman) || (xenemy == xpacman && yenemy == ypacman + 8)|| (xenemy == xpacman - 8 && yenemy == ypacman) || (xenemy == xpacman && yenemy == ypacman - 8)) {
                  xpacman = 120;
                  ypacman = 80;  } 
   }
   
   if (ypacman < yenemy) {
      yenemy--;
      if (yenemy <= yMin || (xenemy == xpacman + 8 && yenemy == ypacman) || (xenemy == xpacman && yenemy == ypacman + 8)|| (xenemy == xpacman - 8 && yenemy == ypacman) || (xenemy == xpacman && yenemy == ypacman - 8)) {
                  xpacman = 120;
                  ypacman = 80;  }   
   }

   if (ypacman > yenemy) {
      yenemy++; 
      if (yenemy >= yMax || (xenemy == xpacman + 8 && yenemy == ypacman) || (xenemy == xpacman && yenemy == ypacman + 8)|| (xenemy == xpacman - 8 && yenemy == ypacman) || (xenemy == xpacman && yenemy == ypacman - 8)) {
                  xpacman = 120;
                  ypacman = 80;  }     
   }

}



But when I move my pacman to the edge of the screen, then sideways, it appears in the middle of the screen again (like it should when it gets hit) even though none of my statements evaluate true. Can you please help me get to the bottom of this bug,
Biubid_boy.

#56517 - quickcup - Sun Oct 09, 2005 7:26 am

Try some simple debugging. One at time put a while(1); inside the body of your second level if branch. If your game freezes then that is the one that is evaluating true.

The portion of the clause that I suspect is evaluating true is one of the first ones like xenemy <= xMin.
Why would you reset pacman's coordinates based on whether the enemy goes off screen?

#56519 - biubid_boy - Sun Oct 09, 2005 8:01 am

Oh! Why didn't I see that? I was recycling code from another program (I'm lazy). Problem solved! Thanks!