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

つまんでたおして

*遊び方
上にあるスタートボタンを押して始めてください。
敵の画像が表示されたら、画像の一部を左クリックして、左クリックしたままなるべく遠くにドラッグしてください。
もし画像が伸びたら、伸びた分だけダメージを与えることができます。画像が伸びなかったら、ダメージを与えることはできません。
十分にダメージを与えたら、その部分だけ色が薄くなります。色が薄くなったところはクリックすることはできないので、別の個所を攻撃してください。
*勝敗
PlayerのHPが下に表示されます。
これが0になるとLoseで、HPが0になる前に敵の弱点を破壊すればWinとなります。
/**
 * Copyright h_kamizono ( http://wonderfl.net/user/h_kamizono )
 * MIT License ( http://www.opensource.org/licenses/mit-license.php )
 * Downloaded from: http://wonderfl.net/c/mCms
 */

package {
    import flash.display.Sprite;
    import flash.display.Bitmap;
    import flash.display.BitmapData;
    import flash.display.Loader;
    import flash.net.URLRequest;
    import flash.system.LoaderContext;
    import flash.events.Event;
    import com.bit101.components.PushButton;
    
    public class Main extends Sprite 
    {
        private var _loader:Loader; // モンスター表示用コンテナ
        private var _startButton:PushButton;
        private var _enemyBtmp:Bitmap;
        private var _player:Player;
        private var _enemy:Enemy;
        
        private var _hpView:HpView; // HP表示
        private var _serifView:SerifView;
        private var _strView:StringView;
        
        //start flag
        private var _startf:Boolean = false;
        
        
        public function Main() 
        {
            setStartButton();
            setHpView();
            setSerifView();
            setStringView();
            // モンスターをロードする
            _loader=new Loader();
            var context:LoaderContext=new LoaderContext(true);
            _loader.contentLoaderInfo.addEventListener(Event.COMPLETE, picsOnComplete);
            _loader.load(new URLRequest(TigerImgUrl), context);
            
        }
        
        // モンスターのロード完了時の処理
        private function picsOnComplete(eventObj:Event):void
        {
            _loader.removeEventListener(Event.COMPLETE, picsOnComplete);
            var enemyBtmpd:BitmapData = new BitmapData(_loader.width, _loader.height);
            enemyBtmpd.draw(_loader);
            _enemyBtmp = new Bitmap(enemyBtmpd);
            
            // game start
            addEventListener(Event.ENTER_FRAME, onEnterFrame);
        }
        
        // startボタンを配置する
        private function setStartButton():void
        {
            _startButton = new PushButton(this, 0, 0, "start", onStartButtonClick);
            _startButton.y = 10;
            _startButton.x = 170;
        }
        private function setHpView():void
        {
            // playerのHPを表示する
            var cHP:uint = 0;
            if (_player) cHP = _player.HP
            _hpView=new HpView(cHP, PlayerHP);
            _hpView.y= 440;
            _hpView.x= 170;
            addChild(_hpView);
        }
        private function setSerifView():void
        {
            _serifView = new SerifView();
            _serifView.y = 360;
            _serifView.x = 40;
            addChild(_serifView);
        }
        private function setStringView():void
        {
            _strView = new StringView();
            _strView.y = 170;
            _strView.x = 170;
            addChild(_strView);
        }
        private function onStartButtonClick(evt:Event):void { _startf = true; }
        
        // game loop
        private function onEnterFrame(e:Event):void
        {
            // HP表示を更新する
            if (_player) _hpView.update(_player.HP);
            // セリフ表示を更新する
            if (_enemy && _enemy.serif) _serifView.update(_enemy.serif);
            if (_startf)
            {
                delAll();
                _serifView.update("");
                _strView.update("");
                //this.removeChild(_strView);
                _player = new Player(PlayerHP, TigerAttackFrequency);
                addChild(_player);
                _enemy = new Enemy(TigerCol, TigerRow, Tiger_ID_HP, TigerWeakPoints, TigerID_SerifEffect);
                _enemy.build(_enemyBtmp, this, stage.stageWidth / 2 - _loader.width / 2, -30 + stage.stageHeight / 2 - _loader.height / 2);
                addChild(_enemy);
                //trace(this.parent.numChildren, this.numChildren);
            }
            // 敵が死亡したとき
            else if (!_startf && _enemy && _enemy.isDead()) 
            {
                _strView.update("Win");
                _hpView.update(_player.HP);
                delAll();
            }
            // playerが死亡したとき
            else if (!_startf && _player && _player.isDead())
            {
                _strView.update("Lose");
                _hpView.update(_player.HP);
                delAll();
            }
            // playerのターンが終了
            else if (!_startf && _player && _player.isEndTurn())
            {
                _player.HP -= _enemy.attack(TigerDefaultDamage, TigerID_Animation);
                _serifView.update(_enemy.serif, false);
                //trace(this.numChildren, this.getChildAt(0), _player.isDead());
            }
            
        }
        
        private function delAll():void
        {
            _startf = false;
            // ゲームが終わったら全部消す
            if (_player) 
            {
                this.removeChild(_player);
                _player = null;
            }
            if (_enemy)
            {
                _enemy.delAllTile(this);
                this.removeChild(_enemy);
                _enemy = null;
            }
        }
        
    }
}

