Talking about Hexagonal Tiles game, Actionscript 3, Flash and Game development.
I am porting this prototype into AS3.
I am not doing it for the sake of porting something, but because I want to show you a complete Dice Wars prototype.
I am sorry if the code is not that clean, I’ll come with a dedicated class later, but at the moment this is what I made.
If you want to stay up to date, you should read:
- Understanding hexagonal tiles
- Hex maps creation and rollover
- Finding adjacent cells in an hex map
- Finding adjacent cells in an hex map – part 2
Anyway, this is the main class:
package {
import flash.display.Sprite;
import flash.events.Event;
public class main extends Sprite {
public var hexagon_width:int=38;
public var hexagon_height:int=44;
public var grid_x_size:int=12;
public var grid_y_size:int=11;
public var sector_width:int=hexagon_width;
public var sector_height:Number=hexagon_height/4*3;
public var gradient:Number = (hexagon_height/4)/(hexagon_width/2);
public function main():void {
var hexagon_x_position:Number;
var hexagon_y_position:Number;
var hexagon_number:int;
var hexagon:hexagon_mc;
for (var i:int=0; i=hexagon_width/2) {
n=hexagon_height/2-delta_sector_x*gradient;
if (delta_sector_y=0) && (real_x=0) && (real_y0) {
hexagon_hi=this.getChildByName("hex_"+String(hexagon_hover-grid_x_size-1)) as hexagon_mc;
hexagon_hi.gotoAndStop(3);
}
}
if (Math.floor(hexagon_hover/grid_x_size)0) {
hexagon_hi=this.getChildByName("hex_"+String(hexagon_hover-grid_x_size)) as hexagon_mc;
hexagon_hi.gotoAndStop(3);
}
} else {
if (hexagon_hover%grid_x_size!=grid_x_size-1) {
if (Math.floor(hexagon_hover/grid_x_size)
While hexagon_mc
simply "turns off" the hexagons
package {
import flash.display.MovieClip;
import flash.events.Event;
public class hexagon_mc extends MovieClip {
public function hexagon_mc():void {
addEventListener(Event.ENTER_FRAME,on_enter_frame);
}
public function on_enter_frame(e:Event):void {
gotoAndStop(1);
}
}
}
This is the result:
Place mouse on an hexagon to highlight it and also highlight in a different color its neighbors.
Never miss an update! Subscribe, and I will bother you by email only when a new game or full source code comes out.