Jump to content
  • Advertisement


This topic is now archived and is closed to further replies.


Isometric Diamond maps

This topic is 6206 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

Hi there! I am learning with Ernest Pazera book ("Isometric Game Programming with...") I am trying to do a isometric diamond map engine (following the book) I have problems when I need to block the scroll. If not, the cursor goes far away from the map I use the technique in the book. (I define a World Rect and a Anchor Rect) When is a little map (like 64 x 64 tiles) it works fine, but when the map is bigger, it does not. If you know how to do that, please reply me Ernest: if you read this, I hope that you could help me Thanks in advance

Share this post

Link to post
Share on other sites
I think I can guess the problem you are having here, the bounding rectangle that stops the view from going away from the map goes to the extents of the map, if the map is large then there will be large areas of none map that you can scroll into. You''ll need to make sure that the screen always has a map tile being drawn to screen. What you could try is this

When the mouse is moved to the edge of the screen (for this exaqmple I''ll use the right hand side of the screen so the map will scroll to the right). This is an easy way though but wont work if you plan to use black in your map. You''d simply test the pixel in the top left. If it is black then stop scrolling to the right. The only problem is that solution prevents you from using black and means you have to get the DC of the surface and thats slow.

A better way would be to convert the top left pixel (if the screen is being scrolled to the right) and convert it to the position it is in your world (I cant remember what does this in the ISO engine from the book you are using but Im sure you can find it) then convert to the tile number, is the pixel (top left of the screen) is outside the map, ie moving into blank space then it will be less (I think, so check it) than zero, you may have to do a conversion on this again before it works, as I said i cant remember the engine offhand. Basically you change the top left pixel into a tile number and see if its in the map (ie if you map was Map[10][10] and your pixel was -1,2 or 13,12 then its outside the map) and you should stop scrolling if it isnt, that will lock the view onto the map no matter what. The bug I can see is that the view starts with a corner of the screen outside the map in which case it will never move and that it might be awkard to see the corners. To solve this make sure the screen view starts within the map and allow it to go a few pixels outside the map or change the psoition tested.

I hope that made sense, just a rough idea of the top of my head so I dont guarentee it to work

Ballistic Programs

Share this post

Link to post
Share on other sites
this can be a bit of a problem with diamond maps. it is much less so with staggered maps, which are more rectangular, and thus easier to use the world rect and anchor rect.

i''m assuming that the problem is that you can scroll away from the map into the "black corners" that have nothing in them.

the solution lies in using a different type of structure for world space other than a simple rect ( a simple rect will work for many cases, but not in all). for a diamond map, the world space should really be shaped more like a diamond than a rectangle.

so, here''s my suggestion: make a diamond shaped anchor space by connecting four points.

the top point should be the location of the very top of the map (in world coordinates), subtract half of the screenspace width and height from the x and y of this location.

for the left, bottom, and right points, determine them the same way, the most extreme position on the map, minus half of the width and height of screenspace.

taken together, these four points form a diamond that is the same size as the map, but offset slightly upwards and to the left. as long as the anchor remains within the diamond, part of the map will be visible.

the trick, of course, is keeping the anchor within the diamond shape.

luckily, provided the map has as equal number of rows and columns ( which is typical), the diamond shaped anchor space has both horizontal and vertical symmetry, so you can easily determine in which of the four quadrants (upper left, upper right, lower left, and lower right) the anchor is in by checking x against the top point''s x (if greater, its on the right, if less, its on the left), and the y against the left point''s y (if higher, its on the bottom, if lower on the top).

(naturally, you first check against the bounding rectangle of the diamond before doing this and adjust the anchor as necessary)

once you determine which quadrant you are in, you can check to see on which side of the line you are on. this can simply be done with linear algebra.

the equation for a line is:

( y - y1 ) = ( y2 - y1 ) / ( x2 - x1 ) * ( x - x1 )

where x1, y1 and x2, y2 are the end points of the line, and x and y are any point on the line.

another way to put this equation is like so:

( x2 - x1 ) * ( y - y1 ) - ( y2 - y1 ) * ( x - x1 ) = 0

if you plug any (x,y) coordinate into this equation, it''ll tell you one of two things. either that it is on the line, and if not, which side of the line it is on. on one side of the line, the equation will be positive, and on the other side negative.

once you know which quadrant you are in, you only have one line to deal with. you simply plug in the value of the anchor for x and y, and see what side of the line the anchor is on.

a positive result means that the anchor is below the line, and a negative result means that it is above the line.

for the upper left and upper right, you do not want to be above the line, and so you look for a negative value, and if so adjust the position of the anchor (which i''ll get to in a moment). if you are on the bottom left or bottom right, you don''t want to be below the line, so you look for a positive and adjust if you find one.

if you find an invalid value for this test, you''ll need to adjust the anchor point. keep the anchor at the original x value, and solve for y on that line with that x value, according to this form of the line equation.

y = ( y2 - y1 ) / ( x2 - x1 ) * ( x - x1 ) + y1

set your anchor y equal to that, and you now have your anchor in the proper position, and this method should be reasonably faster than the alternatives(which are making an HRGN for anchor space and using matrices), and more accurate for a diamond map than a simple rectangle ever could be.

Share this post

Link to post
Share on other sites

  • Advertisement

Important Information

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

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!