class Character extends Sprite 
{
    public function Character() 
    {
        if (stage) init(null);
        else addEventListener(Event.ADDED_TO_STAGE, init);
    }
    public function isDead():Boolean { return true; }
    protected function init(evt:Event) : void 
    {
        if (evt != null) removeEventListener(Event.ADDED_TO_STAGE, init);
        stage.addEventListener(MouseEvent.MOUSE_UP, outMouse);
    }
    protected function outMouse(evt:MouseEvent):void {}
}

class Player extends Character
{
    private var _HP:int = 0;
    // playerの攻撃回数
    private var _af:uint;
    private var _caf:uint;
    public function Player(hitPoint:int, attackFrequency:uint)
    {
        _HP = hitPoint;
        _af = _caf = attackFrequency;
        super();
    }
    public override function isDead():Boolean { return _HP <= 0; }
    public function isEndTurn():Boolean
    {
        var f:Boolean = _caf == 0;
        if (f) _caf = _af;
        return f;
    }
    protected override function outMouse(evt:MouseEvent):void
    {
        if (_caf > 0) --_caf; //trace(_caf,_af);
    }
    // getter and setter
    public function get HP():uint { return _HP; }
    public function set HP(value:uint):void 
    {
        _HP = value;
    }
}

import flash.display.Bitmap;
import flash.display.BitmapData;
import flash.events.MouseEvent;
import flash.events.Event;
import flash.geom.Point;
import flash.geom.Matrix;
import flash.geom.ColorTransform;
import flash.geom.Rectangle;
import caurina.transitions.Tweener;
// 敵クラス、敵のタイルの管理など
class Enemy extends Character 
{
    private var _cols:uint;
    private var _rows:uint;
    private var _ID_HP:Object;
    private var _wp:Array;
    
    /*
     * _ID_SerifEffect の使い方
     * _ID_SerifEffect[id][SERIF][DAMAGE] => あるIDのタイルに設定したダメージを受けた時のセリフ
     */
    private var _ID_SerifEffect:Object;
    private static const SERIF:uint = 0;
    private static const EFFECT:uint = 1;
    private static const ATTACK:uint = 0;
    private static const DAMAGE:uint = 1;
    private static const DESTROY:uint = 2;
    
    private var _tileArray:Array;
    private var _serif:String = null;
    private var _effectA:Array = null;
    private var _effectD:Array = null;
    
    private var _attackTimes:uint = 1; 
    
    public function Enemy(cols:uint, rows:uint, ID_HP:Object, weakPoints:Array, ID_SerifEffect:Object)
    {
        _cols = cols; _rows = rows;
        _ID_HP = ID_HP;
        _wp = weakPoints;
        _ID_SerifEffect = ID_SerifEffect;
        _tileArray = new Array();
        
        super();
    }
    
    // 敵の画像からタイルを生成
    public function build(btmp:Bitmap, main:Sprite, offsetx:uint = 0, offsety:uint = 0):void 
    {    
        // タイルのサイズ
        var w:Number = btmp.width / _cols;
        var h:Number = btmp.height / _rows;
        
        for (var y:int = 0; y < _rows; ++y) 
        {
            for (var x:int = 0; x < _cols; ++x) 
            {
                // タイル生成
                var id:uint =  x + y * _cols;
                var bitmap:BitmapData = clip(w, h, btmp, w * x, h * y);
                var tile:Tile = new Tile(id, btmp.x + w * x + offsetx, btmp.y + h * y + offsety, bitmap, w, h);
                
                // IDのないタイルは操作できないように、IDのあるタイルにはHPを設定
                if (_ID_HP[id] == undefined) tile.delEventListener();
                else if (_ID_HP[id]) tile.HP = _ID_HP[id];
                // タイルの表示
                tile.draw();
                
                _tileArray.push(tile);
                main.addChild(tile);
            }
        }
    }
    // 弱点となるタイルのHPが0になったらtrue
    public override function isDead():Boolean
    {
        for (var i:uint = 0; i < _wp.length; ++i)
        {
            var id:uint = _tileArray[_wp[i]].tileID;
            if (_ID_HP[id] && _tileArray[_wp[i]].HP > 0) return false;
        }
        return true;
    }
    // すべてのタイルを削除
    public function delAllTile(main:Sprite):void
    {
        if (_tileArray.length == 0) return;
        for each (var tile:Sprite in _tileArray)
        {
            main.removeChild(tile);
            tile = null;
        }
    }
    
