forked from: [FF]: Tiles
forked from [FF]: Tiles (diff: 40)
ActionScript3 source code
/**
* Copyright nayu ( http://wonderfl.net/user/nayu )
* MIT License ( http://www.opensource.org/licenses/mit-license.php )
* Downloaded from: http://wonderfl.net/c/pKwo
*/
// forked from bradsedito's [FF]: Tiles
// forked from mach51's Tiles
package
{
import flash.display.MovieClip;
[SWF(width = '500', height = '500', backgroundColor = '0xffffff', frameRate = '100')]
public class Tiles extends MovieClip
{
public var map:Array =
[
1, 1, 2, 0, 0,
0, 0, 0, 0, 0,
0, 0, 0, 0, 0,
0, 0, 0, 0, 0,
0, 0, 0, 0, 0];
public const COLUMNS:int = 5;
public const SIDE:Number = Tile.getSideLength(stage.stageWidth, COLUMNS);
public var blueTile:Tile = new Tile(0, 0xE8E8E8, SIDE);
public var redTile:Tile = new Tile(1, 0xff0011, SIDE);
public var greenTile:Tile = new Tile(2, 0x00FF00, 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;
case 2:
var c:Tile = new Tile(greenTile.getID(), greenTile.getColour(), SIDE);
addChild(c);
c.x = ( i % COLUMNS * SIDE);
c.y = ( Math.floor(i / COLUMNS) * SIDE);
break;
}
//画像を読み込む処理を書いてみる
}
} // class end
}
import flash.events.MouseEvent;
import flash.ui.Mouse;
import flash.events.Event; // end package
import flash.display.MovieClip;
class Tile extends MovieClip
{
private var s:Number; // 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;
graphics.beginFill(this.colour);
graphics.drawRect(0, 0, s/1.5, s/1.5);
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;
}
}