Finding adjacent cells in an hex map – part 2
- April 27, 2008 by Emanuele Feronato
- Filed under Actionscript 2, Flash, Game design | 3 Comments
In the Finding adjacent cells in an hex map post I showed you how to find adjacent cells in horizontal hex maps.
Now it’s time to find adjacent cells in vertical hex maps.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 | hexagon_width = 44;
hexagon_height = 38;
grid_x_size = 10;
grid_y_size = 12;
sector_width = hexagon_width/4*3;
sector_height = hexagon_height;
gradient = (hexagon_width/4)/(hexagon_height/2);
for (x=0; x<grid_x_size; x++) {
for (y=0; y<grid_y_size; y++) {
hexagon_x_position = hexagon_width*y/4*3;
hexagon_y_position = hexagon_height*x+(y%2)*hexagon_height/2;
hexagon_number = y+x*grid_y_size;
hexagon_movieclip = attachMovie("hhexagon", "hhexagon_"+hexagon_number, hexagon_number, {_x:hexagon_x_position, _y:hexagon_y_position});
hexagon_movieclip.gotoAndStop(1);
hexagon_movieclip.txt.text = hexagon_number;
}
}
onEnterFrame = function () {
_root["hhexagon_"+hexagon_hover].gotoAndStop(1);
_root["hhexagon_"+(hexagon_hover+1)].gotoAndStop(1);
_root["hhexagon_"+(hexagon_hover-1)].gotoAndStop(1);
_root["hhexagon_"+(hexagon_hover+11)].gotoAndStop(1);
_root["hhexagon_"+(hexagon_hover+12)].gotoAndStop(1);
_root["hhexagon_"+(hexagon_hover+13)].gotoAndStop(1);
_root["hhexagon_"+(hexagon_hover-11)].gotoAndStop(1);
_root["hhexagon_"+(hexagon_hover-12)].gotoAndStop(1);
_root["hhexagon_"+(hexagon_hover-13)].gotoAndStop(1);
sector_x = Math.floor(_xmouse/sector_width);
sector_y = Math.floor(_ymouse/sector_height);
delta_sector_x = _xmouse%sector_width;
delta_sector_y = _ymouse%sector_height;
switch (sector_x%2) {
case 1 :
if (delta_sector_y>=hexagon_height/2) {
if (delta_sector_x>(hexagon_width/2-delta_sector_y*gradient)) {
real_x = sector_x;
real_y = sector_y;
}
else {
real_x = sector_x-1;
real_y = sector_y;
}
}
else {
if (delta_sector_x<delta_sector_y*gradient) {
real_x = sector_x-1;
real_y = sector_y;
}
else {
real_x = sector_x;
real_y = sector_y-1;
}
}
break;
case 0 :
real_x = sector_x;
real_y = sector_y;
if (delta_sector_x<((hexagon_width/4)-delta_sector_y*gradient)) {
real_x = sector_x-1;
real_y = sector_y-1;
}
if (delta_sector_x<((-hexagon_width/4)+delta_sector_y*gradient)) {
real_x = sector_x-1;
real_y = sector_y;
}
break;
}
if ((real_x>=0) and (real_x<grid_y_size) and (real_y>=0) and (real_y<grid_x_size)) {
hexagon_hover = real_x+real_y*grid_y_size;
_root["hhexagon_"+hexagon_hover].gotoAndStop(2);
if(hexagon_hover%grid_y_size!=grid_y_size-1){
_root["hhexagon_"+(hexagon_hover+1)].gotoAndStop(3);
}
if(hexagon_hover%grid_y_size!=0){
_root["hhexagon_"+(hexagon_hover-1)].gotoAndStop(3);
}
if (hexagon_hover%2 == 0) {
_root["hhexagon_"+(hexagon_hover-11)].gotoAndStop(3);
if(hexagon_hover%grid_y_size!=0){
_root["hhexagon_"+(hexagon_hover-13)].gotoAndStop(3);
}
_root["hhexagon_"+(hexagon_hover+12)].gotoAndStop(3);
_root["hhexagon_"+(hexagon_hover-12)].gotoAndStop(3);
}
else {
if(hexagon_hover%grid_y_size!=grid_y_size-1){
_root["hhexagon_"+(hexagon_hover+13)].gotoAndStop(3);
}
_root["hhexagon_"+(hexagon_hover+11)].gotoAndStop(3);
_root["hhexagon_"+(hexagon_hover+12)].gotoAndStop(3);
_root["hhexagon_"+(hexagon_hover-12)].gotoAndStop(3);
}
}
}; |
Here it is:
This is the last uncommented step, during next one we will discuss about the method used to determine adjacent cells.
Download and enjoy!!
» Flash Templates provided by Template Monster are pre-made web design products developed using Flash technology.
They can be easily customized to meet the unique requirements of your project.
They can be easily customized to meet the unique requirements of your project.
3 Responses
Leave a Reply
TUTORIAL SERIES:
- Una guida completa al gioco del poker online e una selezione dei migliori casino online.
- casino online
- migliori casino online
- BlackJack online
- casinò online



First comment! This is really cool, your tutorials are awesome.
Second comment, Gratz ! looking great, what are you planning ?
[...] Finding adjacent cells in an hex map – part 2 : Emanuele Feronato – [...]