    public function attack(damage:uint, ID_Animation:Object):uint
    {
        var id:int = -1;
        var tmp:int = 0;
        var d:uint = 0; 
        var at:int = _attackTimes;
        var serif:String = "";
        var atupf:Boolean = true;
        while (at > 0)
        {
            // select id
            while (id == -1)
            {
                tmp = int(Math.random() * _tileArray.length);
                if (_ID_SerifEffect[tmp] != undefined && _tileArray[tmp].HP > 0) id = tmp;
            }
            tmp = int(Math.random() * _ID_SerifEffect[id][SERIF][ATTACK].length);
            serif += _ID_SerifEffect[id][SERIF][ATTACK][tmp] + " ";
            tmp = int(Math.random() * _ID_SerifEffect[id][EFFECT][ATTACK].length);
            _effectA = _ID_SerifEffect[id][EFFECT][ATTACK][tmp];
            
            var tmpdamage:int = damage;
            switch (_effectA[0]) 
            {
                // 攻撃力が上がる
                case "attack":
                tmpdamage *= _effectA[1], d += tmpdamage;
                break;
                // 攻撃回数が増える
                case "atup":
                if (atupf) at += _effectA[1], atupf = false, d = damage, serif = "連続攻撃!! " + serif;
                break;
            }
            if (ID_Animation && ID_Animation[id]) ID_Animation[id](_tileArray);
            id = -1; at -= 1;
        }
        //trace(serif, _effectA, d);
        _serif = serif + "\n" + d + "のダメージをくらった!!"; _effectA = null;
        return d;
    }
    
    // 攻撃を受けた時のアニメーション実行とセリフのセット
    protected override function outMouse(evt:MouseEvent):void
    {
        for (var i:uint = 0; i < _tileArray.length; ++i)
        {
            if (_ID_HP[i] && _tileArray[i].mouseDown) 
            {
                _tileArray[i].outMouse();
                var id:uint = i;
                _tileArray[i].addEventListener("animeComplete", function(event:Event):void 
                {
                    //trace(id, i, _tileArray[id].HP)
                    if (_tileArray[id].HP <= 0) setSerifEffect(id, DESTROY);
                    else setSerifEffect(id, DAMAGE);
                });
            }
        }
    }
    
    
    private function setSerifEffect(id:uint, add:uint):void
    {
        if (_ID_SerifEffect[id] == undefined) 
        { 
            _serif = "あまりダメージを受けていないようだ。";
        }
        else
        {
            var i:uint = uint(Math.random() * _ID_SerifEffect[id][SERIF][add].length);
            _serif = _ID_SerifEffect[id][SERIF][add][i];
            i = uint(Math.random() * _ID_SerifEffect[id][EFFECT][add].length);
            _effectD = _ID_SerifEffect[id][EFFECT][add][i];
            
        }
        reflectEffect(id);
    }
    
    private function reflectEffect(id:uint):void
    {
        //trace(_effectD, _effectD == Nothing);
        if (_effectD && _effectD != Nothing)
        {
            switch (_effectD[0]) 
            {
                case "defence":
                _serif += " \n 防御力があがったようだ。";
                _tileArray[id].def = _effectD[1];
                break;
                case "cure":
                _serif += " \n 敵の体の一部が回復しているようだ"; 
                _tileArray[id].HP += _effectD[1];
                if (_ID_HP[id] < _tileArray[id].HP) _tileArray[id].HP = _ID_HP[id];
                break;
                case "allcure":
                _serif += " \n 敵の体が回復しているようだ"; 
                for (var i:uint = 0; i < _tileArray.length; ++i)
                {
                    var id2:uint = _tileArray[i].tileID;
                    if (_ID_HP[id2] != undefined) _tileArray[id2].HP += _effectD[1];
                    if (_ID_HP[id2] < _tileArray[id2].HP) _tileArray[id2].HP = _ID_HP[id2];
                }
                break;
                case "relate":
                _tileArray[_effectD[1]].HP -= 100;
                break;
            }
        }
    }
    
    // 指定したサイズと位置で画像を切り取り
    private function clip(w:Number, h:Number, btmp:Bitmap, x:Number, y:Number):BitmapData 
    {
        var bitmap:BitmapData = new BitmapData(w, h, true);
        bitmap.draw(btmp,
                    new Matrix(1, 0, 0, 1, -x, -y),
                    new ColorTransform(),
                    "normal",
                    new Rectangle(0, 0, w, h),
                    true);
        return bitmap;
    }
    
    // getter and setter
    public function get serif():String 
    {
        return _serif; 
    }
}


// 参考にしたサイト http://sakef.jp/blog/2010/07/transform_image01/
class Tile extends Sprite 
{
    private var _tileID:uint;
    // Tileの元の位置
    private var _preX:uint;
    private var _preY:uint;
    // Tileの大きさ
    private var _width:uint;
    private var _height:uint;
    // TileのBitmapData
    private var _oriBitmapData:BitmapData;
    
