/**
* Copyright shohei909 ( http://wonderfl.net/user/shohei909 )
* MIT License ( http://www.opensource.org/licenses/mit-license.php )
* Downloaded from: http://wonderfl.net/c/vjMd
*/
// forked from Event's Button
/*
九月のJAMの課題
「思わず押したくなるボタンをつくってください」に挑戦。
すね毛ぼたん&美脚ボタン(Button Man & Button Woman)
動くボタンがいいなと思ったので、
とりあえず、すね毛の生えたボタンに走ってもらいました。
*/
package {
import flash.events.Event;
import flash.display.*;
import flash.net.navigateToURL;
import flash.utils.escapeMultiByte;
import flash.net.URLRequest;
import caurina.transitions.Tweener;
import net.hires.debug.Stats;
import com.bit101.components.*;
[SWF(width="465", height="465", backgroundColor="0x000000", frameRate="40")]
public class Game extends Sprite {
private var loaders:Vector.<Loader>;
private var data:Data = new Data();
private var room:Room;
private var text:Label;
private var count:int = 0;
private var woman:int = 0;
private var man:int = 0;
public function Game() {
//マップデータの作成
//o:何もなし
var o:Array = [],
a:Array = [ ["plate"] ],
b:Array = [ ["wall"] ],
m:Array = [ ["man"] ],
w:Array = [ ["woman"] ];
data.stageMap[0] = [
[ o , o , o , o , o , o , o , o , o , o , o , o , o , o , o ],
[ o , o , o , o , o , o , o , o , o , o , o , o , o , o , o ],
[ o , o , o , o , o , o , o , o , o , o , o , o , o , o , o ],
[ o , o , o , o , o , o , o , o , o , o , o , o , o , o , o ],
[ o , o , o , o , o , o , o , o , b , a , a , a , b , o , o ],
[ o , o , o , o , o , o , o , o , o , o , o , o , o , o , o ],
[ o , o , o , o , o , o , o , o , o , o , o , o , o , o , o ],
[ o , o , o , o , o , o , o , o , o , o , o , o , o , o , o ],
[ o , o , o , o , o , o , o , o , o , o , o , o , o , o , o ],
[ o , o , o , o , o , o , o , o , o , o , o , o , o , o , o ],
[ o , o , o , o , o , o , o , o , o , o , o , o , o , o , o ],
[ o , o , o , o , o , o , o , o , o , o , o , o , o , o , o ],
[ o , o , o , o , o , o , o , o , o , o , o , o , o , o , o ],
[ o , o , o , o , o , o , o , o , o , o , o , o , o , o , o ],
[ b , a , a , a , a , a , a , a , a , a , a , a , a , a , b ]
];
loaders = data.load();
var nowload:NowLoading = new NowLoading(stage,init);
for each(var loader:Loader in loaders){
nowload.addLoader(loader);
}
}
private function init():void{
Tweener.addTween(stage.getChildAt(1),{alpha:0,time:0,onComplete:function():void{stage.removeChildAt(1)} });
text = new Label(this);
text.scaleX = text.scaleY = 3;
text.y = 420;
textUpdate();
room = new Room(data);
room.scaleX = room.scaleY = 1;
addChild( room );
alpha=0; Tweener.addTween(this,{delay:0,alpha:1,time:0} );
//ボタンを配置=======================================
var button:GameObject = Data.setObject( room, 10, 0, "man", "", "ADD BUTTON");
button.addEventListener( "push", addButton );
}
private function textUpdate():void{ text.text = "buttonMan:" + man + " buttonWoman:" + woman }
private function addButton(e:Event):void{
if(count++ % 2 == 0){
var button:GameObject = Data.setObject( room, 1, 1, "man", "");
button.addEventListener( "push", function btn1():void{man++;textUpdate();} );
}else{
button = Data.setObject( room, 1, 1, "woman", "");
button.addEventListener( "push", function btn2():void{woman++;textUpdate();} );
}
if(count == 10){e.target.textField.text = "NO MORE BUTTON"; e.target.ability.usable = false}
}
}
}
import flash.utils.ByteArray;
import flash.system.LoaderContext;
import flash.geom.*;
import flash.display.*;
import flash.text.TextField;
import flash.events.*;
import flash.net.*;
import caurina.transitions.*;
//オブジェクト作成はデータのロード後に行う。
class Room extends Sprite {
//イメージの場所を記録した配列
private var imgArray:Array;
public var mapWidth:int,mapHeight:int;
public var objects:Vector.<GameObject> = new Vector.<GameObject>;
public var focus:GameObject;
public var hummer:Hummer;
private var data:Data;
private var stageNum:int = 0 //現在のステージ番号
public var stop:int; //設定されている時間だけ一時停止
public var count:int;
private var bitmap:Bitmap;
private var backmapData:BitmapData;
public function Room(d:Data) {
bitmap=new Bitmap( new BitmapData(1,1,true) );
addChild(bitmap);
data = d;
readData(data.stageMap[0]);
addEventListener("addedToStage",init);
}
private function init(e:Event):void{
removeEventListener("addedToStage",init);
hummer = new Hummer(data);
addChild( hummer );
addEventListener("enterFrame", onFrame );
stage.addEventListener("mouseMove", mouseMove );
stage.addEventListener("mouseDown", mouseDown );
stage.addEventListener("mouseUp", mouseUp );
}
public function readData(arr:Array):void {
objects = new Vector.<GameObject>;
focus = null;
mapWidth=arr[0].length+2;
mapHeight=arr.length+2;
bitmap.bitmapData = new BitmapData(mapWidth * Data.cellWidth, mapHeight * Data.cellHeight, true, 0x0);
backmapData = new BitmapData(mapWidth * Data.cellWidth, mapHeight * Data.cellHeight, true, 0x0);
for(var i:int=0;i<mapHeight;i++){
for(var j:int=0;j<mapWidth;j++){
if( i<mapHeight-1 && i>0 && j<mapWidth-1 && j>0 ){
var obj:Array = arr[i-1][j-1];
for(var k:int=0;k<obj.length;k++){
var name:String = obj[k][0];
var param:String = obj[k][1];
if(param == null){ param = "" }
Data.setObject( this, j, i, name, param);
}
}
}
}
}
public function check(x:int,y:int,type:String = ""):Vector.<GameObject>{
var vec:Vector.<GameObject> = new Vector.<GameObject>()
for each( var obj:GameObject in objects ){
if(obj.mapX == x && obj.mapY == y && ( (obj.ability[type] != null && obj.ability[type] == true) || type == "" )){ vec.push(obj) }
}
return vec;
}
private function onFrame(e:Event = null):void {
if (stop > 0) {
stop--;
}else{
count++;
hummer.frame();
bitmap.bitmapData.lock();
bitmap.bitmapData.fillRect(bitmap.bitmapData.rect,0x00000000);
bitmap.bitmapData.draw(backmapData);
for each( var o:GameObject in objects){
if(o.tween.length > 0){ o.move() }
if(o.tween.length == 0 && o.frame != null ){ o.frame(o) }
if( o.anim != null ){ o.animation() }
data.draw(bitmap.bitmapData, o.type, o.state, o.x, o.y, o.dir!=o.rev );
if( o.textField != null){o.textField.x = o.x-o.textField.width/2+13;o.textField.y = o.y-22+((count>>4)% 2)}
if( hummer.down == true && o.ability["hit"] != null ){
if( hummer.hitTestPoint( (o.x * scaleX) + x, (o.y * scaleY) + y - Data.cellHeight, false ) || hummer.hitTestPoint( (o.x * scaleX) + x + Data.cellWidth, (o.y * scaleY) + y - Data.cellHeight, false ) ){
o.hit(o)
}
}
}
if(focus != null){
x = -focus.x * scaleX + (-Data.cellWidth + stage.stageWidth)/2;
y = -focus.y * scaleY + (-Data.cellHeight + stage.stageHeight)/2;
}
bitmap.bitmapData.unlock();
}
}
private function mouseDown(e:Event):void{
hummer.action = true;
Tweener.addTween(hummer,{ y:hummer.y-60, rotation:320, time:0.5});
}
private function mouseUp(e:Event):void{
hummer.down = true;
Tweener.addTween(hummer,{ y:hummer.y+80, rotation:90, time:0.1, transition:"easeInQuad", onComplete:hummer.end});
}
private function mouseMove(e:Event):void{
hummer.move(mouseX, mouseY);
}
}
//マップに配置するオブジェクト
class GameObject extends EventDispatcher {
public var objectName:String = "null" //オブジェクト名
public var depth:int = 0; //深度
public var anim:Object; //アニメーションに関するデータ
public var dir:Boolean = true; //向き
public var rev:Boolean = false; //画像反転
public var textField:TextField;
//オブジェクトの性質を表す。
public var ability:Object = {};
public var frame:Function; //毎フレーム呼び出される:void
public var key:Function; //キーボード操作で呼び出される(e:Event):void
public var damage:Function; //食べられたとき呼び出される。:void
public var hit:Function; //叩かれたとき呼び出される。:void
public var open:Function; //なかに入ろうとしたとき呼び出される。:Boolean
public var kick:Function; //蹴られたとき呼び出される。(dirX):Boolean
public var react:Function; //(戻り値:String)
public var pick:Function; //拾われたとき呼び出される:void
public var param:String; //マップ作成時に設定したパラメータ
public var name:String; //オブジェクトの名前
public var room:Room; //配置された部屋
public var x:Number,y:Number;
public var mapX:int,mapY:int;
public var state:String; //画像の状態
public var type:String; //使用する画像のタイプ
public var count:int = 0;
public var wait:int = 0;
public var animState:String;//現在選択されているアニメーション
//tween?
public var tweenFrame:Vector.<int> = new Vector.<int>();
public var tween:Vector.<Object> = new Vector.<Object>();
//アニメーション時に呼び出される
public function animation():void{
if(anim[animState]!=null){
var data:Array = anim[animState];
//配列から現在のカウントと一致するものを取り出す。
data = data.filter(function(d:*, i:int, a:Array):Boolean{return d[0]==this.count},this);
for each(var act:Array in data){
switch(act[1]){
case "goto":
count = act[2];break;
case "action":
animState = act[2];
count = -1; break;
default:
state = act[1];
if( act[2] != null && act[2] == true){rev = true}
else{rev = false}
}
}
count++;
}
}
public function action(state:String,count:int=0):void{
animState = state; this.count = count;
}
public function addTween( o:Object, frame:int = 1, delay:int = 0):void{
tween.push(o); tweenFrame.push(frame);
};
public function removeTween():void{
tween.splice(0,tween.length);
};
public function move():void{
for(var str:String in tween[0]){
this[str] = ( this[str]* (tweenFrame[0]-1) + tween[0][str] ) / tweenFrame[0];
}
tweenFrame[0]--;
if( tweenFrame[0] == 0){ tween.shift(); tweenFrame.shift(); }
}
}
//button man に関するデータ用クラス
class ButtonMan{
static public const name:String = "ボタンマン";
static public const info:String = "走るボタン";
static public const anim:Object = {
"down":[[0,"d0"],[52,"d1"],[58,"d2"],[64,"d3"],[67,"j"],[70,"action","walk2"]],
"stop":[[0,"d0"]],
"fall":[[0,"w0"],[1,"w1"],[2,"n"],[3,"w2"],[4,"w3"],[5,"w2"],[6,"n"],[7,"w1"]],
"walk1":[[0,"w1"],[4,"w0"],[8,"w1"],[12,"n"]],
"walk2":[[0,"w2"],[4,"w3"],[8,"w2"],[12,"n"]]
}
static public function frame(man:GameObject):void{
if( man.room.check( man.mapX, man.mapY+1, "stand" ).length == 0 ){
man.addTween( {y:man.y + Data.cellWidth }, 8 );
man.action("fall");
man.mapY ++;
}else{
if(man.ability.usable){
if( man.wait < 0 ){
var dirX:int = man.dir ? -1:1;
if( man.room.check( man.mapX + dirX, man.mapY, "block" ).length == 0 && man.room.check( man.mapX + dirX, man.mapY+1, "stand" ).length > 0 ){
man.addTween( {x:man.x + Data.cellWidth * dirX}, 16 );
man.mapX += dirX ;
}else{
man.dir = (man.dir == false);
man.addTween( {}, 16 );
}
if( man.animState == "walk1" ){ man.action("walk2"); }
else{ man.action("walk1"); }
if( man.textField != null ){ man.textField.visible = true }
}else{
if( man.textField != null ){ man.textField.visible = false }
}
}else{
man.action("stop");
}
}
man.wait--;
}
static public function hit(man:GameObject):void{
if( man.wait < 0 && man.ability.usable){
if( man.room.check( man.mapX, man.mapY+1, "stand" ).length == 0 ){
var c:int = 0;
while( man.room.check( man.mapX, man.mapY+1, "stand" ).length == 0 && man.room.mapHeight > man.mapY){
man.mapY++; c++;
}
man.removeTween();
man.addTween( {y:man.mapY * Data.cellWidth }, c*2 );
}
man.action("down",-1);
man.wait = 60;
Sound.se(0);
man.dispatchEvent( new Event("push") );
}
}
}
class Hummer extends Sprite{
public var action:Boolean = false;
public var down:Boolean = false;
private var tx:int = 200,ty:int = 200, dir:Number = 0;
function Hummer(data:Data){
var b:BitmapData = new BitmapData( Data.cellWidth, Data.cellHeight, true, 0 );
data.draw(b,"hummer","hummer",0,0,true)
var map:Bitmap = new Bitmap( b );
map.x = -Data.cellWidth/2;
map.y = -Data.cellHeight/2;
addChild( map )
}
public function move(x:int,y:int):void{
this.tx = x;
this.ty = y;
}
public function frame():void{
if( action == false ){
this.x = (tx + x*3)>>2;
this.y = (ty + y*3)>>2;
}
}
public function end():void{
action = false;
down = false
Sound.se(1);
}
}
//ゲームデータ用クラス
class Data{
static public const keyString:Object = {37:"←",38:"↑",39:"→",40:"↓",88:"x",90:"z"}
static public const URL:Object = {
"buttonMan":"http://assets.wonderfl.net/images/related_images/1/16/16e0/16e073987af19fb15e61fd1a7ae2cd94439b69fb",
"buttonWoman":"http://assets.wonderfl.net/images/related_images/7/7b/7bb6/7bb66e3f61466228418b2c696bd8f27085cfc42a",
"hummer":"http://assets.wonderfl.net/images/related_images/e/e7/e70e/e70ef560808a9b3096bc62c54604ab6b1d127b18",
"object":"http://assets.wonderfl.net/images/related_images/1/1b/1b39/1b39ef89632ff13eb7bf50798762d61ac59ecf9e"
}
static public const URL_NAME:Array=["buttonMan","buttonWoman","hummer","object"];
static public const IMG_NAME:Object = {
"buttonMan":["w0","w1","w2","w3","d0" ,"d1","d2","d3","j","n"],
"buttonWoman":["w0","w1","w2","w3","d0" ,"d1","d2","d3","j","n"],
"hummer":["n","b","hummer"],
"object":["plate","wall"]
}
static public const OBJECT:Object = {
"man":[["depth",0],["type","buttonMan"],["hit",ButtonMan.hit],["frame",ButtonMan.frame],["anim",ButtonMan.anim],["animState","walk1"],["ability",{usable:true,block:true,hit:true}]],
"woman":[["depth",0],["type","buttonWoman"],["hit",ButtonMan.hit],["frame",ButtonMan.frame],["anim",ButtonMan.anim],["animState","walk1"],["ability",{usable:true,block:true,hit:true}]],
"wall":[["depth",5],["type","object"],["state","wall"],["ability",{block:true,stand:true}]],
"plate":[["depth",5],["type","object"],["state","plate"],["ability",{stand:true}]],
"trans":[["depth",5],["type","hummer"],["state","n"]]
}
//テキストフィールド
static private const TF1:Array = [ ["autoSize","left"],["selectable",false],["alpha",1] ];
static private const FR1:Array = [ ["align","center"],["font","_sans"],["bold",true],["size",20],["color",0xFF6666] ];
public var stageMap:Array = [];
static public const cellWidth:int=27,cellHeight:int=27;
//各オブジェクトに使うビットマップデータの設定
public var MAP_SET:Object = {
"buttonMan":"buttonMan",
"buttonWoman":"buttonWoman",
"hummer":"hummer",
"object":"object"
}
//ビットマップを記録したオブジェクト。ロード後に使用可能
public var imageMap:Object = {};
public var imageCell:Object = {};
public var imageRect:Object = {};
private var loaders:Vector.<Loader> = new Vector.<Loader>();
//画像をロード。ローダーの配列を作る。
public function load():Vector.<Loader>{
for each(var url:String in URL){
var loader:Loader = new Loader();
loaders.push(loader);
}
loaders[0].load(new URLRequest(URL[URL_NAME[0]]), new LoaderContext(true));
loaders[0].contentLoaderInfo.addEventListener("complete",onLoad,false,1000);
return loaders;
}
//bitmapdataに画像を描画する
public function draw(target:BitmapData,type:String,name:String,x:int=0,y:int=0,dir:Boolean=true):void{
var map:String = MAP_SET[type];
var mtr:Matrix = new Matrix(-1,0,0,1,x+cellWidth,y)
if (dir) { mtr.a = 1, mtr.tx = x }
if(-1 < IMG_NAME[type].indexOf(name)){
target.draw( imageCell[map][ IMG_NAME[type].indexOf(name) ],mtr)
}
}
//指定した条件で部屋に物体を設置する。
static public function setObject(room:Room, x:int,y:int,name:String,param:String,text:String=null):GameObject{
if(name != null && OBJECT[name] != null){
var arr:Array = clone( OBJECT[name] );
var gObj:GameObject = new GameObject();
for each(var data:Array in arr){
gObj[data[0]] = data[1];
}
gObj.room=room;
gObj.param=param;
gObj.objectName=name;
gObj.mapX=x; gObj.x=x*cellWidth;
gObj.mapY=y; gObj.y=y*cellHeight;
if(text != null){
gObj.textField = TFUtil.textField(TF1,FR1);
gObj.textField.text = text;
alpha1(gObj.textField);
room.addChildAt(gObj.textField,0);
}
//深度が低い順に並べる
for(var i:int=0;i<room.objects.length;i++){
if( room.objects[i].depth < gObj.depth ){break;}
}
room.objects.splice(i,0, gObj);
}
return gObj;
}
//指定した条件で部屋に物体を移動する。
static public function jumpObject(room:Room, x:int, y:int, gObj:GameObject):void {
gObj.room=room;
gObj.mapX=x; gObj.x=x*cellWidth;
gObj.mapY=y; gObj.y=y*cellHeight;
//深度が低い順に並べる
for(var i:int=0;i<room.objects.length;i++){
if( room.objects[i].depth < gObj.depth ){break;}
}
room.objects.splice(i,0, gObj );
}
static private var loadNum:int = 0;
private function onLoad(e:Event):void{
e.currentTarget.removeEventListener("complete",onLoad);
var rect:Rectangle = e.currentTarget.content.getRect(e.currentTarget.content);
imageMap[URL_NAME[loadNum]]=new BitmapData(rect.width,rect.height,true,0x000000);
imageMap[URL_NAME[loadNum]].draw( e.currentTarget.content );
imageMap[URL_NAME[loadNum]].lock();
setImageRect(URL_NAME[loadNum]);
loadNum++;
if(URL_NAME.length>loadNum){
loaders[loadNum].load(new URLRequest(URL[URL_NAME[loadNum]]), new LoaderContext(true));
loaders[loadNum].contentLoaderInfo.addEventListener("complete",onLoad,false,1000);
}
}
private function setImageRect(name:String):void{
imageCell[name] = [];
var map:BitmapData = imageMap[name];
var lineColor:uint = map.getPixel32(map.width-1,map.height-1);
var x:int = 0; var y:int=0; var height:int=0; var width:int=0; var count:int=0;
while(true){
width=0;height=0;
if(lineColor != map.getPixel32(x,y) ){
for(var i:int=1;i+x<map.width;i++){
if( lineColor == map.getPixel32(x+i,y) ){break;}
}
width=i;
for(var j:int=1;j+y<map.width;j++){
if( lineColor == map.getPixel32(x,y+j) ){break;}
}
height=j;
var rect:Rectangle = new Rectangle(x,y,width,height);
var rect2:Rectangle = new Rectangle(0,0,width,height);
var cell:BitmapData = new BitmapData(rect.width,rect.height,true,0x0)
cell.setVector( rect2,map.getVector( rect ) );
imageCell[name].push( cell );
}
x+=width+1;
if(x>=map.width){ y+=height+1;x=0; }
if(y>=map.height){ break; }
count++;
}
}
}
//ロード画面
class NowLoading extends Sprite{
static public const COMPLETE:String = "complete";
public var loaders:Vector.<Object> = new Vector.<Object>;
public var bytesTotal:uint=0,bytesLoaded:uint=0;
private var _loaderNum:uint=0,_completedNum:uint=0,_openNum:uint=0; //ローダーの数
private var text:Bitmap, sprite:ProgressSprite;
private var onLoaded:Function;
private var LETTER:Object = {
"1":[[0,1,1],[0,0,1],[0,0,1],[0,0,1],[0,0,1]],"2":[[1,1,1],[0,0,1],[0,1,1],[1,0,0],[1,1,1]],"3":[[1,1,1],[0,0,1],[1,1,1],[0,0,1],[1,1,1]],"4":[[1,0,1],[1,0,1],[1,0,1],[1,1,1],[0,0,1]],"5":[[1,1,1],[1,0,0],[1,1,1],[0,0,1],[1,1,1]],
"6":[[1,1,1],[1,0,0],[1,1,1],[1,0,1],[1,1,1]],"7":[[1,1,1],[0,0,1],[0,0,1],[0,0,1],[0,0,1]],"8":[[1,1,1],[1,0,1],[1,1,1],[1,0,1],[1,1,1]],"9":[[1,1,1],[1,0,1],[1,1,1],[0,0,1],[0,0,1]],"0":[[1,1,1],[1,0,1],[1,0,1],[1,0,1],[1,1,1]],
".":[[0],[0],[0],[0],[1]]," ":[[0],[0],[0],[0],[0]],"n":[[0,0,0],[0,0,0],[1,1,1],[1,0,1],[1,0,1]],"w":[[0,0,0,0,0],[0,0,0,0,0],[1,0,1,0,1],[1,0,1,0,1],[1,1,1,1,1]],"o":[[0,0,0],[0,0,0],[1,1,1],[1,0,1],[1,1,1]],
"a":[[0,0,0],[0,0,1],[1,1,1],[1,0,1],[1,1,1]],"l":[[1],[1],[1],[1],[1]],"i":[[1],[0],[1],[1],[1]],"d":[[0,0,1],[0,0,1],[1,1,1],[1,0,1],[1,1,1]],"g":[[0,0,0],[0,0,0],[1,1,1],[1,0,1],[1,1,1],[0,0,1],[1,1,1]],
"C":[[1,1,1],[1,0,0],[1,0,0],[1,0,0],[1,1,1]],"O":[[1,1,1],[1,0,1],[1,0,1],[1,0,1],[1,1,1]],"M":[[1,1,1,1,1],[1,0,1,0,1],[1,0,1,0,1],[1,0,1,0,1],[1,0,1,0,1]],"P":[[1,1,1],[1,0,1],[1,1,1],[1,0,0],[1,0,0]],
"T":[[1,1,1],[0,1,0],[0,1,0],[0,1,0],[0,1,0]],"L":[[1,0,0],[1,0,0],[1,0,0],[1,0,0],[1,1,1]],"E":[[1,1,1],[1,0,0],[1,1,1],[1,0,0],[1,1,1]]
}
//ステージと関数を渡す
public function NowLoading(stage:Stage, onLoaded:Function = null){
if(onLoaded == null){ this.onLoaded=nullFunc }else{ this.onLoaded=onLoaded }
sprite = new ProgressSprite(stage.stageWidth,stage.stageHeight);
text = new Bitmap( new BitmapData(30*4,8,true,0x00000000 ) );
stage.addChild(this); addChild(sprite); addChild(text);
with(text){scaleX=scaleY=1; blendMode="invert"; x=stage.stageWidth-text.width; y=stage.stageHeight-text.height;}
}
//ローダーの追加
public function addLoader(loader:Loader):Loader{ setListener(loader.contentLoaderInfo);_loaderNum++;return loader;}
public function addURLLoader(loader:URLLoader):URLLoader{setListener(loader); _loaderNum++; return loader;}
private function nullFunc():void{}
private function setListener(loader:*):void{
loader.addEventListener("open", onOpen);
loader.addEventListener("complete", onComplete);
loader.addEventListener("progress", update);
}
private function update(e:Event=null):void{
bytesLoaded=0; bytesTotal=0;
for each(var loadObj:Object in loaders){
bytesLoaded += loadObj.bytesLoaded;
bytesTotal += loadObj.bytesTotal;
};
sprite.progress(bytesLoaded/bytesTotal * _openNum/_loaderNum);
if(bytesTotal!=0){ setText( "now loading... "+(bytesLoaded/bytesTotal* _openNum/_loaderNum*100).toFixed(1) ); }
}
private function onOpen(e:Event):void{ _openNum++;loaders.push(e.currentTarget); bytesTotal+=e.currentTarget.bytesTotal; }
private function onComplete(e:Event):void{ _completedNum++;if(_loaderNum == _completedNum){ setText( "COMPLETE" );onLoaded(); } }
private function setText(str:String):void{
var b:BitmapData = text.bitmapData; var l:int = str.length; var position:int = b.width;
b.lock();b.fillRect(b.rect,0x000000);
for(var i:int=0;i<l;i++){
var letterData:Array = LETTER[str.substr(l-i-1,1)];position-=letterData[0].length+1;
for(var n:int=0;n<letterData.length;n++){ for(var m:int=0;m<letterData[n].length;m++){
if(letterData[n][m]==1){b.setPixel32(m+position,n+1,0xFF000000);}
} }
}
b.unlock();
}
}
//このスプライトを編集することでロード画面を変えることができる。
class ProgressSprite extends Sprite{
private var mapData:BitmapData,sphereData:BitmapData,noizeData:BitmapData;
private var bfRate:Number=0; //前の段階での進行度
private var drawRate:Number=0;
private var maxLevel:int = 5;
private var meter:Array = new Array();
//コンストラクタ
public function ProgressSprite(width:int,height:int):void{
mapData = new BitmapData(width,height,true,0x00000000);
addChild(new Bitmap(mapData)).blendMode="invert";
for(var i:int=0;i<maxLevel;i++){
meter[i]=0;
}
addEventListener("enterFrame",onFrame);
}
//ロードが進行したときに呼び出される。 rateはロードの進行度で0-1
public function progress(rate:Number):void{
bfRate = rate;
}
private function draw(rate:Number, level:int=0):void{
var thick:int = mapData.height*(0.61803)/1.61803;
var floor:int = 0;
for(var i:int=1;i<level+1;i++){
thick*=(0.61803)/1.61803;
floor+=thick;
}
mapData.fillRect( new Rectangle(0,mapData.height-floor,mapData.width*rate,thick), 0x1000000*int(0xFF*(maxLevel-level+1)/(maxLevel)));
}
private function onFrame(e:Event):void{
for(var i:int=0;i<maxLevel;i++){
var n:int = Math.pow(2,i+2);
meter[i]=(bfRate+ meter[i]*(n-1))/n;
draw(meter[i],i);
}
}
}
import flash.text.TextFormat;
class TFUtil{
//行列に従ってパラメータを設定したTextFieldを返します。
static public function textField(arr:Array,format:Array=null):TextField{
var tf:TextField = new TextField();
if(format!=null){tf.defaultTextFormat = TFUtil.format(format);}
for(var i:int=0;i<arr.length;i++){tf[arr[i][0]]=arr[i][1];}
return tf;
}
//行列に従ってパラメータを設定したTextFormatを返します。
static public function format(arr:Array):TextFormat{
var f:TextFormat = new TextFormat();
for(var i:int=0;i<arr.length;i++){f[arr[i][0]]=arr[i][1];}
return f;
}
//行列に従ってパラメータをobjに設定します。
static public function push(obj:Object,arr:Array):void{
for(var i:int=0;i<arr.length;i++){obj[arr[i][0]]=arr[i][1];}
}
}
//SiON
import org.si.sion.*;
import org.si.sound.*;
class MyDriver extends SiONDriver {
//public var dm:DrumMachine = new DrumMachine(0, 0, 0, 1, 1, 1);
public var fill:SiONData;
function MyDriver():void{
super();
volume = 2.0
//dm.volume = 0.1
setVoice(0, new SiONVoice(5,2,63,63,-10,0,2,20));
fill = compile("#A=c&ccrccrc&cccrc&c&c&c;#B=<c&c>bragrf&fedrc&c&c&c;#C=<c&c>bragra&ab<crc&c&c&c>;%1@8,l16B;#D=rrrrrrrrrrrrcerg;#E=<c>bagfedcfedrc&c&c&c;#F=cdefgab<c>fgar<c&c&c&c>;");
setSamplerData(0, render("%3@4 v16 l24 c<<c"));
setSamplerData(1, render("%2@3 v8 q1l60 c"));
setSamplerData(2, render("%3@8 l12 <<<<<a0b0c0b0e0d0g"));
setSamplerData(3, render("%3@4 l60 <<<<<c>c"));
setSamplerData(4, render("%2@60 v2 l48 c<c"));
setSamplerData(5, render("%3@0q0,c"));
setSamplerData(6, render("%2@4, l24q0 <<c<<c>>c<<c>>"));
play() ;
}
}
class Sound{
static public var driver:MyDriver = new MyDriver();
static public function se(i:int,delay:int=0):void{
driver.playSound(i,0,delay);
}
static public function music(i:int=1):void{
switch(i) {
}
}
}
//配列の複製を返す
import flash.utils.getQualifiedClassName;
function clone(arg:*):*{
var cl:*;
var name:String = getQualifiedClassName(arg);
if( name == "Object" || name == "Array" || name == "Vector" ){
if( name == "Object" ){ cl = {}; }
else if( name == "Array" ){ cl = []; }
else if( name == "Vector" ){ cl = Vector([]); }
for( var s:String in arg ){
cl[s] = clone( arg[s] );
}
return cl;
}else if( arg is Object && arg.hasOwnProperty("clone") && arg.clone is Function ){
return arg.clone();
}
return arg;
}
//点滅用
function alpha1(d:DisplayObject):void{
Tweener.addTween(d,{ alpha:0.6, time:0.3, transition:"easeInOutQuad", onCompleteParams:[d], onComplete:alpha2});
}
function alpha2(d:DisplayObject):void{
Tweener.addTween(d,{ alpha:0.8, time:0.3, transition:"easeInOutQuad", onCompleteParams:[d], onComplete:alpha1});
}