In case Flash no longer exists; a copy of this site is included in the Flashpoint archive's "ultimate" collection.

Dead Code Preservation :: Archived AS3 works from wonderfl.net

Tiles

Playing with a tile engine...
Get Adobe Flash player
by mach51 11 Jul 2011
/**
 * Copyright mach51 ( http://wonderfl.net/user/mach51 )
 * MIT License ( http://www.opensource.org/licenses/mit-license.php )
 * Downloaded from: http://wonderfl.net/c/udoy
 */

package 
{
    import flash.display.MovieClip;
    
    [SWF(width = '600', height = '600', backgroundColor = '0x000000', frameRate = '30')]
    
    public class Tiles extends MovieClip
    {
        
        // 10 by 10
        public var map:Array = [
            0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
            0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
            0, 0, 1, 0, 0, 0, 0, 1, 0, 0,
            0, 0, 1, 0, 0, 0, 0, 1, 0, 0,
            0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
            0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
            0, 1, 0, 0, 0, 0, 0, 0, 1, 0,
            0, 0, 1, 0, 0, 0, 0, 1, 0, 0,
            0, 0, 0, 1, 1, 1, 1, 0, 0, 0,
            0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
        ];

        public const COLUMNS:int = 10;
        
        public const SIDE:Number = Tile.getSideLength(stage.stageWidth, COLUMNS);
        
        public var blueTile:Tile = new Tile(0, 0x0055ff, SIDE);
        public var redTile:Tile = new Tile(1, 0xff0011, SIDE); 
        
        public function Tiles() 
        {
            map.forEach(drawTiles);
        }
        
        public function drawTiles(id:int, i:int, ar:Array):void
        {
            switch(id)
            {
                case 0:
                var k:Tile = new Tile(blueTile.getID(), blueTile.getColour(), SIDE);
                addChild(k);
                k.x = i % COLUMNS * SIDE;
                k.y = Math.floor(i / COLUMNS) * SIDE;
                break;
                case 1:
                var b:Tile = new Tile(redTile.getID(), redTile.getColour(), SIDE);
                addChild(b);
                b.x = i % COLUMNS * SIDE;
                b.y = Math.floor(i / COLUMNS) * SIDE;
                break;
                
            }
        }

    } // class end
    
}
import flash.geom.Matrix;
import flash.display.GradientType; // end package

import flash.display.MovieClip; 

class Tile extends MovieClip
{
    private var s:Number; // sidelength of a single tile is such that tiles fill the entire stage evenly: stageWidth / columns
    
    private var id:int;
    private var colour:uint;
    
    public function Tile(id:int, colour:uint, s:Number)
    {
        this.id = id;
        this.colour = colour;
        this.s = s;
        
        var mat:Matrix = new Matrix();
        mat.createGradientBox(s, s, 1 / Math.SQRT2, 0, 0);
        
        graphics.lineStyle(1, 0x000000);
        //graphics.beginFill(this.colour);
        graphics.beginGradientFill(GradientType.LINEAR, [this.colour, this.colour && 0x000000], [1, 1], [64, 255], mat);
        graphics.drawRect(0, 0, s, s);
        graphics.endFill();
    }
    
    public static function getSideLength(squareDimension:int, columns:int):Number
    {
        return squareDimension / columns;
    }

    
    public function getColour():uint
    {
        return this.colour;
    }
    
    public function getID():int
    {
        return this.id;
    }
}