Public Group

# Pacman Wall Design Question

This topic is 3692 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

## Recommended Posts

Hi, I'm starting to make plans to write a Pacman game using C++ and openGL. I want to begin by setting up the map. However, I'm having trouble coming up with a good but simple way of setting of the walls. The only way I can think of setting up the walls right now is by creating rectangles. This sounds simple enough but what confuses me is that if I do set up walls this way, how can I check to see if Pacman touches a wall? That is, if the user presses the left key, but there is a wall to Pacman's left, how will I make him goes straight until it has been calculated that there is no wall to the left? Does this mean I'd have to keep track of every wall position and have to constantly check if Pacman is going to touch a wall if he makes the next move? Any advice would be very much appreciated! - Omelas PS: Here is example of the map structure I'm using as my model: http://thefuntimesguide.com/images/blogs/pacman-game-online.jpg

##### Share on other sites
yes, you can loop through each tile to check for collision, but this is not the good way. The better way to check for collision is this. When the pacman is moving to the left, check if x - 1 is walkable before updating the pacman position. So the codes should look something like this.
if (moveleft && map.tiles[pacman.x - 1][pacman.y].walkable){   pacman.x--;}else if (moveright && map.tiles[pacman.x + 1][pacman.y].walkable){   pacman.x++;}if (moveup && map.tiles[pacman.x][pacman.y - 1].walkable){   pacman.y--;}else if (moveright && map.tiles[pacman.x][pacman.y + 1].walkable){   pacman.y++;}

##### Share on other sites
Well, rectangle collision is normally not too hard.

if PACMAN.x>wall.x
{
if PACMMAN.x<wall.x+wall.width
{
if PACMAN.y>wall.y
{
if(PACMAN.y<wall.y+wall.height
{
collision = true;
}
}
}
}

Then, if collision is true, just move the player back (IE, if they moved left last frame, move them to the right this frame before handling any input)

Edit: Woops, Dannielum's stuff looks a lot more efficent than mine. I guess it depends on if you want to go rectangle by rectangle(The wall stuff can easily be an array) or have walkability. Walkability maps would probably be much simpler, especially to visualize.

##### Share on other sites
Thanks for the replies guys!

I've never actually used tiles before. Perhaps this is why I'm confused. I wasn't planning on importing any image files for my game. I've got about a month to code this game for a course I'm taking and I don't want to learn more things than I have to since I don't have a lot of time. It's a C++ course so the graphics aren't all that important. Would it still make sense to use tiles? When I asked the question, what I had in mind was that I'd be using basic openGL shapes to make the walls. Do you think I could do this more simply using tiling? It looks like it would take a long time to do tiling from the tutorial I just read about it... What do you suggest would be the best approach in this case?

If I have extra time I'd like to develop an interesting tracking algorithm for the bad guys to find a short path to get to Pacman so I'd like to make the map (walls) in such a way that would make make my job of designing path calculations as simple as possible.

As for Brandon's latest comment regarding walkability maps. Do you think this would take long to implement for a game like Pacman? Can anyone suggest a good resource I might be able to use to learn how to do that as quickly as possible (I've already taken a computer graphics course during which I learn most of the basics of openGL so I'm not starting off from nothing).

Thanks!!

- Omelas

##### Share on other sites
I can't think of any easier design for building pacman game without using tiles. Also, if you need to implement the path finding for the ghosts, you need to have a grid system (tiles!) to track. Tiles map is actually a concept, so if you are already familiar with programming, this should not be something too hard to learn. Try to read some articles about tile system in 2d games. This is the first result i got by searching "2d tile tutorial" on google [google]:
http://compsci.ca/v3/viewtopic.php?t=15927
It is quite short, try to understand the concept then it will be easier for you to implement the game. If you insist to do it other way without using tiles system, you might end up spending more time to implement and might not get it to work as well. So i will recommend to learn it first. Good luck on your project.

##### Share on other sites
Thank you so much for setting me on the right path dannielum!

- Omelas

##### Share on other sites
no problem. by the way, you can use my 2d editor to generate map for your pacman levels. the editor will also help you to generate some codes for the map.
Clicky

1. 1
2. 2
3. 3
Rutin
15
4. 4
khawk
13
5. 5
frob
12

• 9
• 9
• 11
• 11
• 23
• ### Forum Statistics

• Total Topics
633669
• Total Posts
3013257
×

## Important Information

GameDev.net is your game development community. Create an account for your GameDev Portfolio and participate in the largest developer community in the games industry.

Sign me up!