Game programming

Moderators: None (Apply to moderate this forum)
Number of threads: 2070
Number of posts: 5361

This Forum Only
Post New Thread
Single Post View       Linear View       Threaded View      f

Report
PACMAN GAME - COLLISION DETECTION WITH MAZE WALLS Posted by spcman on 29 Jun 2003 at 8:10 AM
Hello,
I am currently still trying to develop my own version of the pacman arcade game.
The problem I have is to do with the movement of pacman within the maze.
My maze is made up of tiles which are 8x8 pixels each.
Pacman is a sprite which is 16x16 pixels in size, same with the ghosts.
Note that a tile containing part of a wall also has "moving space" which means that pacman can move onto some of the tile even although the tile is classed as a wall tile.
This can be observed by placing an 8x8 grid over a snapshot of the arcade version.

I have tried a method which will detect whether the tile is a wall or not, if it is a wall then pacman will continue to move until he is halfway into the tile before stopping.

Another method is to use a counter which counts 8 pixels from pacmans previous position (note that I am using the centre of pacman sprite as the position reference).

I have downloaded versions of pacman with source code but these versions only seem to have pacman as an 8x8 sprite as with the tiles and pacman's movement is restricted to one tile at a time.

I need pacman to be able to move smoothly one pixel at a time between tiles and be able to move back and forward at will without having to wait until movement onto next tile before changing direction.

Can anyone suggest a way of solving this problem.
I would be grateful for any advice that can be provided.

Thanks
Spcman

Report
Re: PACMAN GAME - COLLISION DETECTION WITH MAZE WALLS Posted by kreitler on 29 Jun 2003 at 8:51 AM
Hey Spcman,
Without really knowing how your code and tile bitmaps look, it's hard to suggest a good collision algorithm, but here's something that might help.

1) Depending on pacman's direction of motion, calculate the position of a pixel on his "leading edge" (in other words, if he's moving up, calculate the coordinate of a point with a y-value along his top edge, and x value in his center. If he's moving right, use the x of his right edge, and y of his center, etc). Call this Pstart.

2) Calculate a second point that accounts for the total distance he'll move this frame (again, if he's going to move up 5 pixels this frame, take the original point and subtract 5 from its y-value, leaving the x value the same). Call this Pend.

3) Now loop from Pstart to Pend, generating pixel coordinates for each step. For each of these pixels, check the corresponding point on the board. If it falls in an empty tile, go to the next step in the loop. If it falls on a wall tile, go to step 4.

4) If one of the points in the loop falls on a wall tile, you need to do extra calculation. Based on the type of wall tile, you can figure out if the point falls on a wall or an empty pixel. For example, if pacman is moving toward a top edge tile, the bottom few pixels are empty (i.e., the 'move space'). You should be able to subtract the y-coordinate of the tile's bottom edge from the y value of the current "movement check point" to get a value that represents how far past the tile's bottom edge the current move point falls. If that value is less than the number of "move spaces" in the tile, it's valid for pacman to continue moving. If not, exit the loop. The current counter of the loop represents the distance pacman can move, plus 1 pixel. Subtract 1 and move pacman ahead by the remaining amount.

6) If you loop through without hitting any pixels, allow pacman to move the full distance.

That's it. It probably doesn't make much sense without diagrams. If it's not helpful, let me know and I'll try to explain it more clearly.

Good luck!

Kreitler


: Hello,
: I am currently still trying to develop my own version of the pacman arcade game.
: The problem I have is to do with the movement of pacman within the maze.
: My maze is made up of tiles which are 8x8 pixels each.
: Pacman is a sprite which is 16x16 pixels in size, same with the ghosts.
: Note that a tile containing part of a wall also has "moving space" which means that pacman can move onto some of the tile even although the tile is classed as a wall tile.
: This can be observed by placing an 8x8 grid over a snapshot of the arcade version.
:
: I have tried a method which will detect whether the tile is a wall or not, if it is a wall then pacman will continue to move until he is halfway into the tile before stopping.
:
: Another method is to use a counter which counts 8 pixels from pacmans previous position (note that I am using the centre of pacman sprite as the position reference).
:
: I have downloaded versions of pacman with source code but these versions only seem to have pacman as an 8x8 sprite as with the tiles and pacman's movement is restricted to one tile at a time.
:
: I need pacman to be able to move smoothly one pixel at a time between tiles and be able to move back and forward at will without having to wait until movement onto next tile before changing direction.
:
: Can anyone suggest a way of solving this problem.
: I would be grateful for any advice that can be provided.
:
: Thanks
: Spcman
:
:

Report
Re: PACMAN GAME - COLLISION DETECTION WITH MAZE WALLS Posted by kor on 30 Jun 2003 at 4:51 PM
I forsee one massive problem, besides having different sized tiles and sprites:
Assuming pacman's the full 16 pixels wide, with 8 wide tiles, I assume he'll be centered on one.
This means he extends 4 pixels onto each of the adjacent tiles. Either he can't move since he's stuck in a wall, you can't draw the wall, or he can move on one side of a wall, but not the other.