    // 分割数
    private static const hDiv:int = 3;
    private static const vDiv:int = 3;
    
    // 動かす点を元の位置に戻すためのPoint
    private var _point0:Sprite;
    private var _point1:Sprite;
    private var _point2:Sprite;
    private var _point3:Sprite;
    // 動かす点
    private var _b0:Point;
    private var _b1:Point;
    private var _b2:Point;
    private var _b3:Point;
    // Tweenerで使用する変数
    private var _X:int;
    private var _Y:int;
    // 0, 1, 2, 3, = 左上、 右上、 左下、 右下
    private var _pointNum:String;
    
    private var _mouseDown:Boolean = false;
    private var _mouseUp:Boolean = false; 
    
    private var _damage:int = -1;
    private var _HP:int = -1;
    private var _def:Number = 1.0;
    
    // 攻撃アニメーション用のフラグ
    private var _animef:Boolean = false;
    
    public function Tile(id:uint, preX:uint, preY:uint, bitmap:BitmapData, w:uint, h:uint)
    {
        _tileID = id;
        this.x = preX; this.y = preY;
        _preX = preX; _preY = preY;
        _oriBitmapData = bitmap;
        _width = w; _height = h;
        
        this.name = "tile";
        
        setEventListener();
    }
    
    // Tileを表示
    public function draw():void
    {
        _oriBitmapData.lock();
        with (this.graphics) 
        {
            clear(); beginBitmapFill(_oriBitmapData); drawRect(0, 0, _width, _height); endFill();
        }
        _oriBitmapData.unlock();
    }
    
    public function setCircle():void
    {
        // 動かす点の用意 (左上、 右上、 左下、 右下)
        _point0 = createCircle(0, 0);
        _point1 = createCircle(_width, 0);
        _point2 = createCircle(0, _height);
        _point3 = createCircle(_width, _height);
    }
    
    public function setPoints():void
    {
        _b0 = new Point(0, 0); _b1 = new Point(_width, 0);
        _b2 = new Point(0, _height); _b3 = new Point(_width, _height);
    }
    
    public function delCircle():void
    {
        if (_point0 == null) return;
        _point0.graphics.clear(); _point1.graphics.clear();
        _point2.graphics.clear(); _point3.graphics.clear();
        if (_point0.parent) removeChild(_point0); 
        if (_point1.parent) removeChild(_point1);
        if (_point2.parent) removeChild(_point2); 
        if (_point3.parent) removeChild(_point3);
        _point0 = null; _point1 = null; _point2 = null; _point3 = null;
    }
    
    public function outMouse():void
    {
        // アニメーション中ならなにもしない
        if (Tweener.isTweening(this)) return;
        this._mouseUp = true;
        this._X = mouseX; this._Y = mouseY;
        Tweener.addTween(this, { X:0, Y:0, time:0.4, transition:"easeOutBounce", onComplete: function():void 
        {    
            if (this._damage > 0) this._HP -= this._damage * this._def;
            this._damage = -1;
            //trace(this._HP, this._tileID);
            
            this._mouseDown = false;
            this._mouseUp = false;
            this.delCircle();            
            
            // HPが0以下でアルファ値を下げる
            if (this._HP <= 0) 
            {
                this.alpha = 0.4;
                this.delEventListener();
            }
            // アニメーション終了
            dispatchEvent(new Event("animeComplete"));
        }});
    }
    
    public function delEventListener():void 
    {
        this.removeEventListener(Event.ENTER_FRAME, onEnterFrame);
        this.removeEventListener(MouseEvent.MOUSE_DOWN, onDown);
        Tweener.removeAllTweens();
    }
    
    private function setEventListener():void 
    {
        this.addEventListener(Event.ENTER_FRAME, onEnterFrame);
        this.addEventListener(Event.ENTER_FRAME, onEnterFrame2);
        this.addEventListener(MouseEvent.MOUSE_DOWN, onDown);
    }
    
