/**
* Copyright mutantleg ( http://wonderfl.net/user/mutantleg )
* MIT License ( http://www.opensource.org/licenses/mit-license.php )
* Downloaded from: http://wonderfl.net/c/fq1I
*/
package {
import flash.events.Event;
import flash.display.Sprite;
public class FlashTest extends Sprite {
//isometric sprite sorting thingy
public function FlashTest() {
var i:int;
var k:int;
var a:xActor;
vecAct = new Vector.<xActor>(0, false);
for (i = 0; i < 8; i++)
{
//for (k = 0; k < 8; k++)
for (k = 8; k >= 0; k--) //make sure they are in wrong order by default
{
a = new xActor();
a.cx = k*32 + Math.random()*8;
a.cy = i*32 + Math.random()*8;
a.cz = Math.random(); //+++ is up --- is down
vecAct.push(a);
}//nextk
}//nexti
stage.addEventListener(Event.ENTER_FRAME, onEnter);
}//ctor
public var vecAct:Vector.<xActor>;
public function onEnter(e:Event):void
{
graphics.clear();
graphics.lineStyle(2, 0);
var i:int;
var num:int;
var a:xActor;
var sx:Number;
var sy:Number;
num = vecAct.length;
for (i = 0; i < num; i++)
{
a = vecAct[i];
sx = a.cx - a.cy;
sy = (a.cx*0.5)+(a.cy*0.5) - a.cz;
a.sx = sx;
a.sy = sy;
/*
basic sorting --
works good until you want stuff
on top of each other
*/
a.sortCode = a.cx + a.cy;
//bouncing
a.vz -= 0.2;
if (a.vz < 0 && a.cz <= 0) { a.vz = 1+Math.random(); a.cz =0; }
a.cz += a.vz;
}//nexti
vecAct.sort(compAct);
for (i = 0; i < num; i++)
{
a = vecAct[i];
sx = a.sx;
sy = a.sy;
sx += 200;
sy += 100;
graphics.beginFill(a.c, 0.95);
graphics.drawCircle(sx, sy, 32);
graphics.endFill();
}//nexti
}//onenter
public function compAct(a:xActor, b:xActor):Number
{
if (a.sortCode == b.sortCode) { return 0;}
if (a.sortCode < b.sortCode) { return -1;}
return 1;
}//compact
}//classend
}
internal class xActor
{
public var cx:Number = 0;
public var cy:Number = 0;
public var cz:Number = 0; //up
public var sx:Number = 0;
public var sy:Number = 0;
public var sortCode:int = 0;
public var c:uint = Math.random()*0xFFffFFff;
public var vz:Number = 0;
}//classend