This is ridiculous:
var xo:int; //x offset.
var yo:int; //y offset.
var i2:int;
var z0:int;
var z1:int;
var zeroMaybe:int;
for (var i:int = 0; i < 4; i++)
{
zeroMaybe = (i < 2) ? 0 : 1;
i2 = i + 1;
z0 = (i & 1);
z1 = (i2 & 1);
xo = (z0 + (-1 * z1)) * zeroMaybe;
yo = (z1 + ( -1 * z0)) * (1-zeroMaybe);
trace("debug");
}
Guess I should just put the pairs into a vector.
Trying to iterate over checking 4 positions relative to a tile:
UP,DOWN,LEFT,RIGHT.
By outputting the correct offset values each iteration:
[0,1] [0,-1], [1,0], [-1,0] in no specific order.
Actually... This isn't bad for building a lookup table that is a linked-list.
Same thing said another way:
for (var i:uint = 0; i < 4; i++)
{
var and3:uint = i & 3; //OUTPUT: 0,1,2,3 0,1,2,3
//OUTPUT in BINARY: 00, 01, 10, 11
//If we SUBTRACT the bits, we can get 0,-1,1,0. Just what we need.
var a3 :uint = (i + 2) & 3; //same as and3, but input is shifted over two.
//When and3 and a3 are converted to -1,1,or zero, we will have the following outputs in this order:
// [0,1] , [-1,0], [1,0], [0,-1] ALL THE KITTY KORNERS.
var npX:int = ((and3 & 2)>>1) - (and3 & 1); //convert number 0-3 to: 0,1,-1
var npY:int = ((a3 & 2)>>1) - (a3 & 1); //convert number 0-3 to: 0,1,-1
//Building linked-list table of offset quadrant values:
cur.x = npX;
cur.y = npY;
if (i != 3)
{
cur.hasNext = true;
cur.next = new LinkedXYPair();
cur = cur.next;
}
trace("debug: [" + npX + " : " + npY + "]");
}
No comments:
Post a Comment