Iso terrain
/**
* Copyright baudon.thomas ( http://wonderfl.net/user/baudon.thomas )
* MIT License ( http://www.opensource.org/licenses/mit-license.php )
* Downloaded from: http://wonderfl.net/c/lgFt
*/
package
{
import flash.display.Sprite;
import flash.events.Event;
import flash.geom.Matrix;
import flash.geom.Point;
public class Main extends Sprite
{
private var myPoints:Vector.<Point>;
private var myWidth:uint = 20;
private var myHeight:uint = 20;
public function Main():void
{
if (stage) init();
else addEventListener(Event.ADDED_TO_STAGE, init);
}
private function init(e:Event = null):void
{
removeEventListener(Event.ADDED_TO_STAGE, init);
myPoints = new Vector.<Point>();
for (var i:uint = 0; i < myHeight +1; ++i) {
for (var j:uint = 0; j < myWidth +1; ++j) {
var temp:Point = new Point();
temp.x = j * 32;
temp.y = i * 32;
myPoints.push(temp );
}
}
var mat:Matrix = new Matrix();
mat.rotate(Math.PI / 4);
mat.scale(1, 0.5);
for (var a:uint = 0; a < myPoints.length; ++a){
myPoints[a] = mat.transformPoint(myPoints[a]);
myPoints[a].x += stage.stageWidth / 2;
myPoints[a].y += Math.random() * 20 -10;
}
graphics.lineStyle(2, 0x333366, 0.8);
for (var k:uint = 0; k < myHeight; ++k) {
for (var l:uint = 0; l < myWidth; ++l) {
if ((k+l)%2 > 0)
graphics.beginFill(0x666699);
else
graphics.beginFill(0x9999cc);
var i:uint = l % (myHeight + 1) + k * (myWidth + 1);
graphics.moveTo(myPoints[i].x, myPoints[i].y);
graphics.lineTo(myPoints[i + 1].x, myPoints[i + 1].y);
graphics.lineTo(myPoints[i + 2+ myWidth].x, myPoints[i + 2 + myWidth].y);
graphics.lineTo(myPoints[i + 1 + myWidth].x, myPoints[i + 1 + myWidth].y);
graphics.lineTo(myPoints[i].x, myPoints[i].y);
}
}
}
}
}