Jump to content
  • Advertisement
Sign in to follow this  
Ultimate_Fusion

how to use lines like pacman?

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

If you intended to correct an error in the post then please contact us.

Recommended Posts

hope I can explain this right anyway . . In the early pacman game (and a game called maze) the level was drawn using lines. I want to use lines to map out a 2d game i am making. I want to do this the easiest way possible. correct me if im wrong but I think the way pac man did it is just using coordinates and printing to screen, maybe using a txt file to store where each line goes. I was wondering if there is a better way of doing this. I was think of using an image for the background with a picture on it and to check if a character reaches a line I could compare the colour of the pixel to see if its white. A - will this work? B - is there a better way to do it? cheers UF

Share this post


Link to post
Share on other sites
Advertisement
The level is divided into squares, like the picture below. There are many types of walls, horizontal and vertical ones, and they can be combined. The best way would be to store everything in a tilemap, however this time it would rather be called a wall map ;)


The green lines are just there to illustrate that there's a grid. I'll refer to each of those green squares to a tile.

If we were to create a level like the one above, we could use arrays. Every wall type - every combination of walls in a tile - would be assigned a letter. So if there was a tile with just one wall at the left, we could give it the name "a". Another tile, which only has a wall at the top, could be called "b", and so on. A possible list of wall types:

a = Left
b = Top
c = Right
d = Bottom
e = Top and left
f = Top and right
g = Right and bottom
h = Bottom and left
i = Top, left and right
j = Top, left and bottom
k = Right, bottom and left
l = Bottom, left and top
m = Top and bottom
n = Left and right
o = Empty
p = Walls on every side

If you don't understand the above, let me explain again. The "Right, left" etc. are where the walls are located in the tile. This tile, |_|, would for example be "Right, bottom and left", in other words, "k". And | | would be "Left and right", or as it's name in the list says, n. Hopefully you understand =)

Anyway, when making a level, it would be composed of multiple tiles, with diffrent types of walls. The above map would for example look like this:

i b b b
a o f c
k o o c
a g b c
g d d k

Then you can store the above map in a file, read it and create an array out of it, and then do the appropriate rendering based on the list above.

Tell me if you don't understand, and I'll try to explain more =)

Martin

Share this post


Link to post
Share on other sites
I understood that fine. my mate said to do somethinglike that but then how do you do collision detection of stop a player from crossing a line.
in pacman the payer moves along the grid and probale ends up in one of the grid positions so the array position cxan be looked up and see i the pacman can move left, right up or down.

I was planning on moving a ball around a pretty much open area, but the area is pretty big so will contain quite a few walls or paths.

Share this post


Link to post
Share on other sites
It's more convenient to have the walls go through the middle of the grid, as
such:



Then you only need 4 corners, 4 T-sections, 1 vertical bar, 1 horizontal bar, 4 endpoints, and a crossing. The pacman and ghost sprites need to be somewhat larger than the tiles to fit nicely between the walls. So the grid is filled with either a wall-piece, a dot, a pill, or nothing (in the original pacman there's more dots in each tile but alas). The sprites can move wherever there's no wall piece. Hope this conveys the idea.

Share this post


Link to post
Share on other sites
And if you use Prototype's idea, collision detection is a breeze:


if( keyUpIsPushed )
{
if( mapArray[ playerX, playerY - 1 ] != 2 ) // Check if the tile we're moving to is a wall
{
playerY-=1;
}
}

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

Participate in the game development conversation and more when you create an account on GameDev.net!

Sign me up!