pacman collision

This is a discussion on pacman collision within the Game Programming forums, part of the General Programming Boards category; In my pacman game my tiles and pacman are 32x32 and I move them by 32px. However, sometimes if pacman ...

  1. #1
    Registered User
    Join Date
    Aug 2001
    Posts
    380

    pacman collision

    In my pacman game my tiles and pacman are 32x32 and I move them by 32px. However, sometimes if pacman collides with a ghost, pacman's face becomes the ghost's face. Could having the Collision checking within my Input function be part of the problem?

    I have asked this question on the Allegro.cc forum and they say that I should be using box bound collision instead of tile collision. Is this true?
    Don't you dare hit me on the head, you know I'm not normal.
    A Stooge Site
    Green Frog Software

  2. #2
    Registered User
    Join Date
    Dec 2001
    Posts
    479

    I have asked this question on the Allegro.cc forum and they say that I should be using box bound collision instead of tile collision. Is this true?
    LOL
    is this true? we cant give that ansver, is it true or not?
    it depends on u and your program
    how are u checking your collision now?
    can u show us some code please

  3. #3
    Has a Masters in B.S.
    Join Date
    Aug 2001
    Posts
    2,267
    without code or visual aid i cant say but it sound like your draw ordering.
    ADVISORY: This users posts are rated CP-MA, for Mature Audiences only.

  4. #4
    Registered User Frobozz's Avatar
    Join Date
    Dec 2002
    Posts
    546
    Tile collision would be more useful for an RPG that consists of a grid of tiles and it would check only for what was in each tile of the grid.

    Bounding box moves with the object (unlike tile which stays in one place... I think). So if you want accurate collision detection, I'd go for bounding box.

    I hope I got this all right...

  5. #5
    Blank
    Join Date
    Aug 2001
    Posts
    1,034
    Your problem could be that
    pacman and the ghost are off the tile offsets.
    If your using the same collision detection for
    tile collision as sprite collision it will be off if you divide by the tile
    width.

  6. #6
    Registered User
    Join Date
    Aug 2001
    Posts
    380
    I have included the code for my Input function and all functions releating to drawing to the screen.

    Thank you all for your help.

    Code:
    void getInput(void)
    {
    	pacman.oldx = pacman.x;
    	pacman.oldy = pacman.y;
    
    	if(key[KEY_UP]  && pacman.y > 0)
    	  {           // && level[pacman.y-1][pacman.x] != 1
    		 pacman.y--;		        pacman.sprNum = PACMAN4_BMP;
    		 pacman.direction = UP;
    	  }
    	else if(key[KEY_DOWN] && pacman.y < 14)
    		{   // && level[pacman.y+1][pacman.x] != 1
    			pacman.y++;
    			pacman.sprNum = PACMAN1_BMP;
    			pacman.direction = DOWN;
    		}
    	else if(key[KEY_LEFT] && pacman.x > 0)
    		{  //  && level[pacman.y][pacman.x-1] != 1
    		  pacman.x--;
    		  pacman.sprNum = PACMAN3_BMP;
    		  pacman.direction = LEFT;
    		}
    	else if(key[KEY_RIGHT]  && pacman.x < 19)
    		{    //&& level[pacman.y][pacman.x+1] != 1
    			pacman.x++;
    			pacman.sprNum = PACMAN2_BMP;
         		pacman.direction = RIGHT;
    		}
    
    	else if(key[KEY_PRTSCR])
    		{
    			savescreen();
    		}
       else if(key[KEY_M])
          {
             if(music == 1)
              { music = 0;
                midi_pause();
              }
             else
              { music = 1;
              midi_resume();
              }
          }
    	else if(key[KEY_ESC])
    		{
    			gui_bg_color = 255;
    			gui_fg_color = 0;
    			play_sample(sound[SOUND5_WAV].dat,255,128,1000,FALSE);
    			if(alert("Are you sure", "you want to", "Quit?","&Yes","&No",'y','n') == 1)
    				quit = 1;
    		}
    
       checkCollision();
       level[pacman.y][pacman.x] = 0;
       levelScent[pacman.oldy][pacman.oldx] = pacman.direction;
    }
    
    void drawscreen(void)
    {
       int i;
    	clear_to_color(buffer,0);
       acquire_screen();
    	drawBackground();
     	drawLevel();
    	masked_blit(graphic[pacman.sprNum].dat,buffer,0,0,pacman.x*32,pacman.y*32,32,32);
    
       for(i = 0; i < 3; i++)
       {
    	blit(graphic[BGBLOCK_BMP].dat,buffer,0,0,ghosts[i].x*32,ghosts[i].y*32,32,32);
    	masked_blit(graphic[ghosts[i].sprNum].dat,buffer,0,0,ghosts[i].x*32,ghosts[i].y*32,32,32); // blue ghost
       }
    
       //	textprintf(buffer,font,1,1,15,"x:%d y:%d dots:%d pacman.flee: %d",pacman.x,pacman.y, dots, pacman.flee);
    //	textprintf(buffer,font,1,1,15,"super_pill_timer:%d pacman.flee: %d",super_pill_timer, pacman.flee);
    	textprintf(buffer,font,1,1,15,"music:%d",music);
    	textprintf(buffer,font,290,1,9,"Lives:%d",pacman.lives);
    	textprintf(buffer,font,290,11,9,"Score:%d",pacman.score);
    	textprintf(buffer,font,290,21,9,"Level:%d",levelNum);
    	blit(buffer,screen,0,0,0,0,640,480);
       release_screen();
    }
    /*****************************************************************************/
    void drawLevel(void)
    {
    	int i,j;
    	for(i = 0; i < 20; i++)
    	{
    		for(j = 0; j < 15;j++)
    		{
    			switch(level[j][i])
    			{
    				case 1 :	blit(graphic[BLOCK_BMP].dat,buffer,0,0,i*32,j*32,32,32);
    							break;
    				case 3 : masked_blit(graphic[DOT_BMP].dat,buffer,0,0,i*32,j*32,32,32);
    							break;
    				case 4 : masked_blit(graphic[bonus.sprNum].dat,buffer,0,0,i*32,j*32,32,32);
    							break;
    				case 8 : masked_blit(graphic[BONUS4_BMP].dat,buffer,0,0,i*32,j*32,32,32);
    							break;
    			}
    		}
    	}
    }
    /*****************************************************************************/
    void drawBackground(void)
    {
    	int i,j;
    	for(i = 0; i < 20; i++)
    	{
    		for(j = 0; j < 15;j++)
    		{
    			if(level[j][i] != 1)
    				blit(graphic[BGBLOCK_BMP].dat,buffer,0,0,i*32,j*32,32,32);
    
    		}
    	}
    }
    Don't you dare hit me on the head, you know I'm not normal.
    A Stooge Site
    Green Frog Software

  7. #7
    Has a Masters in B.S.
    Join Date
    Aug 2001
    Posts
    2,267
    well, if you wan pacman always on top(ie he's visible even when he shares a space with the ghost) you should draw him after you draw the ghosts.

    draw order like so

    background:
    level:
    ghosts:
    pacman:

    is that what your lookin for?
    ADVISORY: This users posts are rated CP-MA, for Mature Audiences only.

  8. #8
    Registered User
    Join Date
    Aug 2001
    Posts
    380
    No, I don't want pacman and a ghost to share a tile at anytime. Instead I want a collision to happen and have the ghosts and pacman go home.

    Yes, I using the same collision checking method for everything in the game.

    If in the game a ghost and pacman are setup like so:

    g > < p

    they sometime end up like this:
    < g

    see there now the ghost is pacman which is not what I want.

    I take using Bounding box collision would solve this problem except I don't understand how to apply it to the walls in the game which don't move.

  9. #9
    Registered User
    Join Date
    Dec 2001
    Posts
    479
    are u using a tile-based map?

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Some collision handling fun
    By DavidP in forum Game Programming
    Replies: 9
    Last Post: 04-13-2008, 08:45 AM
  2. Collision Detection Problems
    By Dark_Phoenix in forum Game Programming
    Replies: 1
    Last Post: 12-17-2006, 02:25 PM
  3. pacman ai collision and flee
    By lambs4 in forum Game Programming
    Replies: 5
    Last Post: 01-29-2003, 12:48 PM
  4. collision detection
    By DavidP in forum Game Programming
    Replies: 2
    Last Post: 05-11-2002, 01:31 PM
  5. Replies: 4
    Last Post: 05-03-2002, 09:40 PM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21