Talking about Hexagonal Tiles game, Actionscript 2, Flash, Game development and Users contributions.
This tutorial continues Hex maps creation and rollover.
Now I will show you how find adjacent cells. Again, at the moment it’s only code, and it only works for horizontal hex maps
hexagon_width = 38;
hexagon_height = 44;
grid_x_size = 12;
grid_y_size = 10;
sector_width = hexagon_width;
sector_height = hexagon_height/4*3;
gradient = (hexagon_height/4)/(hexagon_width/2);
for (x=0; x=hexagon_width/2) {
if (delta_sector_y<(hexagon_height/2-delta_sector_x*gradient)) {
real_x = sector_x;
real_y = sector_y-1;
} else {
real_x = sector_x;
real_y = sector_y;
}
} else {
if (delta_sector_y=0) and (real_x=0) and (real_y
and this is the result:
While I am optimizing the code and writing the routines for the vertical hex maps, James Prankard sent me the AS3 version of the code published in the Hex maps creation and rollover tutorial
Here it is:
// Container so you can easily getChildAt
var hexagon_container:MovieClip = new MovieClip();
addChild(hexagon_container);
// Declare variables
var hexagon_width:int = 38;
var hexagon_height:int = 44;
var hexagon_number = 0;
var grid_x_size:int = 12;
var grid_y_size:int = 10;
var sector_width:Number = hexagon_width;
var sector_height:Number = hexagon_height/4*3;
var gradient:Number = (hexagon_height/4)/(hexagon_width/2)
var hexagon_hover:Number = 0;
// Changed the y and x for loop to add the hexagons in the correct way for getChildAt
for (var y_pos:int =0; y_pos=hexagon_width/2){
if(delta_sector_y<(hexagon_height/2-delta_sector_x*gradient)){
real_x = sector_x;
real_y = sector_y-1;
}
else{
real_x = sector_x;
real_y = sector_y;
}
}
else{
if(delta_sector_y=0)&&(real_x=0)&&(real_y
Download the source codes and experiment
Never miss an update! Subscribe, and I will bother you by email only when a new game or full source code comes out.