    // 画像を描写する関数
    private function onEnterFrame(e:Event):void
    {
        if (_mouseDown && !_animef) {
            this.graphics.clear();
            // 描写
            // こちらを参考にしました。:http://www.d-project.com/flex/009_FreeTransform/
            var a0:Point = new Point; var a1:Point = new Point(_width, 0); 
            var a2:Point = new Point(0, _height); var a3:Point = new Point(_width, _height);
            /*
            _b0 = new Point(_point0.x, _point0.y); _b1 = new Point(_point1.x, _point1.y);
            _b2 = new Point(_point2.x, _point2.y); _b3 = new Point(_point3.x, _point3.y);
            */
            setPoints();
            if (_mouseUp && outPoints()) 
            {
                switch (_pointNum)
                {
                    case "0":
                    _b0.x = _X; _b0.y = _Y;
                    break;
                    case "1":
                    _b1.x = _X + _width; _b1.y = _Y;
                    break;
                    case "2":
                    _b2.x = _X; _b2.y = _Y + _height;
                    break;
                    case "3":
                    _b3.x = _X + _width; _b3.y = _Y + _height;
                    break;
                }
            } 
            else
            {
                var d0:uint = distance(mouseX, mouseY, _b0.x, _b0.y);
                var d1:uint = distance(mouseX, mouseY, _b1.x, _b1.y);
                var d2:uint = distance(mouseX, mouseY, _b2.x, _b2.y);
                var d3:uint = distance(mouseX, mouseY, _b3.x, _b3.y);
                // マウスの位置と近い座標を得る
                var data:Array = new Array(d0, d1, d2, d3); data.sort(Array.NUMERIC);
                if (outPoints())
                {
                    switch (data[0])
                    {
                        case d0:
                        _pointNum = "0"; _b0.x = mouseX; _b0.y = mouseY;
                        break;
                        case d1:
                        _pointNum = "1"; _b1.x = mouseX; _b1.y = mouseY;
                        break;
                        case d2:
                        _pointNum = "2"; _b2.x = mouseX; _b2.y = mouseY;
                        break;
                        case d3:
                        _pointNum = "3"; _b3.x = mouseX; _b3.y = mouseY;
                        break;
                    }
                    // damage用に
                    _damage = data[0] >> 10;
                }
            }
            
 
            for (var i:int = 0; i < hDiv; i++)
            {
                var h0:Number=i / hDiv; var h1:Number=(i + 1) / hDiv;
 
                var ta0:Point = getPoint(a0, a1, h0); var ta1:Point = getPoint(a0, a1, h1);
                var ta2:Point = getPoint(a2, a3, h0); var ta3:Point = getPoint(a2, a3, h1);
                var tb0:Point = getPoint(_b0, _b1, h0); var tb1:Point = getPoint(_b0, _b1, h1);
                var tb2:Point = getPoint(_b2, _b3, h0); var tb3:Point = getPoint(_b2, _b3, h1);
                
                for(var j:int=0; j < vDiv; j++)
                {
                    var v0:Number = j / vDiv; var v1:Number = (j + 1) / vDiv;
                    var tta0:Point = getPoint(ta0, ta2, v0); var tta1:Point = getPoint(ta0, ta2, v1);
                    var tta2:Point = getPoint(ta1, ta3, v0); var tta3:Point = getPoint(ta1, ta3, v1);
                    var ttb0:Point = getPoint(tb0, tb2, v0); var ttb1:Point = getPoint(tb0, tb2, v1);
                    var ttb2:Point = getPoint(tb1, tb3, v0); var ttb3:Point = getPoint(tb1, tb3, v1);
                    
                    var mtx:Matrix = createMatrix(tta0, tta1, tta2, ttb0, ttb1, ttb2);
                    with (this.graphics) 
                    {
                        beginBitmapFill(_oriBitmapData, mtx);
                        moveTo(ttb0.x, ttb0.y);
                        lineTo(ttb1.x, ttb1.y); 
                        lineTo(ttb2.x, ttb2.y);
                        endFill();
                    
                        mtx = createMatrix(tta3, tta1, tta2, ttb3, ttb1, ttb2);
                        beginBitmapFill(_oriBitmapData, mtx);
                        moveTo(ttb3.x, ttb3.y);
                        lineTo(ttb1.x, ttb1.y);
                        lineTo(ttb2.x, ttb2.y);
                        endFill();
                    }
                }
            }
        } 
    }
    // メンバー変数の4つの点からなる四角形の外にマウスが動いたらtrue
    private function outPoints():Boolean
    {
        if (0 <= mouseX && 0 <= mouseY && _width >= mouseX && _height >= mouseY)
        {
            return false;
        }
        return true;
    }
    
