Web Wargaming
simulations of historical conflicts on the web

wargame design  mapgrid  sequence of play  terrain  force  movement  combat  retreat  final game

Step 2: The MapGrid coordinates

The MapGrid converts pixels into hexagons and hexparts coordinates.

The Hexagon object has a name ( 0101, A12, etc ) and a MapGrid x, y coordinate.

The Hexpart object also has a MapGrid x, y coordinate. The Hexpart is either the hexagon center, or a hexside. The Hexpart has a hexpartType number. The HexpartTypes are center = 0, bottom = 1, lowerLeft = 2, upperLeft = 3. The Hexpart also has the MapGrid x, y coordinate of it's reference Hexagon.

range, bearing, and line of sight methods.

The big challange: the hexagon map

Every wargame numbering system does not work for programming.  Another coordinate system needs to be used.

Screen pixels do not work 
the mouse events return screen pixels.

This is not useful in any wargame calculations.


Cartesian coordinates do not work well


Geometry coordinates

Using the triangle as a reference, create a grid where the bottom of the triangle is 2 units long.  Using trigonometry, the height of the triangle is sqrt( 42 - 22) = 2 √ 3

These coordinates are difficult to use.

 

 

Geometry coordinates do not work well

 

The solution: get rid of the √ 3

By creating another Y-axis that divides the √ 3,  a new axis can be used that has just integer numbers, and still can be reference the real cartesian coordinate system and follow the rules of analytic geometry. 

The X-axis is NOT divided by √ 3.  That's ok.

The X-axis and Y-axis are not on the same scale.  

MapGrid: Hexpart coordinates work

The mapGrid function calculates a grid over the map that identifies a hexpart and hexagon coordinate.

The hexpart coordinates just factors out 

the √ 3 on the Y-axis.

The hexpart coordinates adjust the X-axis by dividing by 3.

Notice that the hexagon with the triangle has:

24, 16 √ 3  =  8, 16 hexparts

The hexparts are used to calculate movement, rane, bearing and line of sight.  

This works !

how mapGrid works

Hexagon names are still needed for the wargame!

Although the hexagon numbering system has been abandoned for calculations, we still need to display the hexagon name to the wargamer.  The Hexagon function converts the hexagon coordinates into a wargame numbering system, such as 0101 or A1.  This preserves the wargame playing system.

 

Movement is easily calculated with simple math.
Northx + 0, y - 4
Northeastx + 2, y - 2
Southeastx + 2, y + 2
Southx + 0, y + 4
Southwestx - 2, y + 2
Northwestx - 2, y - 2
map map map map
 
 

copyright (c) 1998-2009  redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation; either version 2 of the License, or (at your option) any later version.