3
import mathx.MatrixUtil;
8
import flash.display.Sprite;
11
* A wall object is a type of BuildObject which adds to the
14
typedef WallLayout = mathx.Matrix<Int>;
15
class WallObject extends BuildObject
18
static private var wls : Array<Array<Array<Int>>> = [
42
static public var maxSize = MatPoint.at( 3, 3 );
44
public var wl : WallLayout; //external [read-only]
46
static private function transformCopy( wl : WallLayout ) : WallLayout
49
if( Math.random() > 0.5 ) //either flip or maintain as is (flip is only different than rotate for a few items)
50
nwl = nwl.createFlip( );
52
for( i in 0...Math.floor( Math.random() * 4 ) ) //rotate a 0-3 times (90 degrees each)
58
override public function getBuildMap() : Matrix<Int>
63
override public function canBuildAt( at : MatPoint, ct : Int, mod : Int, lo : LiveObject ) : Bool
65
return ct == MapData.ctLand
66
&& !(mod & MapData.modOccupied == MapData.modOccupied);
70
* Creates a new randomly shaped wall bit.
72
public function new( )
75
wl = transformCopy( Matrix.fromArrayMat( wls[ Math.floor( Math.random() * wls.length ) ] ) );
80
override public function rotate()
86
private function draw()
88
//center on top-left cell
89
var left = -wl.size.x * GConst.gridSizeX / 2.0;
90
var top = -wl.size.y * GConst.gridSizeY / 2.0;
92
while( numChildren > 0 )
93
removeChild( getChildAt( 0 ) );
96
for( y in 0...wl.size.y )
98
for( x in 0...wl.size.x )
100
if( wl.get(x,y) == 1 )
102
//see MapBackground, this is too slow to use real Objects...
103
var seg = new IClipWall();
104
seg.x = left + x * GConst.gridSizeX;
105
seg.y = top + y * GConst.gridSizeY;
106
seg.width = GConst.gridSizeX;
107
seg.height = GConst.gridSizeY;
110
/*drawWall( false, graphics,
111
left + x * GConst.gridSizeX, top + y * GConst.gridSizeY,
112
GConst.gridSizeX, GConst.gridSizeY );*/
119
override public function dragGridTransform() : Point2
127
static public function drawWall( danger : Bool, g : flash.display.Graphics, x : Float, y : Float, w : Float, h : Float )
130
g.beginFill( if( danger ) 0xFF8080 else 0x808080 );
131
g.drawRoundRect( x, y, w-1, h-1, 4, 4 );