Monday, November 26, 2012

Making an overhead map

Unlike classic RPG's of old, I want to keep as much info as possible off the game screen and keep that real estate for the actual game. I don't have any interest in a small overhead map in the corner of the screen that will create clutter and only be looked at some of the time.

I actually struggled with this for a while since I really had no idea how to code it. I posted in the Blitzmax forums asking for ideas and one of them (and a pretty good one) was to create a pixmap sprite. A pixmap sprite allows you to manipulate every pixel in it terms of color and what's the draw. One idea is each pixel would represent a single tile on a level and either draw that tile had or perhaps shade it so objects would be one color and the ground would be another.

After thinking a lot about it I think I have it figured out, in theory anyway. When I read in a level it populates several data structures. Basically, you have square at X and Y and I store the data. What coordinate does that square represent, what sprite gets drawn there, etc. When I render the screen I just loop through those arrays and draw it.

So why not pull in that same data but scale it! When I draw a level, I start at a fixed point for the first square at it's center, say X 0 and Y 0. The next square gets draw at X 32 and Y 8 and so on. If I wanted to draw a mini map of the entire level I could scale by size and coordinates. Let's say we have a 64x64 sprite. Zooming   out by a factor of 1 would make it 32x32. Now, instead of drawing it at the same coordinates I will draw it at X 16 and Y 8. If I wanted to zoom out more I could keeping halving the numbers.

Of course this is all in theory. Fleshing it out in this post sounds like it should work but there is only one way to find out. Since I don't plan on constantly refreshing the map I would only have to loop through all the items only once so bigger maps shouldn't be a problem to draw. Once I get this coded and hopefully working I'll post more about it.

No comments:

Post a Comment