To make it look good, with 8 wide tiles, the walls would have to be 2 pixels wide, one on each side of the center of the tile.
so, you have 3 pixels on each side of each wall, and the 8 in the middle. This adds up to 14 pixels, pacman can't be any bigger than this. You should also have a single pixel on each side of padding, where nothing is, reducing the size available to 12 pixels.

: Hey Spcman,
: Without really knowing how your code and tile bitmaps look, it's hard to suggest a good collision algorithm, but here's something that might help.
:
: 1) Depending on pacman's direction of motion, calculate the position of a pixel on his "leading edge" (in other words, if he's moving up, calculate the coordinate of a point with a y-value along his top edge, and x value in his center. If he's moving right, use the x of his right edge, and y of his center, etc). Call this Pstart.
:
: 2) Calculate a second point that accounts for the total distance he'll move this frame (again, if he's going to move up 5 pixels this frame, take the original point and subtract 5 from its y-value, leaving the x value the same). Call this Pend.
:
: 3) Now loop from Pstart to Pend, generating pixel coordinates for each step. For each of these pixels, check the corresponding point on the board. If it falls in an empty tile, go to the next step in the loop. If it falls on a wall tile, go to step 4.
:
: 4) If one of the points in the loop falls on a wall tile, you need to do extra calculation. Based on the type of wall tile, you can figure out if the point falls on a wall or an empty pixel. For example, if pacman is moving toward a top edge tile, the bottom few pixels are empty (i.e., the 'move space'). You should be able to subtract the y-coordinate of the tile's bottom edge from the y value of the current "movement check point" to get a value that represents how far past the tile's bottom edge the current move point falls. If that value is less than the number of "move spaces" in the tile, it's valid for pacman to continue moving. If not, exit the loop. The current counter of the loop represents the distance pacman can move, plus 1 pixel. Subtract 1 and move pacman ahead by the remaining amount.
:
: 6) If you loop through without hitting any pixels, allow pacman to move the full distance.
:
: That's it. It probably doesn't make much sense without diagrams. If it's not helpful, let me know and I'll try to explain it more clearly.
:
: Good luck!
:
: Kreitler
:
:
: : Hello,
: : I am currently still trying to develop my own version of the pacman arcade game.
: : The problem I have is to do with the movement of pacman within the maze.
: : My maze is made up of tiles which are 8x8 pixels each.
: : Pacman is a sprite which is 16x16 pixels in size, same with the ghosts.
: : Note that a tile containing part of a wall also has "moving space" which means that pacman can move onto some of the tile even although the tile is classed as a wall tile.
: : This can be observed by placing an 8x8 grid over a snapshot of the arcade version.
: :
: : I have tried a method which will detect whether the tile is a wall or not, if it is a wall then pacman will continue to move until he is halfway into the tile before stopping.
: :
: : Another method is to use a counter which counts 8 pixels from pacmans previous position (note that I am using the centre of pacman sprite as the position reference).
: :
: : I have downloaded versions of pacman with source code but these versions only seem to have pacman as an 8x8 sprite as with the tiles and pacman's movement is restricted to one tile at a time.
: :
: : I need pacman to be able to move smoothly one pixel at a time between tiles and be able to move back and forward at will without having to wait until movement onto next tile before changing direction.
: :
: : Can anyone suggest a way of solving this problem.
: : I would be grateful for any advice that can be provided.
: :
: : Thanks
: : Spcman
: :
: :
:
:

Report
Re: PACMAN GAME - COLLISION DETECTION WITH MAZE WALLS Posted by rapter39 on 19 May 2012 at 9:11 AM
i think use a counter which counts 8 pixels from pacmans previous position (note that I am using the centre of pacman sprite as the position reference). sorry i still newbie in programming. jasa poles marmer
Report
Re: PACMAN GAME - COLLISION DETECTION WITH MAZE WALLS Posted by gamecoder11 on 9 Dec 2011 at 10:28 PM
There are versions online you can examine to check out the detection methods etc.
I like this pacman version it is like the original.
Report
This post has been deleted. Posted by gamecoder11 on 9 Dec 2011 at 10:30 PM
This post has been deleted.
Report
This post has been deleted. Posted by gamecoder11 on 9 Dec 2011 at 10:30 PM
This post has been deleted.
Report
Re: PACMAN GAME - COLLISION DETECTION WITH MAZE WALLS Posted by rapter39 on 19 May 2012 at 9:27 AM
i think use a counter which counts 8 pixels from pacmans previous position (note that I am using the centre of pacman sprite as the position reference). sorry i still newbie in programming. jasa poles marmer



 

Recent Jobs

Official Programmer's Heaven Blogs
Web Hosting | Browser and Social Games | Gadgets

Popular resources on Programmersheaven.com
Assembly | Basic | C | C# | C++ | Delphi | Flash | Java | JavaScript | Pascal | Perl | PHP | Python | Ruby | Visual Basic
© Copyright 2011 Programmersheaven.com - All rights reserved.
Reproduction in whole or in part, in any form or medium without express written permission is prohibited.
Violators of this policy may be subject to legal action. Please read our Terms Of Use and Privacy Statement for more information.
Operated by CommunityHeaven, a BootstrapLabs company.