    // 画像を描写する関数(攻撃アニメーション用)
    private function onEnterFrame2(e:Event):void
    {
        if (_animef && this.parent) {
            this.parent.setChildIndex(this, this.parent.numChildren - 1);
            this.graphics.clear();
            // 描写
            // こちらを参考にしました。:http://www.d-project.com/flex/009_FreeTransform/
            var a0:Point = new Point; var a1:Point = new Point(_width, 0); 
            var a2:Point = new Point(0, _height); var a3:Point = new Point(_width, _height);
            //_pointNum = "0";
            this.setPoints();
            switch (_pointNum)
            {
                    case "0":
                    _b0.x = _X; _b0.y = _Y;
                    break;
                    case "1":
                    _b1.x = _X + _width; _b1.y = _Y;
                    break;
                    case "2":
                    _b2.x = _X; _b2.y = _Y + _height;
                    break;
                    case "3":
                    _b3.x = _X + _width; _b3.y = _Y + _height;
                    break;
                }
          
 
            for (var i:int = 0; i < hDiv; i++)
            {
                var h0:Number=i / hDiv; var h1:Number=(i + 1) / hDiv;
 
                var ta0:Point = getPoint(a0, a1, h0); var ta1:Point = getPoint(a0, a1, h1);
                var ta2:Point = getPoint(a2, a3, h0); var ta3:Point = getPoint(a2, a3, h1);
                var tb0:Point = getPoint(_b0, _b1, h0); var tb1:Point = getPoint(_b0, _b1, h1);
                var tb2:Point = getPoint(_b2, _b3, h0); var tb3:Point = getPoint(_b2, _b3, h1);
                
                for(var j:int=0; j < vDiv; j++)
                {
                    var v0:Number = j / vDiv; var v1:Number = (j + 1) / vDiv;
                    var tta0:Point = getPoint(ta0, ta2, v0); var tta1:Point = getPoint(ta0, ta2, v1);
                    var tta2:Point = getPoint(ta1, ta3, v0); var tta3:Point = getPoint(ta1, ta3, v1);
                    var ttb0:Point = getPoint(tb0, tb2, v0); var ttb1:Point = getPoint(tb0, tb2, v1);
                    var ttb2:Point = getPoint(tb1, tb3, v0); var ttb3:Point = getPoint(tb1, tb3, v1);
                    
                    var mtx:Matrix = createMatrix(tta0, tta1, tta2, ttb0, ttb1, ttb2);
                    with (this.graphics) 
                    {
                        beginBitmapFill(_oriBitmapData, mtx);
                        moveTo(ttb0.x, ttb0.y);
                        lineTo(ttb1.x, ttb1.y); 
                        lineTo(ttb2.x, ttb2.y);
                        endFill();
                    
                        mtx = createMatrix(tta3, tta1, tta2, ttb3, ttb1, ttb2);
                        beginBitmapFill(_oriBitmapData, mtx);
                        moveTo(ttb3.x, ttb3.y);
                        lineTo(ttb1.x, ttb1.y);
                        lineTo(ttb2.x, ttb2.y);
                        endFill();
                    }
                }
            }
        } 
    }
    
    private function distance(x1:uint, y1:uint, x2:uint, y2:uint):uint
    {
        return (x1 - x2) * (x1 - x2) + (y1 - y2) * (y1 - y2);
    }
    
    // 分割点計算用関数
    // こちらのものを使わせてもらいました。:http://www.d-project.com/flex/009_FreeTransform/
    private function getPoint(p0:Point, p1:Point, ratio:Number):Point
    {
        return new Point(p0.x + (p1.x - p0.x) * ratio, p0.y + (p1.y - p0.y) * ratio);
    }
 
    // 変形用行列の作成用関数
    // こちらのものを使わせてもらいました。:http://www.d-project.com/flex/009_FreeTransform/
    private function createMatrix(a0:Point, a1:Point, a2:Point, point0:Point, point1:Point, point2:Point):Matrix
    {
        var ma:Matrix = new Matrix(a1.x - a0.x, a1.y - a0.y, a2.x - a0.x, a2.y - a0.y);
        var mb:Matrix = new Matrix(point1.x - point0.x, point1.y - point0.y, point2.x - point0.x, point2.y - point0.y);
        ma.invert();
 
        var m:Matrix = new Matrix();
        m.translate( -a0.x, -a0.y);
        m.concat(ma);
        m.concat(mb);
        m.translate(point0.x, point0.y);
        return m;
    }
    
    // 円を作る関数
    private function createCircle(x:Number, y:Number):Sprite
    {
        var sp:Sprite = addChild(new Sprite) as Sprite;
        sp.x = x;
        sp.y = y;
        with (sp.graphics) {beginFill(0xffffff, 0.1); drawCircle(0, 0, 0.1); endFill();}
        return sp;
    }
    
    private function onDown(evt:MouseEvent):void
    {
        if (evt.target.name == "tile")
        {
            evt.target.parent.setChildIndex(evt.target, evt.target.parent.numChildren - 1);
            evt.target.setCircle();
            evt.target.mouseDown= true;
        }
    }
    
    // getter and setter
    public function get tileID():uint { return _tileID; }
    public function get preX():uint { return _preX; }
    public function get preY():uint { return _preY; }
    public function get X():int { return _X; }
    public function set X(value:int):void 
    {
        _X = value;
    }
    public function get Y():int { return _Y; }
    public function set Y(value:int):void 
    {
        _Y = value;
    }
    public function get mouseUp():Boolean { return _mouseUp; }
    public function set mouseUp(value:Boolean):void 
    {
        _mouseUp = value;
    }
    public function get mouseDown():Boolean { return _mouseDown; }
    public function set mouseDown(value:Boolean):void 
    {
        _mouseDown = value;
    }
    public function get HP():int { return _HP; }
    public function set HP(value:int):void 
    {
        _HP = value;
    }
    
    public function get def():Number { return _def; }
    public function set def(value:Number):void 
    {
        _def = value;
    }
    
    public function get animef():Boolean { return _animef; }
    
