realbasic-games
[Top] [All Lists]

Re: How to do a hex-map?

To: REALbasic Games <REALbasic-Games at lists dot realsoftware dot com>
Subject: Re: How to do a hex-map?
From: Lars Jensen <larsjensen at rcn dot com>
Date: Sat, 27 Sep 2003 01:12:04 -0400
> My main game window would look like a hex-grid with possible terrain in each
> hex.  The terrain may have some impact (such as movement cost to enter the
> hex or defense value).  Units will reside in that grid, and the user should
> be able to click on them to exert control (selecting them for movement or
> combat).  This overall hex-grid would be the map where battle takes place.

Yes, I got that. I'm familiar with hex-based game maps.

> The ability to have multiple maps is a plus, so storing the map as an
> editable file or database would be desirable (although the map editor might
> be a separate application from the game).

Sounds good.

> Presumably units themselves would reside in an array, with one element in
> the array being a coordinate value to indicate which hex they are in.

Also good.

> Does that help give the detail you requested?

Um, not quite...I'm still not sure how to interpret "I have no clue how to
draw the hexmap, and select/move the units on it."

So I'll try a couple of answers:

To draw the hex map, you could either draw directly to a Canvas, or use a
SpriteSurface, or use an RB3DSpace (that's the one I'd use, 'cause it would
look really cool to fly the camera around). Check out the documentation on
each of those for more details about how to do the drawing, and test for
mouse clicks as a selection indicator.

Is that in the right direction? If not, how about this:

For any hex-based world, you'll need a way of specifying position and motion
in hex coordinates.

I chose a coordinate system that uses rows and columns as follows:
                   _____
                  /     \
            _____/  2 2  \_____
           /     \       /     \
     _____/  2 1  \_____/  1 2  \_____
    /     \       /     \       /     \
   /  2 0  \_____/  1 1  \_____/  0 2  \
   \       /     \       /     \       /
    \_____/  1 0  \_____/  0 1  \_____/
    /     \       /     \       /     \
   /  1 -1 \_____/  0 0  \_____/ -1 1  \
   \       /     \       /     \       /
    \_____/  0 -1 \_____/ -1 0  \_____/
    /     \       /     \       /     \
   /  0 -2 \_____/ -1 -1 \_____/ -2 0  \
   \       /     \       /     \       /
    \_____/ -1 -2 \_____/ -2 -1 \_____/
          \       /     \       /
           \_____/ -2 -2 \_____/
                 \       /
                  \_____/

I also chose this convention for direction/orientation:

  0 = straight up
  1 = forward and to the right
  2 = rearward and to the right
  3 = straight down
  4 = rearward and to the left
  5 = forward and to the left

So if you are at 0,0 and you move in direction 1, you will end up at 0,1.

I then made several routines to do things like calculate the row/column of a
cell that is a given direction and distance from another cell, in either
absolute or relative coordinates.

Is that the kind of info you're looking for?

lj


---
Unsubscribe or switch delivery mode:
<http://support.realsoftware.com/listmanager/>

<Prev in Thread] Current Thread [Next in Thread>