Finding adjacent cells in an hex map – part 2
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 to “Finding adjacent cells in an hex map – part 2”
Leave a Reply
Trackbacks
-
Bookmarks for March 9th from 11:18 to 11:19 « what i say // jon burger on
March 9th, 2009 4:15 pm
[...] Finding adjacent cells in an hex map – part 2 : Emanuele Feronato – [...]
- My epic fail with ClickBank
- Get up to $100,000 for your next Flash game with Mochi GAME Developer Fund
- Create a dynamic content animated footer ad for your site in just 9 jQuery lines – 17 lines version
- Sell sitelocked version of your Flash games and even .fla sources to Free Online Games
- Protect your work from ActionScript code theft with SWF Protector
- Create a dynamic content animated footer ad for your site in just 9 jQuery lines
- Understanding Box2D’s one-way platforms, aka CLOUDS
- Triqui MochiAds Arcade plugin for WordPress upgraded to 1.2
- Box2D Flash game creation tutorial – part 2
- 11 Flash isometric engines you can use in your games
- Create a Lightbox effect only with CSS - no javascript needed
- Flash game creation tutorial - part 1
- Create a Flash Racing Game Tutorial
- Flash game creation tutorial - part 2
- Make a Flash game like Flash Element Tower Defense - Part 2
- Flash game creation tutorial - part 3
- Make a Flash game like Flash Element Tower Defense - Part 1
- Create a flash draw game like Line Rider or others - part 1
- Triqui MochiAds Arcade plugin for WordPress official page
- Create a flash artillery game - step 1
- Flash game creation tutorial – part 5.2 (4.88/5)
- Create a flash artillery game – step 1 (4.79/5)
- Create a Flash Racing Game Tutorial (4.76/5)
- Create a flash artillery game – step 2 (4.74/5)
- Create a survival horror game in Flash tutorial – part 1 (4.73/5)
- Creation of a Flash arcade site using WordPress – step 2 (4.73/5)
- Flash game creation tutorial – part 2 (4.71/5)
- Flash game creation tutorial – part 1 (4.70/5)
- Create a flash draw game like Line Rider or others – part 1 (4.69/5)
- Creation of a platform game with Flash – step 2 (4.68/5)





First comment! This is really cool, your tutorials are awesome.
Second comment, Gratz ! looking great, what are you planning ?