    public function set animef(value:Boolean):void 
    {
        _animef = value;
    }
    
    public function get pointNum():String { return _pointNum; }
    
    public function set pointNum(value:String):void 
    {
        _pointNum = value;
    }
}

import flash.display.Sprite;
import flash.text.TextField;
import flash.text.TextFieldAutoSize;
import flash.text.TextFormat;

class View extends Sprite
{
    protected var _text:TextField;
    protected var _format:TextFormat = new TextFormat();
    function View() 
    {
        _text = new TextField();
        
        _format.size = 14;
        _format.bold = true;
        _text.autoSize = TextFieldAutoSize.LEFT;
        _text.defaultTextFormat=_format;
        addChild(_text);
    }
}

class HpView extends View
{
    private var _hpMax:int;

    function HpView(hp:int, hpMax:int)
    {
        super();
        _hpMax=hpMax;
        update(hp);
    }
    // HP表示を更新する
    public function update(hp:int):void
    {
        if (((hp * 100) / _hpMax) <= 30) _text.textColor = 0xFF0000;
        else _text.textColor = 0x000000;
        _text.text="Player HP : " + String(hp) + "/" + _hpMax;
    }
}

class SerifView extends View
{
    private var _preStr:String = "";
    function SerifView()
    {
        super();
    }
    public function update(str:String, isPlayer:Boolean = true):void
    {
        if (isPlayer) _text.textColor = 0x000000;
        else _text.textColor = 0xFF0000;
        _text.text = str;
    }
}

class StringView extends Sprite
{
    protected var _text:TextField;
    protected var _format:TextFormat = new TextFormat();
    function StringView()
    {
        _text = new TextField();
        
        _format.size = 50;
        _format.bold = true;
        _text.autoSize = TextFieldAutoSize.LEFT;
        _text.defaultTextFormat=_format;
        addChild(_text);
    }
    public function update(str:String):void
    {
        _text.text = str;
    }
}

//
function makeObject(a:Array, b:Array):Object
{
    var obj:Object = new Object();
    for (var i:int = 0; i < a.length; ++i) 
    {
        obj[a[i]] = b[i];
    }
    return obj;
}

// playerの設定
var PlayerHP:int = 2000;

// Tiger(公式の白っぽいトラのこと)の設定
// Tigerの画像のURL
var TigerImgUrl:String="http://assets.wonderfl.net/images/related_images/6/6d/6d2a/6d2aac9165308e05d07f52232f99bfe9d52a06fb";
//  Tigerの画像をいくつにわけるか(xがcolで、yがrow)  
var TigerCol:uint = 10;
var TigerRow:uint = 7;
// Tigerの攻撃回数(プレイヤーが何回攻撃したら1回攻撃するかという値)
var TigerAttackFrequency:uint = 3;
// 敵の画像で使用するタイルのID、ここにあるIDのタイルが伸縮し、ダメージを与えることができる。
var TigerIDData:Array = [23, 24, 25, 26, 33, 34, 35, 36, 42, 43, 44, 46, 47, 48, 57];
// TigerIDDataで定義したIDのタイルのhitPoint、TigerIDDataの配列と同じ長さに(15)
var TigerHPData:Array = [1000, 1400, 1000, 1000, 1000, 300, 400, 1000, 300, 2000, 1000, 1000, 9000, 300, 200];
// TigerのIDとHPの連想配列(IDがkeyでHPがvalue)
var Tiger_ID_HP:Object = makeObject(TigerIDData, TigerHPData);
// Tigerの弱点となるタイルのID 
var TigerWeakPoints:Array = [24];
// それぞれのタイルがもつセリフと効果のあるID配列
var TigerSerifID:Array = [23, 24, 34, 35, 42, 43, 48, 57];
// セリフと効果配列
var Nothing:Array = ["", 0];
var TigerSerifEffect:Array = [ 
                               [ [ ["尻尾の攻撃をうけた。"], ["痛めた尻尾をなめているようだ。"], ["尻尾をひきちぎった。"] ], [ [["attack", 1.2]], [["cure", 500]], [Nothing] ] ],
                               [ [ ["角の攻撃をうけた。"], ["非常に痛そうだ。", "角を必死に守ろうとしている。"], ["Tigerはもろく崩れ去った。"] ], [ [["attack", 5.0]], [["defence", 0.7]], [Nothing] ] ],
                               [ [ ["左目で睨まれた。"], ["左目をこすっている。"], ["左目をつぶした。"] ], [ [["atup", 1]], [["cure", 500]], [Nothing] ] ],
                               [ [ ["右目で睨まれた。"], ["右目をこすっている。"], ["右目をつぶした。"] ], [ [["atup", 2]], [["cure", 3000],["allcure", 1000]], [Nothing] ] ],
                               [ [ ["左爪の攻撃をうけた。"], ["左爪にひびが入ったようだ。"], ["左爪を剥いだ。"] ], [ [["attack", 1.2]], [Nothing], [["relate", 43]] ] ],
                               [ [ ["左爪の攻撃をうけた。"], ["左爪にひびが入ったようだ。"], ["左爪を剥いだ。"] ], [ [["attack", 1.1]], [Nothing], [["relate", 42]] ] ],
                               [ [ ["右爪の攻撃をうけた。"], ["右爪にひびが入ったようだ。"], ["右爪を剥いだ。"] ], [ [["attack", 4.0]], [Nothing], [["relate", 57]] ] ],
                               [ [ ["右爪の攻撃をうけた。"], ["右爪にひびが入ったようだ。"], ["右爪を剥いだ。"] ], [ [["attack", 3.5]], [Nothing], [["relate", 48]] ] ] 
                             ];
                        
