-
Notifications
You must be signed in to change notification settings - Fork 0
/
Grid.as
86 lines (70 loc) · 1.81 KB
/
Grid.as
1
package { import flash.display.MovieClip; public class Grid extends MovieClip{ public static const XSIZE:int = 15; public static const YSIZE:int = 15; var tilesmc:MovieClip; var obstaclemc:MovieClip; var gridArray:Array; var elementArray:Array; public function Grid() { tilesmc = new MovieClip(); addChild(tilesmc); obstaclemc = new MovieClip(); addChild(obstaclemc); gridArray = new Array(); elementArray = new Array(); buildBackground(); buildGround(); this.scaleX = this.scaleY = 0.35; } public function addTile(t:Tile):void { tilesmc.addChild(t); if (gridArray[t.gy] == undefined) gridArray [t.gy] = new Array(); gridArray[t.gy][t.gx] = t; } public function getTile(gx:int, gy:int):Tile { //trace(gridArray[gy][gx]); if(gridArray[gy][gx] == undefined) return null; else return gridArray[gy][gx]; } public function getTileArray():Array{ return gridArray; } public function buildGround():void { for (var gx:int = 0; gx < XSIZE; gx++){ for(var gy:int = 0 ; gy < YSIZE; gy++){ var t:Tile = new Tile(); t.gotoAndStop(1); t.init(gx,gy); t.grid = this; addTile(t); } } } public function buildBackground():void { for (var gx:int = 0; gx < XSIZE; gx++){ for(var gy:int = 0 ; gy < YSIZE; gy++){ var t:TileBackground = new TileBackground(); t.init(gx,gy); t.grid = this; tilesmc.addChild(t); } } } public function removeGrid():void{ for each(var e:Element in elementArray){ if(e.parent != null) obstaclemc.removeChild(e); } elementArray = null; } public function resetElementStacks():void{ for each(var a:Array in gridArray){ for each (var t:Tile in a){ t.elementStack = null; } } gridArray = null; } } }