var TigerID_SerifEffect:Object = makeObject(TigerSerifID, TigerSerifEffect);
// Tiger のデフォルトダメージ
var TigerDefaultDamage:uint = 100;

// 角アニメーション doAnimation(_tileArray[24], 20,150,0.5); // 角
function hornAnimation(tileArray:Array):void
{
    var tile:Tile = tileArray[24];
    tile.animef = true; tile.pointNum = "3";
    Tweener.addTween(tile, { X:20, Y:150, time:0.5, transition:"easeOutElastic", onComplete: function():void 
    {
        Tweener.addTween(this, { X:0, Y:0, time:0.4, onComplete: function():void
        {
            tile.animef = false;
        } } );
    } } );
}
// 尻尾 doAnimation(_tileArray[22],_tileArray[23], 30,50,0.5); // 尻尾
function tailAnimation(tileArray:Array):void
{
    var tile1:Tile = tileArray[22]; var tile2:Tile = tileArray[23];
    tile1.animef = true; tile2.animef = true;
        tile1.pointNum = "0"; tile2.pointNum = "0";
        Tweener.addTween(tile1, { X: -190, Y:130, time:0.5, transition:"easeOutElastic", onComplete: function():void 
        {
            Tweener.addTween(this, { X:0, Y:0, time:0.2, onComplete: function():void
            {
                tile1.animef = false;
            } } );
        } } );
        Tweener.addTween(tile2, { X: -190, Y:130, time:0.5, transition:"easeOutElastic", onComplete: function():void 
        {
            Tweener.addTween(this, { X:0, Y:0, time:0.2, onComplete: function():void
            {
                tile2.animef = false;
            } } );
        } } );
}
    
// left claw 
function lclawAnimation(tileArray:Array):void
{
    var tile1:Tile = tileArray[42]; var tile2:Tile = tileArray[43];
        tile1.animef = true; tile2.animef = true;
        tile1.pointNum = "2"; tile2.pointNum = "3";
        Tweener.addTween(tile1, { X: -35, Y:50, time:0.5, transition:"easeOutElastic", onComplete: function():void 
        {
            Tweener.addTween(this, { X:0, Y:0, time:0.2, onComplete: function():void
            {
                tile1.animef = false;
            } } );
        } } );
        Tweener.addTween(tile2, { X:60, Y:100, time:0.5, transition:"easeOutElastic", onComplete: function():void 
        {
            Tweener.addTween(this, { X:0, Y:0, time:0.2, onComplete: function():void
            {
                tile2.animef = false;
            } } );
        } } );
}

// right claw
 function rclawAnimation(tileArray:Array):void
    {
        var tile1:Tile = tileArray[48]; var tile2:Tile = tileArray[57]; var tile3:Tile = tileArray[47]; 
        tile1.animef = true; tile2.animef = true; tile3.animef = true;
        tile1.pointNum = "3"; tile2.pointNum = "3"; tile3.pointNum = "3";
        Tweener.addTween(tile1, { X:30, Y:50, time:0.5, transition:"easeOutElastic", onComplete: function():void 
        {
            Tweener.addTween(this, { X:0, Y:0, time:0.2, onComplete: function():void
            {
                tile1.animef = false;
            } } );
        } } );
        Tweener.addTween(tile2, { X:60, Y:70, time:0.5, transition:"easeOutElastic", onComplete: function():void 
        {
            Tweener.addTween(this, { X:0, Y:0, time:0.2, onComplete: function():void
            {
                tile2.animef = false;
            } } );
        } } );
        Tweener.addTween(tile3, { X:10, Y:20, time:0.5, transition:"easeOutElastic", onComplete: function():void 
        {
            Tweener.addTween(this, { X:0, Y:0, time:0.2, onComplete: function():void
            {
                tile3.animef = false;
            } } );
        } } );
    }
    
// 
var TigerAnimationFunction:Array = [tailAnimation, hornAnimation, null, null, lclawAnimation, lclawAnimation, rclawAnimation, rclawAnimation];
var TigerID_Animation:Object = makeObject(TigerSerifID, TigerAnimationFunction);