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

forked from: FFPS - wonderflVer

FFPS ( http://br.wda.jp/wp/ffps/ )
@author br

操作方法
WASD    : 移動
R        : リロード
Q        : 視点の固定
V        : スコープを覗く/外す
X        : 装填(ボルトアクションライフル時のみ)
Shift    : アクセル
Mouse    : 視点の移動
1-9        : 武器の変更

ステージ情報は、2443行目から

Alternativa3D

import jp.wda.br.FFPS.debug.Debugger;

BetweenAS3

BulkLoader

import br.com.stimuli.loading.BulkLoader;
import br.com.stimuli.loading.BulkProgressEvent;

Arthropod Debugger

import com.carlcalderon.arthropod.Debug;

Flash

MinimalComp

Frocessing

SiON
Get Adobe Flash player
by Glidias 28 Sep 2011
// forked from tomo_mk's FFPS - wonderflVer
/**
 * FFPS ( http://br.wda.jp/wp/ffps/ )
* @author br
* 
*    操作方法
*    WASD    : 移動
*     R        : リロード
*     Q        : 視点の固定
*     V        : スコープを覗く/外す
*     X        : 装填(ボルトアクションライフル時のみ)
*     Shift    : アクセル
*     Mouse    : 視点の移動
*     1-9        : 武器の変更
* 
* 
*     ステージ情報は、2443行目から
*/

package {
    
    /* Alternativa3D
    // /////////////////////////////////////////////////////// */
    import alternativ5.engine3d.controllers.WalkController;
    import alternativ5.engine3d.controllers.ObjectController;
    import alternativ5.engine3d.core.Camera3D;
    import alternativ5.engine3d.core.Object3D;
    import alternativ5.engine3d.core.Scene3D;
    import alternativ5.engine3d.core.Mesh;
    import alternativ5.engine3d.core.Vertex;
    import alternativ5.engine3d.core.Face;
    import alternativ5.engine3d.core.Surface;
    import alternativ5.engine3d.display.View;
    import alternativ5.engine3d.events.MouseEvent3D;
    import alternativ5.engine3d.materials.DrawPoint;
    import alternativ5.engine3d.materials.SurfaceMaterial;
    import alternativ5.engine3d.materials.DevMaterial;
    import alternativ5.engine3d.materials.FillMaterial;
    import alternativ5.engine3d.materials.TextureMaterial;
    import alternativ5.engine3d.materials.TextureMaterialPrecision;
    import alternativ5.engine3d.materials.WireMaterial;
    import alternativ5.types.Map;
    import alternativ5.types.Point3D;
    import alternativ5.types.Set;
    import alternativ5.types.Texture
    import alternativ5.utils.FPS;
    import alternativ5.utils.MouseUtils;
    import alternativ5.utils.MathUtils;
    import alternativ5.utils.KeyboardUtils;
    //import jp.wda.br.FFPS.debug.Debugger;
    
    /* BetweenAS3
    // /////////////////////////////////////////////////////// */
    import org.libspark.betweenas3.BetweenAS3;
    import org.libspark.betweenas3.tweens.ITween;
    import org.libspark.betweenas3.events.TweenEvent;
    import org.libspark.betweenas3.easing.Bounce;
    import org.libspark.betweenas3.easing.Elastic;
    import org.libspark.betweenas3.easing.Back;
    
    /* BulkLoader
    // /////////////////////////////////////////////////////// */
    //import br.com.stimuli.loading.BulkLoader;
    //import br.com.stimuli.loading.BulkProgressEvent;
    
    /* Arthropod Debugger
    // /////////////////////////////////////////////////////// */
    //import com.carlcalderon.arthropod.Debug;

    /* Flash
    // /////////////////////////////////////////////////////// */
    import flash.display.Sprite;
    import flash.display.Bitmap;
    import flash.display.BitmapData;
    import flash.display.BlendMode;
    import flash.display.Graphics;
    import flash.events.Event;
    import flash.events.MouseEvent;
    import flash.events.KeyboardEvent;
    import flash.events.TimerEvent;
    import flash.geom.Point;
    import flash.geom.Matrix;
    import flash.text.TextField;
    import flash.text.TextFieldAutoSize;
    import flash.text.TextFormatAlign;
    import flash.text.TextFormat;
    import flash.filters.BlurFilter;
    import flash.media.Sound;
    import flash.media.SoundChannel;
    import flash.media.SoundTransform;
    import flash.net.SharedObject;
    import flash.utils.Timer;
    import flash.utils.SetIntervalTimer;
    import flash.utils.setTimeout;
    
    /* MinimalComp
    // /////////////////////////////////////////////////////// */
    import com.bit101.components.PushButton;
    import com.bit101.components.Label;
    import com.bit101.components.RadioButton;
    import com.bit101.components.CheckBox;
    import com.bit101.components.ProgressBar;
    import com.bit101.components.HUISlider
    import com.bit101.components.HSlider;
    
    /* Frocessing
    // /////////////////////////////////////////////////////// */
    import frocessing.shape.FShapeSVG;
    
    /* SiON
    // /////////////////////////////////////////////////////// */
    import org.si.sion.*;
    
    
    [SWF(width="720", height="480", frameRate="120", backgroundColor="#0")]
    public class Main extends Sprite {
        
        /* SiON
        // /////////////////////////////////////////////////////// */
        private var sionDriver:SiONDriver;
        private var waves:/*SiONVoice*/Array;
        
        /* Game - Core
        // /////////////////////////////////////////////////////// */
        private var ranges:Vector.<Range>;
        private var map:Map;
        
        private var screen:Sprite;
        private var scene:Scene3D;
        private var view:View;
        private var camera:Camera3D;
        private var player:WalkController;
        
        private var eyePoint:Point;
        private const BASE_LINE_METER:Number = 250;
        
        
        /* BulkLoader
        // /////////////////////////////////////////////////////// */
        
        
        /* Game - Array
        // /////////////////////////////////////////////////////// */
        public var periods:/*Period*/Array;
        private var meshes:/*Mesh*/Array;
        private var smashTween2Objects:/*Object*/Array;
        
        private var standupTargets:Vector.<TargetAddress>;
        private var weapons:Vector.<WeaponConfig>;
        
        private var passNumber:Number;
        private var messages:Vector.<Message>;
        
        
        
        /* Flag
        // /////////////////////////////////////////////////////// */
        private var lookingScopeNow:Boolean;
        private var isReloadingNow:Boolean;
        private var isLoadingNow:Boolean;
        private var isMoving:Boolean;
        private var flagQ:Boolean;
        
        private var playingGameID:uint;
        private var usingWeaponID:uint;
        private var runningPeriod4SignalEventType:String;
        private var nextPeriod:String;
        
        /* Reticles
        // /////////////////////////////////////////////////////// */
        private var sight:Sprite;
        private var reticles:/*Sprite*/Array;
        private var reticleSight:Sprite;
        
        /* UserInterface
        // /////////////////////////////////////////////////////// */
        private var userInterface:Sprite;
        private var weaponLabel:TextField;
        private var messageLabel:TextField;
        
        private var walkingSoundChannel:SoundChannel;
        
        private var logo:Bitmap;
        
        /* PublicConfig
        // /////////////////////////////////////////////////////// */
        private var publicConfig:PublicConfig;
        
        /* PlayerConfig
        // /////////////////////////////////////////////////////// */
        private var playerConfigWalkSpeed:Number;
        private var playerConfigWalkSpeedZoomed:Number;
        private var playerConfigJumpSpeed:Number;
        private var playerConfigGravity:Number;
        private var playerConfigHeight:Number;
        private var playerConfigWaggle:Number;
        private var playerConfigWaggleZoomed:Number;
        //private var playerConfigFootStepSound:String;
        
        /* Const
        // /////////////////////////////////////////////////////// */
        private const FOV:Number = 1.5707963267948966;
        private const PI:Number = 3.141592653589793;
        
        /* Debug
        // /////////////////////////////////////////////////////// */
        private var debugMode:Boolean = true;
        private var debugLabel:Label;
        private var debugLabel2:Label;
        
        
        /**
         * Constructor
         * ///////////////////////////////////////////////////////
         */
        public function Main() {
            this.addEventListener(Event.ADDED, init);
        }
        
        /**
         * init
         * @param    e
         */
        public function init(e:Event = null):void {
            /**
             * Remove
             */
            this.removeEventListener(Event.ADDED, init);
            
            /**
             * for debug
             */
            FPS.init(stage);
            //Debug.clear();
            
            
            /**
             * SiON
             */
            sionDriver = new SiONDriver();
            sionDriver.play();
            
            waves = [];
            waves["debug"] = new SiONVoice(5, 4);
            waves["sin"] = new SiONVoice(5, 0);
            
            loadCoreFiles();
            
            
            /**
             * publicConfig
             */
            publicConfig = new PublicConfig();
            with (publicConfig) {
                moveType = PublicConfig.STANDARD;
                rawSpeed = 1;
                volumeBGM = 1;
                volumeMaster = 1;
                volumeSE = 1;
            }
        }
        
        /**
         * loadCoreFiles
         */
        private function loadCoreFiles():void {
            
            //const basePathCore:String = "../../up/files/FFPS/res/core/";
            
            //var coreFilesLoader:BulkLoader = new BulkLoader("coreFilesLoader");
            
            //coreFilesLoader.add(basePathCore + "logo_alternativa3d.png", { type : BulkLoader.TYPE_IMAGE } );
            /*
            coreFilesLoader.add(basePathCore + "brwdajp.png", { type : BulkLoader.TYPE_IMAGE } );
            coreFilesLoader.add(basePathCore + "ffps.png", { type : BulkLoader.TYPE_IMAGE } );
            coreFilesLoader.add(basePathCore + "title.mp3", { type : BulkLoader.TYPE_SOUND } );
            */
            //coreFilesLoader.add(basePathCore + "stages.xml", { type : BulkLoader.TYPE_XML } );
            //
            //coreFilesLoader.addEventListener(BulkLoader.COMPLETE, loadCompleted);
            //coreFilesLoader.addEventListener(BulkLoader.PROGRESS, progressEvent);
            //coreFilesLoader.start();
            
            loadCompleted();
            
            /**
            * ProgressEvent
            * @param    e
            */
            //function progressEvent(e:BulkProgressEvent):void {
            //}
            
            /**
            * ProgressEvent Completed
            * @param    e
            */
            function loadCompleted(/*e:BulkProgressEvent*/):void {
                /**
                * Remove
                */
                //coreFilesLoader.removeEventListener(BulkLoader.COMPLETE, loadCompleted);
                //coreFilesLoader.removeEventListener(BulkLoader.PROGRESS, progressEvent);
                
                //logo = coreFilesLoader.getBitmap(basePathCore + "logo_alternativa3d.png", true);
                
                /**
                 * array range
                 */
                //var stages:XML = XML(coreFilesLoader.getXML(basePathCore + "stages.xml", true));
                var stages:XML = Wonderfl_Resource.STAGES;
                ranges = new Vector.<Range>();
                
                for (var i:uint = 0; i < stages.stages.stage.length(); i++) {
                    ranges.push(new Range(stages.stages.stage[i].@src.toString(), stages.stages.stage[i].@name.toString()));
                }
                
                // call stage select
                stageSelect();
            }
        }
        
        
        /**
         * stageSelect
         */
        private function stageSelect():void {
            
            // call stage ( param : stage_id)
            rangeGameLoadAndStart(0);
        }
        
        /**
         * rangeGameLoadAndStart
         * @param    id stage_id
         */
        public function rangeGameLoadAndStart(id:uint):void {
            
            // if will play range was loaded,
            if (ranges[id].isLoaded) {
                gameStart(id);
            }
            
            // wanst
            else {
                alignmentRange(id);
            }
        }
        
        /**
         * alignmentRange
         * @param    id stage_id
         */
        public function alignmentRange(id:uint):void {
            
            //const rangePath:String = ranges[id].src;
            
            //var rangeResourcesLoader:BulkLoader = new BulkLoader("rangeResourcesLoader");
            //rangeResourcesLoader.add(rangePath, { type: BulkLoader.TYPE_XML } );
            //rangeResourcesLoader.addEventListener(BulkLoader.COMPLETE, loadCompleted);
            //rangeResourcesLoader.start();
            
            
            /**
             * XML loadCompleted
             * @param    evt
             */
            //function loadCompleted(e:BulkProgressEvent):void {
                /**
                 * Remove
                 */
                //rangeResourcesLoader.removeEventListener(BulkLoader.COMPLETE, loadCompleted);
                
                //TODO 置換
                //ranges[id].range = XML(rangeResourcesLoader.getXML(rangePath, true));
                ranges[id].range = Wonderfl_Resource.RANGE;
                //rangeResourcesLoader.removeAll();
                
                // if resources element in xml
                //if ("resources" in ranges[id].range) {
                    
                    // if sounds element in xml
                    //if ("sounds" in ranges[id].range.resources) {
                        //ranges[id].resourcesSounds = new Array();
                        //
                        // sound resources
                        //for (var a:uint = 0; a < ranges[id].range.resources.sounds.sound.length(); a++) {
                            //rangeResourcesLoader.add(ranges[id].range.resources.sounds.sound[a].@src.toString());
                        //}
                    //}
                    
                    // if images element in xml
                    //if ("images" in ranges[id].range.resources) {
                        //ranges[id].resourcesImages = new Array();
                        //
                        //image resources
                        //for (var b:uint = 0; b < ranges[id].range.resources.images.image.length(); b++) {
                            //rangeResourcesLoader.add(ranges[id].range.resources.images.image[b].@src.toString());
                        //}
                    //}
                    
                    //rangeResourcesLoader.addEventListener(BulkLoader.COMPLETE, loadResourcesCompleted);
                    //rangeResourcesLoader.addEventListener(BulkLoader.PROGRESS, loadResourcesProgress);
                    
                    /**
                     * loadResourcesProgress
                     * @param    e
                     */
                    //function loadResourcesProgress(e:BulkProgressEvent):void {
                        //
                    //}
                    
                    /**
                     * loadResourcesCompleted
                     * @param    e
                     */
                    //function loadResourcesCompleted(e:BulkProgressEvent):void {
                        /**
                         * Remove
                         */
                        //rangeResourcesLoader.removeEventListener(BulkLoader.COMPLETE, loadResourcesCompleted);
                        //rangeResourcesLoader.removeEventListener(BulkLoader.PROGRESS, loadResourcesProgress);
                        
                        // if sounds element in xml
                        //if ("sounds" in ranges[id].range.resources) {
                            //for (var a:uint = 0; a < ranges[id].range.resources.sounds.sound.length(); a++) {
                                //var soundName:String = ranges[id].range.resources.sounds.sound[a].@name.toString();
                                //var soundSource:String = ranges[id].range.resources.sounds.sound[a].@src.toString();
                                //
                                // array sounds
                                //ranges[id].resourcesSounds[soundName] = rangeResourcesLoader.getSound(soundSource, true) as Sound;
                            //}
                        //}
                        
                        // if images element in xml
                        //if ("images" in ranges[id].range.resources) {
                            //for (var b:uint = 0; b < ranges[id].range.resources.images.image.length(); b++) {
                                //var imageName:String = ranges[id].range.resources.images.image[b].@name.toString();
                                //var imageSource:String = ranges[id].range.resources.images.image[b].@src.toString();
                                //
                                // array images (BitmapData)
                                //ranges[id].resourcesImages[imageName] = rangeResourcesLoader.getBitmapData(imageSource, true) as BitmapData;
                            //}
                        //}
                        
                        // game start
                        //gameStart(id);
                    //}
                //}
                
                //  not resources
                //else {
                    // game start
                    gameStart(id);
                //}
            //}
        }
        
        /**
         * gameStart
         * @param    id stage_id
         */
        public function gameStart(id:uint):void {
            
            // cast private var
            playingGameID = id;
            
            // call initialize
            initializePlayer();
            
            // create objects
            createMeshes(ranges[playingGameID].range.meshes);
            createPeriods(ranges[playingGameID].range.periods);
            createMap(ranges[playingGameID].range.map);
            createWeapons(ranges[playingGameID].range.weapons);
            createSmashTween2Objects(ranges[playingGameID].range.smashTweens);
            createReticles(ranges[playingGameID].range.reticles);
            
            //FIXME reticleSight
            createReticleSight();
            
            
            /**
             * ! order
             */
            usingWeaponID = 0;
            
            reticleSight = stage.addChild(new Sprite()) as Sprite;
            reticleSight.addChildAt(reticles[weapons[usingWeaponID].reticleNoLookingScopeName], 0);
            
            /**
             * ! order
             * create userInterface
             */
            userInterface = stage.addChild(new Sprite()) as Sprite;
            weaponLabel = userInterface.addChild(new TextField()) as TextField;
            messageLabel = userInterface.addChild(new TextField()) as TextField;
            //userInterface.addChild(logo);
            
            // weapon label
            // userInterface gfx
            with (weaponLabel) {
                defaultTextFormat = new TextFormat("Arial Black", 15, 0xFFFFFF);
                y = 445.9;
            }
            
            with (messageLabel) {
                defaultTextFormat = new TextFormat("Meiryo"    , 12, 0xFFFFFF);
                width = stage.stageWidth;
                x = 10;
                y = 445.9;
            }
            
            initWeaponUserInterface(usingWeaponID);
            
            /**
             * ! order
             * for debug
             */
            if (debugMode) {
                debugLabel = new Label(stage, 500);
                debugLabel2 = new Label(stage, 10, 75);
            }
            
            periodAlignment(ranges[playingGameID].range.periods.period.(@name == ranges[playingGameID].range.info.config.startPeriod.@name.toString()));
        }
        
        /**
         * initWeaponUserInterface
         * @param    weaponID
         */
        private function initWeaponUserInterface(weaponID:uint):void {
            weaponLabel.text = weapons[weaponID].name;
            weaponLabel.autoSize = TextFieldAutoSize.RIGHT;
            weaponLabel.x = stage.stageWidth - weaponLabel.width - 10;
            
            drawBullets(
                weapons[usingWeaponID].magazine - weapons[usingWeaponID].shootCount,
                weapons[usingWeaponID].magazine
            );
        }
        
        
        /**
         * InitializePlayer
         */
        private function initializePlayer():void {
            
            standupTargets = new Vector.<TargetAddress>();
            
            /**
             * Screen/Scene
             */
            screen = stage.addChild(new Sprite()) as Sprite;
            scene = new Scene3D();
            scene.root = new Object3D();
            scene.splitAnalysis = false;
            
            /**
             * Camera / Fov
             */
            camera = new Camera3D();
            camera.rotationX = MathUtils.toRadian(-90);
            camera.rotationZ = MathUtils.toRadian(12);
            scene.root.addChild(camera);
            
            /**
             * Screen
             */
            view = new View();
            screen.addChild(view);
            view.camera = camera;
            
            /**
             * InitializePlayer
             */
            
            var isFlyMode:Boolean;
            var defaultCoords:Point3D;
            
            // all attr cant null
            with (ranges[playingGameID].range.info.config.player) {
                playerConfigWalkSpeed = Number(@walkSpeed);
                playerConfigWalkSpeedZoomed = Number(@walkSpeedZoomed);
                playerConfigJumpSpeed = Number(@jumpSpeed);
                playerConfigGravity = Number(@gravity);
                playerConfigHeight = Number(@height);
                playerConfigWaggle = Number(@waggle);
                playerConfigWaggleZoomed = Number(@waggleZoomed);
                //playerConfigFootStepSound = @footstepSound.toString();
                isFlyMode = (@flyMode == "true") ? true : false;
                
                defaultCoords = new Point3D(
                    Number(@defaultX) ? @defaultX : 0,
                    Number(@defaultY) ? @defaultY : 0,
                    Number(@defaultZ) ? @defaultZ : 0
                );
            }
            
            
            player = new WalkController(stage);
            
            with (player) {
                flyMode = isFlyMode;
                object = camera;
                checkCollisions = true;
                speed = playerConfigWalkSpeed;
                jumpSpeed = playerConfigJumpSpeed;
                gravity = playerConfigGravity;
                objectZPosition = playerConfigHeight;
                
                coords = defaultCoords;
                
                
                /**
                 * bindKeys
                 */
                bindKey(KeyboardUtils.W, ObjectController.ACTION_FORWARD);
                bindKey(KeyboardUtils.S, ObjectController.ACTION_BACK);
                bindKey(KeyboardUtils.A, ObjectController.ACTION_LEFT);
                bindKey(KeyboardUtils.D, ObjectController.ACTION_RIGHT);
                bindKey(KeyboardUtils.Z, ObjectController.ACTION_DOWN);
                bindKey(KeyboardUtils.SPACE, ObjectController.ACTION_UP);
                bindKey(KeyboardUtils.SHIFT, ObjectController.ACTION_ACCELERATE);
            }
            
            
            /**
             * ReSize
             */
            onResize(null);
            
            /**
             * init eyePoint
             */
            eyePoint = new Point();
            
            /* EventListeners
            // /////////////////////////////////////////////////////// */
            with (stage) {
                addEventListener(Event.RESIZE, onResize);
                addEventListener(Event.ENTER_FRAME, enterFrameHandler);
                addEventListener(MouseEvent.MOUSE_MOVE, onMouseMove);
                addEventListener(KeyboardEvent.KEY_DOWN, keyDownHandler);
                addEventListener(KeyboardEvent.KEY_UP, keyUpHandler);
                addEventListener(MouseEvent.CLICK, onMouseClickHandler);
                
                if (debugMode) {
                    addEventListener(Event.ENTER_FRAME, debug);
                }
            }
            
            var timer:Timer = new Timer(320, 0);
            timer.addEventListener(TimerEvent.TIMER, moveSound);
            timer.start();
        }
        
        /**
         *
         * @param    e
         */
        private function debug(e:Event):void {
            
            debugLabel.text =
            
            "[PLAYER]" +
            "\nx\t:\t" + player.object.x +
            "\ny\t:\t" + player.object.y +
            "\nz\t:\t" + player.object.z + "\n" +
            
            "\nrotationX\t:\t" + player.object.rotationX + "\n\t\t\t" + MathUtils.toDegree(player.object.rotationX) +
            "\nrotationZ\t:\t" + player.object.rotationZ + "\n\t\t\t" + MathUtils.toDegree(player.object.rotationZ) + "\n" +
            
            
            "[FLAG]" +
            "\nlookingScopeNow\t\t:\t" + lookingScopeNow +
            "\nisReloadingNow\t\t:\t" + isReloadingNow +
            "\nisLoadingNow\t\t:\t" + isLoadingNow +
            "\nisMoving\t\t\t:\t" + isMoving +
            "\nflagQ\t\t\t\t:\t" + flagQ +
            "\nplayingGameID\t\t:\t" + playingGameID +
            "\nRP4SignalEventType\t:\t" + runningPeriod4SignalEventType +
            "\nnextPeriod\t\t\t:\t" + nextPeriod +
            "\npass\t\t\t\t:\t" + passNumber + "\n\n" +
            
            
            "[WEAPON]" +
            "\nusingWeaponID\t\t:\t" + usingWeaponID +
            "\nsupplyType\t\t:\t" + weapons[usingWeaponID].supplyType +
            "\nneedLoad\t\t:\t" + weapons[usingWeaponID].needLoad +
            "\nshootCount\t\t:\t" + weapons[usingWeaponID].shootCount + "\n\n" +
            
            
            "[PLAYER CONST]" +
            "\nWalkSpeed\t\t\t:\t" + playerConfigWalkSpeed +
            "\nWalkSpeedZoomed\t:\t" + playerConfigWalkSpeedZoomed +
            "\nWaggle\t\t\t:\t" + playerConfigWaggle +
            "\nWaggleZoomed\t\t:\t" + playerConfigWaggleZoomed;
        }
        
        /**
         *
         * @param    str
         */
        private function log(str:String):void {
            if(debugMode) {
                
                sionDriver.noteOn(42, waves["debug"], 1, 0);
                
                if ( debugLabel2.text.length > 550) {
                    debugLabel2.text = "";
                }
                debugLabel2.text += "\r" + str;
            }
        }
        
        /**
         *
         * @param    str
         */
        private function messageLog(str:String):void {
            sionDriver.noteOn(90, waves["sin"], 1, 0);
            messageLabel.text = str;
        }
        
        /**
         *
         * @param    id
         */
        public function createMeshes(db:XMLList):void {
            meshes = new Array();
            
            for (var a:uint = 0; a < db.mesh.length(); a++) {
                meshes[db.mesh[a].@name] = new Mesh();
                
                var x:XMLList = db.mesh[a].surface.(@materialType == EZCreateMesh.TEXTURE).@name;
                
                var textures/*Bitmap*/:Array = new Array();
                
                for (var b:uint = 0; b < x.length(); b++) {
                    textures[x[b]] = ranges[playingGameID].resourcesImages[x[b]] as BitmapData;
                }
                
                meshes[db.mesh[a].@name] = EZCreateMesh.createMesh(db.mesh[a], textures) as Mesh;
            }
        }
        
        
        /**
         * createPeriods
         * @param    db
         */
        public function createPeriods(db:XMLList):void {
            
            periods = new Array();
            
            for (var a:uint = 0; a < db.period.length(); a++) {
                var name:String = db.period[a].@name.toString() as String;
                periods[name] = new Period();
            }
        }
        
        /**
         *
         * @param    map
         * @param    mapName
         */
        private function createMap(db:XMLList):void {
            map = new Map();
            
            for (var a:uint = 0; a < db.set.length(); a++) {
                
                var _set:Set;
                var elements:Array = new Array();
                
                for (var b:uint = 0; b < db.set[a].mesh.length(); b++) {
                    var mesh:Mesh = meshPropertiesSetup(
                        meshes[db.set[a].mesh[b].@name].clone(),
                        db.set[a].mesh[b]
                    );
                    elements.push(mesh);
                }
                
                _set = Set.createFromArray(elements);
                map.add("map:::" + a as String, _set);
                
                /**
                 * セクタの登録
                 */
                switch (db.set[a].@type.toString()) {
                    /**
                     * allTimes
                     * プレイヤーの位置に関係ないセクタ
                     */
                    case "allTimes" :
                        addObjects(map["map:::" + a]);
                    break;
                }
            }
        }
        
        /**
         *
         * @param    mesh
         * @param    properties
         * @return mesh
         */
        public function meshPropertiesSetup(mesh:Mesh, properties:XML):Mesh {
            if (properties.hasOwnProperty("@x")) mesh.x = Number(properties.@x);
            if (properties.hasOwnProperty("@y")) mesh.y = Number(properties.@y);
            if (properties.hasOwnProperty("@z")) mesh.z = Number(properties.@z);
            if (properties.hasOwnProperty("@scaleX")) mesh.scaleX = Number(properties.@scaleX);
            if (properties.hasOwnProperty("@scaleY")) mesh.scaleY = Number(properties.@scaleY);
            if (properties.hasOwnProperty("@scaleZ")) mesh.scaleZ = Number(properties.@scaleZ);
            if (properties.hasOwnProperty("@rotationX")) mesh.rotationX = MathUtils.toRadian(Number(properties.@rotationX));
            if (properties.hasOwnProperty("@rotationY")) mesh.rotationY = MathUtils.toRadian(Number(properties.@rotationY));
            if (properties.hasOwnProperty("@rotationZ")) mesh.rotationZ = MathUtils.toRadian(Number(properties.@rotationZ));;
            return mesh;
        }
        
        /**
         *
         * @param    db
         */
        private function createReticles(db:XMLList):void {
            reticles = new Array();
            
            for (var i:uint = 0; i < db.svg.length(); i++) {
                reticles[db.svg[i].@name.toString()] = new FShapeSVG(db.svg[i]).toSprite();
            }
        }
        
        /**
         *
         */
        private function createReticleSight():void {
            
            // R400
            var svg:XML =
            <svg>
                <g transform="translate(0,-570)">
                    <path style="opacity : 1; fill : #0" d="M -140 -110 L -140 590 L 860 590 L 860 -110 L -140 -110 zM 360 40 C 470 40 560 129 560 240 C 560 350 470 440 360 440 C 249 440 160 350 160 240 C 160 129 249 40 360 40 z " transform="translate(0,570)"/>
                </g>
            </svg>;
            
            sight = new FShapeSVG(svg).toSprite();
        }
        
        /**
         * createSmashTween2Objects
         * @param    db
         */
        public function createSmashTween2Objects(db:XMLList):void {
            smashTween2Objects = new Array();
            
            for (var a:uint = 0; a < db.smashTween.length(); a++) {
                var to:Object = new Object();
                
                var toAttributes:XMLList = db.smashTween[a].to.@ * ;
                for (var b:uint = 0; b < toAttributes.length(); b++) to[String(toAttributes[b].name())] = Number(toAttributes[b]);
                
                smashTween2Objects[db.smashTween[a].@name] = to;
            }
        }
        
        /**
         * addObjects
         * @param    objects
         */
        private function addObjects(objects:Set):void {
            for (var o:* in objects) {
                scene.root.addChild(o);
            }
        }
        
        /**
         * createWeapons
         * @param    db
         */
        public function createWeapons(db:XMLList):void {
            weapons = new Vector.<WeaponConfig>();
            
            for (var a:uint = 0; a < db.weapon.length(); a++) {
                weapons.push(new WeaponConfig(
                    db.weapon[a]
                ) as WeaponConfig);
            }
        }
        
        /**
         * periodAlignment
         * @param    nextPeriodName
         */
        public function periodAlignment(db:XMLList):void {
            
            var name:String = db.@name.toString();
            
            switch (true) {
                case db.@signalEvent == SignalEvent.ALL_MESSAGES_SHOWING : runningPeriod4SignalEventType = SignalEvent.ALL_MESSAGES_SHOWING; break;
                case db.@signalEvent == SignalEvent.ALL_TARGETS_BREAKING : runningPeriod4SignalEventType = SignalEvent.ALL_TARGETS_BREAKING; break;
                case db.@signalEvent == SignalEvent.SWITCH_TARGETS_BREAKING : runningPeriod4SignalEventType = SignalEvent.SWITCH_TARGETS_BREAKING;  break;
            }
            
            nextPeriod = db.@nextPeriod.toString();
            
            /**
             *
             */
            if ("addMeshes" in db) {
                periods[name].meshes = new Vector.<PeriodMesh>();
                for (var a:uint = 0; a < db.addMeshes.addMesh.length(); a++) {
                    periods[name].meshes[a] = new PeriodMesh();
                    
                    periods[name].meshes[a].object = meshPropertiesSetup(
                        meshes[db.addMeshes.addMesh[a].@name.toString()].clone(),
                        db.addMeshes.addMesh[a]
                    );
                }
                
                addPeriodMeshes(periods[name].meshes);
            }
            
            /**
             *
             */
            if ("addTargets" in db) {
                periods[name].targets = new Vector.<PeriodTarget>;
                
                // 追加するターゲットの分だけまわす
                for (var b:uint = 0; b < db.addTargets.addTarget.length(); b++) {
                    
                    // 追加するターゲットが特殊なターゲットであるときのフラグ
                    var isSwitchTarget:Boolean = false;
                    var isTweenTarget:Boolean = ("tweens" in db.addTargets.addTarget[b]) as Boolean;
                    
                    // ターゲットのインスタンスを作成
                    periods[name].targets[b] = new PeriodTarget(
                        b,
                        isSwitchTarget,
                        isTweenTarget,
                        db.addTargets.addTarget[b].@numLife,
                        db.addTargets.addTarget[b].@smashTween,
                        db.addTargets.addTarget[b].@smashTweenTime,
                        db.addTargets.addTarget[b].@collisionRadius,
                        db.addTargets.addTarget[b].@criticalCollisionRadius
                    );
                    
                    periods[name].targets[b].object = meshPropertiesSetup(
                        meshes[db.addTargets.addTarget[b].@name.toString()].clone(),
                        db.addTargets.addTarget[b]
                    );
                    
                    // トゥイーンターゲット
                    if (isTweenTarget) {
                        //Debug.log("TweenTarget");
                        periods[name].targets[b].createTweenInstanceAndPlay(db.addTargets.addTarget[b].tweens);
                    }
                    
                    /**
                     *
                     */
                    standupTargets.push(new TargetAddress(name, b));
                }
                
                addPeriodMeshes(periods[name].targets);
            }
            
            if ("removeMeshes" in db) {
                for (var c:uint = 0; c < db.removeMeshes.removeMesh.length(); c++) {
                    removePeriodMeshes(periods[db.removeMeshes.removeMesh[c].@period.toString()].meshes);
                }
            }
            
            if ("messages" in db) {
                messages = new Vector.<Message>();
                
                for (var d:uint = 0; d < db.messages.message.length(); d++) {
                    
                    var message:String = db.messages.message[d];
                    var time:Number = db.messages.message[d].@time;
                    var delay:Number = db.messages.message[d].@delay;
                    
                    messages.push(new Message(message, time, delay));
                }
                
                var r:Number = Math.random();
                delayMessage((passNumber = (r == passNumber) ? r * .5 : r));
            }
        }
        
        /**
         *
         * @param    pass
         */
        private function showMessages(pass:Number):void {
            var timer:Timer = new Timer(messages[0].time, 1);
            timer.addEventListener(TimerEvent.TIMER, timerEvent);
            timer.start();
            
            // in order
            messageLog(messages.shift().message);
            
            function timerEvent(e:TimerEvent):void {
                messageLog("");
                
                timer.stop();
                timer.removeEventListener(TimerEvent.TIMER, timerEvent);
                delayMessage(pass);
            }
        }
        
        /**
         *
         * @param    pass
         */
        private function delayMessage(pass:Number):void {
            if (messages.length) {
                if (passNumber == pass) {
                    
                    var timer:Timer = new Timer(messages[0].delay, 1);
                    timer.addEventListener(TimerEvent.TIMER, timerEvent);
                    timer.start();
                    
                    function timerEvent(e:TimerEvent):void {
                        timer.stop();
                        timer.removeEventListener(TimerEvent.TIMER, timerEvent);
                        showMessages(pass);
                    }
                }
            }
            else {
                signalEventsController(SignalEvent.ALL_MESSAGES_SHOWING);
            }
        }
        
        /**
         *
         * @param    periodMeshes
         */
        private function addPeriodMeshes(periodMeshes:Vector.<*>):void {
            for (var i:uint = 0; i < periodMeshes.length; i++) {
                scene.root.addChild(periodMeshes[i].object);
            }
        }
        
        /**
         *
         * @param    periodMeshes
         */
        private function removePeriodMeshes(periodMeshes:Vector.<*>):void {
            for (var i:uint = 0; i < periodMeshes.length; i++) {
                scene.root.removeChild(periodMeshes[i].object);
            }
        }
        
        
        /**
         * EventHandlers
         * =====================================
         */
        
        
        /**
         * keyDownHanlder
         * @param    e
         */
        public function keyDownHandler(e:KeyboardEvent):void {
            switch (e.keyCode) {
                case KeyboardUtils.Q : flagQ = false;break;
            }
        }
        
        /**
         * keyUpHandler
         * @param    e
         */
        public function keyUpHandler(e:KeyboardEvent):void {
            var wcl1m:uint = weapons.length - 1;
            
            switch (e.keyCode) {
                case KeyboardUtils.Q : flagQ  = true; break;
                case KeyboardUtils.R : reload();break;
                case KeyboardUtils.V : scope(); break;
                case KeyboardUtils.X : load(); break;
                case KeyboardUtils.NUMBER_1 : if (usingWeaponID != 0) changeWeapon(0); break;
                case KeyboardUtils.NUMBER_2 : if (wcl1m > 0 && usingWeaponID != 1) changeWeapon(1); break;
                case KeyboardUtils.NUMBER_3 : if (wcl1m > 1 && usingWeaponID != 2) changeWeapon(2); break;
                case KeyboardUtils.NUMBER_4 : if (wcl1m > 2 && usingWeaponID != 3) changeWeapon(3); break;
                case KeyboardUtils.NUMBER_5 : if (wcl1m > 3 && usingWeaponID != 4) changeWeapon(4); break;
                case KeyboardUtils.NUMBER_6 : if (wcl1m > 4 && usingWeaponID != 5) changeWeapon(5); break;
                case KeyboardUtils.NUMBER_7 : if (wcl1m > 5 && usingWeaponID != 6) changeWeapon(6); break;
                case KeyboardUtils.NUMBER_8 : if (wcl1m > 6 && usingWeaponID != 7) changeWeapon(7); break;
                case KeyboardUtils.NUMBER_9 : if (wcl1m > 7 && usingWeaponID != 8) changeWeapon(8); break;
                case KeyboardUtils.NUMBER_0 : if (wcl1m > 8 && usingWeaponID != 9) changeWeapon(9); break;
            }
        }
        
        /**
         * onEnterFrameHandler
         * @param    e
         */
        private function enterFrameHandler(e:Event):void {
            player.processInput();
            
            var vww:Number;
            var vwp:Number;
            
            isMoving = (player.currentSpeed > 0) as Boolean;
            
            if (lookingScopeNow) {
                //LookingScope
                vww = weapons[usingWeaponID].waggleZoomed as Number;
                vwp = playerConfigWaggleZoomed;
                
            }
            else {
                //NO LookingScope
                vww = weapons[usingWeaponID].waggle as Number;
                vwp = playerConfigWaggle;
            }
            
            camera.rotationX += MathUtils.toDegree(((Math.random() * 2 > 1)? -1:1) * (Math.random() + Math.random() + Math.random()) * vww * vwp);
            camera.rotationZ += MathUtils.toDegree(((Math.random() * 2 > 1)? -1:1) * (Math.random() + Math.random() + Math.random()) * vww * vwp);
            
            if (-20 < MathUtils.toDegree(camera.rotationX)) camera.rotationX = MathUtils.toRadian(-20);
            else if ( -120 > MathUtils.toDegree(camera.rotationX)) camera.rotationX = MathUtils.toRadian( -120);
            
            scene.calculate();
        }
        
        private function onMouseMove(e:Event):void {
            var vsp:Number;
            
            if (lookingScopeNow) {
                //LookingScope
                vsp = weapons[usingWeaponID].viewSpeedZoomed;
            }
            else {
                //NO LookingScope
                vsp = weapons[usingWeaponID].viewSpeed;
            }
            
            if (flagQ) {
                camera.rotationZ -= (mouseX - eyePoint.x) * vsp;
                camera.rotationX -= (mouseY - eyePoint.y) * vsp;
            }
            
            eyePoint.x = stage.mouseX;
            eyePoint.y = stage.mouseY;
        }
        
        
        /**
         * スコープ切り替え
         */
        private function scope():void {
            if (canScope()) {
                //スコープ切り替え可能
                log("canScope\t\t\t::\ttrue");
                
                //スコープ切り替え開始
                log("call switchScope\t\t::\t" + !lookingScopeNow);
                switchScope(!lookingScopeNow);
            }
            else {
                //スコープ切り替え不可能
                log("canScope\t\t\t::\tfalse");
            }
        }
        
        /**
         * スコープ判定
         * @return
         */
        private function canScope():Boolean {
            //リロード中ではない
            return !(isLoadingNow) as Boolean;
        }
        
        
        /**
         *
         * @param    isLookScope
         */
        private function switchScope(isLookScope:Boolean):void {
            if (isLookScope) {
                log("isLookScope\t\t::\ttrue");
                reticleSight.removeChild(reticles[weapons[usingWeaponID].reticleNoLookingScopeName]);
                
                reticleSight.addChildAt(sight, 0);
                reticleSight.addChildAt(reticles[weapons[usingWeaponID].reticleLookingScopeName], 0);
                
                lookingScopeNow = true;
                
                /**
                 * DotSight Mode
                 */
                if (weapons[usingWeaponID].enlargement == 0) {
                    camera.fov = FOV;
                }
                
                /**
                 * ScopeSight Mode
                 */
                else {
                    camera.fov = weapons[usingWeaponID].enlargement as Number;
                    //screen.filters = [new BlurFilter(4,4)];
                    
                    // cast
                    player.speed = playerConfigWalkSpeedZoomed;
                }
            }
            else {
                log("isLookScope\t\t::\tfalse");
                
                
                if(lookingScopeNow){
                    reticleSight.removeChild(sight);
                    reticleSight.removeChild(reticles[weapons[usingWeaponID].reticleLookingScopeName]);
                }
                
                reticleSight.addChildAt(reticles[weapons[usingWeaponID].reticleNoLookingScopeName], 0);
                
                lookingScopeNow = false;
                
                //デフォルトFOV値へ戻す
                camera.fov = FOV;
                screen.filters = [];
                
                // cast
                player.speed = playerConfigWalkSpeed;
            }
        }
        
        /**
         * onMouseClickHandler
         * @param    e
         */
        private function onMouseClickHandler(e:MouseEvent):void {
            if (canShoot()) {
                //発射
                log("canShoot\t\t\t::\ttrue");
                shoot();
                weapons[usingWeaponID].needLoad = true;
                //装填
                if (weapons[usingWeaponID].supplyType == WeaponConfigType.AUTOMATIC) {
                    log("Load\t\t\t\t::\tAUTOMATIC");
                    load(WeaponConfigType.AUTOMATIC);
                }
            }
            else {
                log("canShoot\t\t\t::\tfalse")
            }
        }
        
        /**
         * 装填
         */
        private function load(flag:String = null):void {
            if (canLoad()) {
                //装填可能
                log("canLoad\t\t\t::\ttrue");
                
                //装填中
                log("Loading");
                
                if (flag == WeaponConfigType.AUTOMATIC) {
                    
                }
                else {
                    switchScope(false);
                }
                
                
                //ranges[playingGameID].resourcesSounds[weapons[usingWeaponID].loadSound].play(0, 0, new SoundTransform(publicConfig.volumeMaster * publicConfig.volumeSE));
                
                isLoadingNow = true;
                setTimeout(loadComplete, weapons[usingWeaponID].interval);
            }
            else {
                //装填不可
                log("canLoad\t\t\t::\tfalse");
            }
        }
        
        /**
         * 装填判定
         * @return 装填可能か
         */
        private function canLoad():Boolean {
            //残弾あり、装填中ではない
            var buttShoot:uint = weapons[usingWeaponID].magazine - weapons[usingWeaponID].shootCount;
            return !(buttShoot == 0) && !isLoadingNow && weapons[usingWeaponID].needLoad as Boolean;
        }
        
        /**
         * 装填完了
         */
        private function loadComplete():void {
            //装填完了
            log("loadCompleted");
            isLoadingNow = false;
            weapons[usingWeaponID].needLoad = false;
        }
        
        /**
         * リロード
         */
        private function reload():void {
            if (canReload()) {
                //リロード可能
                log("canReload\t\t\t::\ttrue");
                //リロード開始
                log("Reloading");
                
                switchScope(false);
                
                //ranges[playingGameID].resourcesSounds[weapons[usingWeaponID].reloadSound].play(0, 0, new SoundTransform(publicConfig.volumeMaster * publicConfig.volumeSE));
                isReloadingNow = true;
                setTimeout(reloadComplete, weapons[usingWeaponID].reloadtime);
            }
            else {
                //リロード不可能
                log("canReload\t\t\t::\tfasle");
            }
        }
        
        /**
         * リロード判定
         * @return リロード可能か
         */
        private function canReload():Boolean {
            //残弾フルではない, リロード中ではない, 装填中ではない
            var buttShoot:uint = weapons[usingWeaponID].magazine - weapons[usingWeaponID].shootCount;
            return (!(weapons[usingWeaponID].shootCount == 0) && !isReloadingNow && !isLoadingNow) as Boolean;
        }
        
        /**
         * リロード完了
         */
        private function reloadComplete():void {
            //リロード完了
            log("reloadCompleted");
            isReloadingNow = false;
            weapons[usingWeaponID].needLoad = false;
            weapons[usingWeaponID].shootCount = 0;
            
            drawBullets(weapons[usingWeaponID].magazine, weapons[usingWeaponID].magazine);
        }
        
        /**
         * 武器変更
         * @param    id
         */
        private function changeWeapon(id:uint):void {
            if (canChangeWeapon()) {
                //武器変更可能
                log("canChangeWeapon\t::\ttrue");
                
                switchScope(false);
                
                initWeaponUserInterface(usingWeaponID = id);
                
                log("call initWeapon\t\t::\t" + id);
            }
            else {
                //武器変更不可能
                log("canChangeWeapon\t\t::\tfalse");
            }
        }
        
        /**
         * 武器変更判定
         * @return 武器の変更が可能か
         */
        private function canChangeWeapon():Boolean {
            //リロード中ではない, 装填中ではない
            return (!isReloadingNow && !isLoadingNow) as Boolean;
        }
        
        /**
         * 発射
         */
        private function shoot():void {
            //PlusShootCount
            weapons[usingWeaponID].shootCount ++;
            
            drawBullets(
                weapons[usingWeaponID].magazine - weapons[usingWeaponID].shootCount,
                weapons[usingWeaponID].magazine
            );
            
            
            //ranges[playingGameID].resourcesSounds[weapons[usingWeaponID].shootSound].play(0, 0, new SoundTransform(publicConfig.volumeMaster * publicConfig.volumeSE));
            
            
            //目線の座標 - depthの数値はレンジと特に関係しなくてもよい
            var eyePoint:Point3D = view.camera.localToGlobal(view.get3DCoords(new Point(stage.stageWidth * .5, stage.stageHeight * .5), 3000));
            
            /**
             * 自然なランダム値を取得する
             * Math.random() + Math.random() + Math.random()
             */
            var nrX:Number = camera.rotationX;
            var nrZ:Number = camera.rotationZ;
            
            var vx:Number = MathUtils.toDegree((Math.random() + Math.random() + Math.random()) * weapons[usingWeaponID].recoil);
            var vz:Number = MathUtils.toDegree(((Math.random() * 2 > 1)? -1:1) * (Math.random() + Math.random() + Math.random()) * weapons[usingWeaponID].recoil);
            
            camera.rotationX += vx;
            camera.rotationZ += vz;
            
            reticles[weapons[usingWeaponID].reticleLookingScopeName].y = -vx * 0x444;
            reticles[weapons[usingWeaponID].reticleLookingScopeName].x = -vz * 0xFF;
            
            BetweenAS3.parallelTweens([
                BetweenAS3.tween(camera, {rotationX : nrX,rotationZ : nrZ},null, 0.2, Back.easeOut),
                BetweenAS3.tween(reticles[weapons[usingWeaponID].reticleLookingScopeName], { y : 0, x : 0 }, null, 0.1, Back.easeOut)
            ]).play();
            
            
            var temporaryAddress:uint = 0;
            var temporaryDistance:Number = Infinity;
            var anyHit:Boolean = false;
            
            var len:uint = standupTargets.length;
            
            
            //ターゲットがひとつも存在しない場合は、衝突判定を行わない
            if (len)
            {
                //すべてのターゲットの衝突判定を行います
                for (var i:uint = 0; i < len; i++)
                {
                    //Coords
                    var playerCoords:Point3D = player.object.coords as Point3D;
                    var objectCoords:Point3D = objectCoords = periods[standupTargets[i].period].targets[standupTargets[i].target].object.coords as Point3D;
                    var collisionRadius:Number = periods[standupTargets[i].period].targets[standupTargets[i].target].collisionRadius as Number;
                    
                    var isTweenTarget:Boolean = periods[standupTargets[i].period].targets[standupTargets[i].target].isTweenTarget;
                    
                    var abs:Number =
                        Math.sqrt(
                            Math.pow(playerCoords.x - objectCoords.x, 2) +
                            Math.pow(playerCoords.y - objectCoords.y, 2) +
                            Math.pow(playerCoords.z - objectCoords.z, 2)
                        );
                    
                    var distance:Number = abs < 0 ? -abs : abs;
                    var position:Number = distance / BASE_LINE_METER / weapons[usingWeaponID].speed;
                    
                    
                    /*
                    if (isTweenTarget) {
                        objectCoords = periods[standupTargets[i].period].targets[standupTargets[i].target].gotoAndReturnPosition(position);
                    }
                    */
                    
                    
                    //衝突している場合
                    
                    if (HitTest.R2R3D(eyePoint, playerCoords, objectCoords, collisionRadius))
                    {
                        log("hitTestR2R3D\t" + i + "\t::\ttrue");
                        
                        //衝突しているターゲットの内、プレイヤーとターゲットの距離が最も近いターゲットを特定します
                        if (temporaryDistance > distance) {
                            temporaryDistance = distance;
                            temporaryAddress = i;
                            anyHit = true;
                        }
                    }else {log("hitTestR2R3D\t" + i + "\t::\tfalse");;}
                }
                
                //ひとつでもヒットしている場合
                if (anyHit) {
                    
                    //レンジとの関係
                    if (weapons[usingWeaponID].range * BASE_LINE_METER < temporaryDistance) {
                        log("--[No hit]--------------------------------\n" + "Hit \"Target " + temporaryAddress + "\", but be out of range" + "\n---------------------------------------");
                    }
                    
                    
                    //衝突確定
                    else if (canTargetSmash(standupTargets[temporaryAddress], temporaryAddress)) {
                        
                        //距離(M)/速さ(M/SEC)
                        var delay:Number = temporaryDistance / BASE_LINE_METER / weapons[usingWeaponID].speed;
                        setTimeout(targetSmash, delay, standupTargets[temporaryAddress], temporaryAddress);
                        
                        log("--[Hit]--------------------------------\n" + "Hit \"Target " + temporaryAddress + "\", delay\t::\t" + delay);
                        
                        //シグナルイベントへ連絡
                        if (len == 1) {
                            signalEventsController(SignalEvent.ALL_TARGETS_BREAKING);
                        }
                        if (periods[standupTargets[temporaryAddress].period].targets[standupTargets[temporaryAddress].target].isSwitchTarget)
                        {
                            
                            var anySwitchTarget:Boolean = false;
                            
                            for (var k:uint = 0; standupTargets.length; k++) {
                                if (periods[standupTargets[k].period].targets[standupTargets[k].target].isSwitchTarget) {
                                    anySwitchTarget = true;
                                }
                            }
                            
                            if (anyHit) {
                                //スイッチが残っている
                            }
                            else signalEventsController(SignalEvent.SWITCH_TARGETS_BREAKING);
                        }
                    }
                }
            }
        }
        
        /**
         * 発射判定
         * @return 発射可能か
         */
        private function canShoot():Boolean {
            var buttShoot:uint = weapons[usingWeaponID].magazine - weapons[usingWeaponID].shootCount;
            
            //残弾あり, リロード中ではない, 装填中ではない
            return (buttShoot && !isReloadingNow && !isLoadingNow && ! weapons[usingWeaponID].needLoad) as Boolean;
        }
        
        /**
         * シグナルイベント管理
         * @param    e
         */
        private function signalEventsController(e:String):void {
            if (runningPeriod4SignalEventType == e)
            {
                periodAlignment(ranges[playingGameID].range.periods.period.(@name == nextPeriod));
            }
        }
        
        /**
         * canTargetSmash
         * @param    smashTargetID
         * @param    address
         * @return canTargetSmash
         */
        private function canTargetSmash(smashTargetID:TargetAddress, address:uint):Boolean {
            if (periods[smashTargetID.period].targets[smashTargetID.target].hit()) {
                return false;
            }
            else {
                return true;
            }
        }
        
        /**
         * targetSmash
         * @param    smashTargetID
         */
        private function targetSmash(smashTargetID:TargetAddress, address:uint):void {
            
            log("numLife (ID :: " + smashTargetID + ", address :: " + address + ")\t::\t" + periods[smashTargetID.period].targets[smashTargetID.target].numLife + "\n---------------------------------------");
            
            standupTargets.splice(address, 1);
            
            //var tween:ITween = BetweenAS3.tween(
                //periods[smashTargetID.period].targets[smashTargetID.target].object,
                //smashTween2Objects[periods[smashTargetID.period].targets[smashTargetID.target].smashTween],
                //null,
                //periods[smashTargetID.period].targets[smashTargetID.target].smashTweenTime
            //);
            //tween.addEventListener(TweenEvent.COMPLETE, removeSmashTarget);
            //tween.play();
            
            //function removeSmashTqarget(e:TweenEvent):void {
                /**
                 * Remove
                 */
                //tween.removeEventListener(TweenEvent.COMPLETE, removeSmashTarget);
                scene.root.removeChild(periods[smashTargetID.period].targets[smashTargetID.target].object);
                
            //}
        }
        
        /**
         *
         * @param    e
         */
        private function moveSound(e:TimerEvent):void {
            if (isMoving && player.onGround && !lookingScopeNow) {
                var vol:Number = Math.random();
                playFootStepSound(vol < 0.2 ? vol + 0.2 : vol);
            }
        }
        
        /**
         *
         * @param    vol
         */
        private function playFootStepSound(vol:Number = 1):void {
            //walkingSoundChannel = ranges[playingGameID].resourcesSounds[playerConfigFootStepSound].play(0, 0, new SoundTransform(vol * publicConfig.volumeMaster * publicConfig.volumeSE, 0));
        }
        
        /**
         *
         */
        private function stopFootStepSound():void {
            walkingSoundChannel.stop();
            walkingSoundChannel = null;
        }
        
        /**
         * onResize
         * @param    e
         */
        private function onResize(e:Event):void {
            
            view.width = stage.stageWidth;
            view.height = stage.stageHeight;
            
            //TODO 夜の実装
            var bgMatrix:Matrix = new Matrix();
            
            bgMatrix.rotate(90 * PI / 180);
            graphics.clear();
            graphics.beginGradientFill("linear", [0x0746bd, 0x90c8cf], [100, 100], [0, 255], bgMatrix);
            graphics.drawRect(0, 0, stage.stageWidth, stage.stageHeight);
            
        }
        
        /**
         *
         * @param    numButtBullets
         * @param    numMagazineBullets
         */
        private function drawBullets(numButtBullets:uint, numMagazineBullets:uint):void {
            /**
             * Graphics Clear
             */
            userInterface.graphics.clear();
            
            for (var a:uint = 0; a < numMagazineBullets; a++ ) {
                if (a < numButtBullets) userInterface.graphics.lineStyle(1, 0xFFFFFF);
                else userInterface.graphics.lineStyle(1, 0x555555);
                
                userInterface.graphics.moveTo(700 - a * 3, 430.9);
                userInterface.graphics.lineTo(700 - a * 3, 440.9);
            }
        }
    }
}

/**
 * classes for debug
 */
//import com.carlcalderon.arthropod.Debug;

/**
 * class PulicConfig
 */
class PublicConfig {
    public var volumeMaster:Number;
    public var volumeBGM:Number;
    public var volumeSE:Number;
    public var moveType:String;
    public var rawSpeed:Number;
    
    public static const STANDARD:String = "Standard";
    public static const RAW_MODE:String = "RawMode";
    
    public static const NORMAL:String = "Normal";
    public static const REVERSE:String = "REVERSE";
}

/**
 * class WeaponConfig
 */
class WeaponConfig {
    public var name:String;
    public var recoil:Number;
    public var enlargement:Number;
    public var magazine:Number;
    public var reloadtime:Number;
    public var speed:Number;
    public var range:Number;
    public var zeroin:Number;
    public var waggle:Number;
    public var waggleZoomed:Number;
    public var interval:Number;
    public var viewSpeed:Number;
    public var viewSpeedZoomed:Number;
    
    public var shootCount:uint;
    public var shootSound:String;
    public var reloadSound:String;
    public var loadSound:String;
    public var reticleLookingScopeName:String;
    public var reticleNoLookingScopeName:String;
    public var supplyType:String;
    
    public var needLoad:Boolean;
    
    /**
     *
     * @param    config
     */
    public function WeaponConfig(config:XML) {
        this.name = config.@name.toString();
        this.recoil = config.@recoil;
        this.enlargement = config.@enlargement;
        this.magazine = config.@magazine;
        this.reloadtime = config.@reloadtime;
        this.speed = config.@speed;
        this.range = config.@range;
        this.zeroin = config.@zeroin;
        this.waggle = config.@waggle;
        this.waggleZoomed = config.@waggleZoomed;
        this.interval = config.@interval;
        this.viewSpeed = config.@viewSpeed;
        this.viewSpeedZoomed = config.@viewSpeedZoomed;
        this.shootCount = 0;
        this.reticleNoLookingScopeName = config.@reticleNoLookingScopeName.toString() as String;
        this.reticleLookingScopeName = config.@reticleLookingScopeName.toString() as String;
        this.shootSound = config.@shootSound.toString() as String;
        this.reloadSound = config.@reloadSound.toString() as String;
        this.loadSound = config.@loadSound.toString() as String;
        this.supplyType = config.@supplyType.toString() == WeaponConfigType.BOLT_ACTION ? WeaponConfigType.BOLT_ACTION : WeaponConfigType.AUTOMATIC;
        this.needLoad = false;
    }
}

/**
 * class WeaponConfigType
 */
class WeaponConfigType {
    /*Bolt Action*/
    public static const BOLT_ACTION:String = "BoltAction";
    
    /*Automatic rifle*/
    public static const AUTOMATIC:String = "Automatic";
}

/**
 * class Range
 */
class Range {
    public var name:String;
    public var range:XML;
    public var src:String;
    public var isLoaded:Boolean;
    public var resourcesImages:/*BitmapData*/Array;
    public var resourcesSounds:/*Sound*/Array;
    
    /**
     *
     * @param    _src
     * @param    _name
     */
    public function Range(_src:String, _name:String) {
        this.name = _name;
        this.src = _src;
        this.isLoaded = false;
    }
}

/**
 * class PeriodMesh
 */
import alternativ5.engine3d.core.Mesh;
class PeriodMesh {
    public var object:Mesh;
}

/**
 * class PeriodTarget
 */
import alternativ5.engine3d.core.Mesh;
import alternativ5.types.Point3D;
import alternativ5.engine3d.core.Object3D;

import org.libspark.betweenas3.BetweenAS3;
import org.libspark.betweenas3.tweens.ITween;
class PeriodTarget {
    public var object:Mesh;
    public var id:uint;
    public var isSwitchTarget:Boolean;
    public var isTweenTarget:Boolean;
    public var isStandup:Boolean;
    public var numLife:int;
    public var smashTween:String;
    public var smashTweenTime:uint;
    public var collisionRadius:Number;
    public var criticalCollisionRadius:Number;
    public var ignoreDelayCriterialMeters:Number;
    
    public var tween:ITween;
    
    /**
     *
     * @param    _name
     * @param    _numLife
     */
    public function PeriodTarget(
        _id:uint = 0,
        _isSwitchTarget:Boolean = false,
        _isTweenTarget:Boolean = false,
        _numLife:int = 0,
        _smashTween:String = null,
        _smashTweenTime:uint = 0,
        _collisionRadius:Number = NaN,
        _criticalCollisionRadius:Number = NaN,
        _ignoreDelayCriterialMeters:Number = NaN
    ) {
        this.id = _id as uint;
        this.numLife = _numLife as int;
        this.isSwitchTarget = _isSwitchTarget as Boolean;
        this.isTweenTarget = _isTweenTarget as Boolean;
        this.isStandup = true;
        this.smashTween = _smashTween as String;
        this.smashTweenTime = _smashTweenTime as uint;
        this.collisionRadius = _collisionRadius as Number;
        this.criticalCollisionRadius = _criticalCollisionRadius as Number;
        this.ignoreDelayCriterialMeters = _ignoreDelayCriterialMeters as Number;
    }
    
    /**
     *
     * @return
     */
    public function hit():Boolean {
        this.numLife -= 1;
        return (this.numLife || this.numLife < 0) ? true : false;
    }
    
    /**
     *
     * @param    db
     */
    public function createTweenInstanceAndPlay(db:XMLList):void {
        //var len:uint = db.tween.length();
        //var tweens:Array = [];
        //
        //
        //for (var a:uint = 0; a < len; a++) {
            //
            //ins undefined
            //var to:Object = new Object();
            //var from:Object = new Object();
            //
            //var fromAttributes:XMLList = db.tween[a].from.@*;
            //var toAttributes:XMLList = db.tween[a].to.@*;
            //
            //for (var b:uint = 0; b < fromAttributes.length(); b++)
                //from[String(fromAttributes[b].name())] = Number(fromAttributes[b]);
            //
            //for (var c:uint = 0; c < toAttributes.length(); c++)
                //to[String(toAttributes[c].name())] = Number(toAttributes[c]);
            //
            //var t:ITween = BetweenAS3.tween(this.object, to, from, Number(db.tween[a].@time), null);
            //tweens.push(t);
        //}
        //
        //tween = BetweenAS3.serialTweens(tweens);
        //
        //if (db.@reverse == "true") {
            //tween = BetweenAS3.serial(tween, BetweenAS3.reverse(tween));
        //}
        //
        //tween.stopOnComplete = (db.@repeat == "true") ? false : true;
        //tween.play();
        
    }
    
    /**
     *
     * @param    position
     * @return
     */
    public function gotoAndReturnPosition(position:Number):Point3D {
        
        var tmp:PeriodTarget = new PeriodTarget();
        tmp.object = new Mesh();
        tmp.object.x = this.object.x;
        tmp.object.y = this.object.y;
        tmp.object.z = this.object.z;
        tmp.tween = this.tween.clone();
        
        
        var pos:Number = this.tween.position + position;
        
        tmp.tween.gotoAndStop(pos);
        
        //Debug.log(this.object.coords, 0xFF0000);
        //Debug.log(tmp.object.coords, 0xFFFF00);
        
        return tmp.object.coords as Point3D;
    }
}

/**
 * classPeriod
 */
class Period {
    public var meshes:Vector.<PeriodMesh>;
    public var targets:Vector.<PeriodTarget>;
}

/**
 * class StandupTargets
 */
class StandupTargets {
    public var targets:Vector.<TargetAddress>;
    public var tweenTargets:Vector.<TargetAddress>;
}

/**
 * class TargetAddress
 */
class TargetAddress {
    public var period:String;
    public var target:uint;
    
    public function TargetAddress(_period:String, _target:uint) {
        this.period = _period;
        this.target = _target;
    }
}

/**
 * class SignalEvent
 */
class SignalEvent {
    public static const ALL_TARGETS_BREAKING:String = "AllTargetsBreaking";
    public static const SWITCH_TARGETS_BREAKING:String = "SwitchTargetsBreaking";
    public static const ALL_MESSAGES_SHOWING:String = "AllMessagesShowing";
}

class Message {
    public var message:String;
    public var time:Number;
    public var delay:Number;
    
    /**
     *
     * @param    _message
     * @param    _time
     * @param    _delay
     */
    public function Message(_message:String, _time:Number, _delay:Number) {
        this.message = _message;
        this.time = _time * 1000;
        this.delay = _delay * 1000;
    }
}


/**
 * EZCreateMesh
 *
 * 簡単に より早くメッシュを作成する為に
 *
 * Alternativa3Dを利用したマップ(Mesh)作成時に ASでは 頂点やフェイス、
 * サーフェス全てに id(名前)をつける必要があり、これらの作業は非常に面倒です
 *
 * XMLに情報を記述することによって
 * 値 変更時にコンパイルが不要になり、誰でも簡単にマップ作成が可能です
 *
 * @author br
 */
import alternativ5.engine3d.core.*;
import alternativ5.engine3d.materials.*;
import alternativ5.types.*;
import alternativ5.utils.*;
import org.libspark.betweenas3.BetweenAS3;
import org.libspark.betweenas3.tweens.ITween;

import flash.geom.*;
import flash.display.*;

import alternativ5.engine3d.core.*;
import alternativ5.engine3d.materials.*;
import alternativ5.types.*;
import alternativ5.utils.*;

import flash.geom.*;
import flash.display.*;

import alternativ5.engine3d.events.*;

class EZCreateMesh {
    
    /**
     * static const
     */
    
    // MATERIAL
    public static const  DEV:String = "DevMaterial";
    public static const  FILL:String = "FillMaterial";
    public static const  TEXTURE:String = "TextureMaterial";
    public static const WIRE:String = "WireMaterial";
    public static const MOVIECLIP:String = "MovieClipMaterial";
    
    
    // SPEITE 3D
    public static const SPRITE_TEXTURE:String = "SpriteTextureMaterial";
    public static const SPRITE:String = "SpriteMaterial";
    
    public static const ID_CONCAT:String = ":";
    public static const ID_SURFACE:String = "s";
    public static const ID_FACE:String = "f";
    public static const ID_VERTEX:String = "v";
    
    public static const KEY_MAP:String = "m";
    
    private static const _PI:Number = Math.PI;
    
    
    /**
     * 渡されたXMLに記載されているMeshを全て作成し配列で返します
     * @param    db
     */
    public static function createMeshes(db:XML, textures:Array = null, main:Main = null):/*Mesh*/Array {
        
        
        var _meshes:/*Mesh*/Array = [];
        
        for (var a:int = 0; a < db.mesh.length(); a++) {
            _meshes[db.mesh[a].@name] = new Mesh();
            
            var textureLists:XMLList = db.mesh[a].surface.(@materialType == TEXTURE).@name;
            
            _meshes[db.mesh[a].@name] = createMesh(db.mesh[a], textures, main) as Mesh;
        }
        
        return _meshes;
    }
    
    /**
     * マップを作成
     * @param    map
     * @param    mapName
     */
    public static function createMap(db:XML, _meshes:/*Mesh*/Array):Map {
        var map:Map = new Map();
        
        for (var a:int = 0; a < db.set.length(); a++) {
            
            var _set:Set;
            var elements:Array = [];
            
            for (var b:int = 0; b < db.set[a].mesh.length(); b++) {
                var mesh:Mesh = meshPropertiesSetup(
                    _meshes[db.set[a].mesh[b].@name].clone(),
                    db.set[a].mesh[b]
                );
                elements.push(mesh);
            }
            
            _set = Set.createFromArray(elements);
            map.add(KEY_MAP + ID_CONCAT + db.set[a].@name, _set);
        }
        
        return map;
    }
    
    /**
     * XMLを元にプロパティを変更したメッシュを返します
     * @param    mesh メッシュ
     * @param    properties プロパティが記載されたXML
     * @return mesh プロパティが変更されたメッシュを返します
     * @exampleText XMLの例を示します
     * <listing version="3.0">
     * <mesh z="-100" scaleX="5" scaleY="5" />
     * </listing>
     */
    public static function meshPropertiesSetup(mesh:Mesh, properties:XML):Mesh {
        if (properties.hasOwnProperty("@x")) mesh.x = Number(properties.@x);
        if (properties.hasOwnProperty("@y")) mesh.y = Number(properties.@y);
        if (properties.hasOwnProperty("@z")) mesh.z = Number(properties.@z);
        if (properties.hasOwnProperty("@scaleX")) mesh.scaleX = Number(properties.@scaleX);
        if (properties.hasOwnProperty("@scaleY")) mesh.scaleY = Number(properties.@scaleY);
        if (properties.hasOwnProperty("@scaleZ")) mesh.scaleZ = Number(properties.@scaleZ);
        if (properties.hasOwnProperty("@rotationX")) mesh.rotationX = MathUtils.toRadian(Number(properties.@rotationX));
        if (properties.hasOwnProperty("@rotationY")) mesh.rotationY = MathUtils.toRadian(Number(properties.@rotationY));
        if (properties.hasOwnProperty("@rotationZ")) mesh.rotationZ = MathUtils.toRadian(Number(properties.@rotationZ));
        return mesh;
    }
    
    
    
    /**
     * メッシュ作成
     * @param    xml メッシュの情報が記載されたXML
     * @return Mesh
     */
    public static function createMesh(xml:XML, textures:/*BitmapData*/Array = null, main:Main = null):Mesh {
        
        var _mesh:Mesh = new Mesh();
        var surfaces:Array = [];
        
        for (var a:int = 0; a < xml.surface.length(); a++)
        {
            
            // eg - s:s (s:0)
            var surfaceName:String = xml.surface[a].hasOwnProperty("@id") ? xml.surface[a].@id : String(ID_SURFACE + ID_CONCAT + a);
            var materialType:String = xml.surface[a].@materialType;
            
            var faces:Array = [];
            
            for (var b:int = 0; b < xml.surface[a].face.length(); b++)
            {
                
                if ("vertices" in xml.surface[a].face[b]) {
                    for (var v:int = 0; v < xml.surface[a].face[b].vertices.length(); v++) {
                        xml.surface[a].face[b].vertices[v].prependChild(createVerticesPrimitive(xml.surface[a].face[b].vertices[v]));
                    }
                }
                
                // eg - f:sf (f:00)
                var faceName:String = xml.surface[a].face[b].hasOwnProperty("@id") ? xml.surface[a].face[b].@id : String(ID_FACE + ID_CONCAT + a + b);
                var vertices:Array = [];
                
                for (var c:int = 0; c < xml.surface[a].face[b]..vertex.length(); c++)
                {
                    
                    // eg - v:sfv (v:000)
                    var vertexName:String = xml.surface[a].face[b]..vertex[c].hasOwnProperty("@id") ? xml.surface[a].face[b]..vertex[c].@id : String(ID_VERTEX + ID_CONCAT + a + b + c);
                    
                    /**
                     * createVertex
                     */
                    _mesh.createVertex(
                        xml.surface[a].face[b]..vertex[c].@x,
                        xml.surface[a].face[b]..vertex[c].@y,
                        xml.surface[a].face[b]..vertex[c].@z,
                        vertexName
                    );
                    vertices.push(vertexName);
                }
                
                /**
                 * createFace
                 */
                _mesh.createFace(vertices, faceName);
                
                with ( _mesh.getFaceById( faceName ) ) {
                    if ( xml.surface[a].face[b].hasOwnProperty("@click") )
                        addEventListener(MouseEvent3D.CLICK , main[xml.surface[a].face[b].@click]);
                    
                    if ( xml.surface[a].face[b].hasOwnProperty("@mouseDown") )
                        addEventListener(MouseEvent3D.MOUSE_DOWN, main[xml.surface[a].face[b].@mouseDown]);
                    
                    if ( xml.surface[a].face[b].hasOwnProperty("@mouseMove") )
                        addEventListener(MouseEvent3D.MOUSE_MOVE , main[xml.surface[a].face[b].@mouseMove]);
                    
                    if ( xml.surface[a].face[b].hasOwnProperty("@mouseOut") )
                        addEventListener(MouseEvent3D.MOUSE_OUT, main[xml.surface[a].face[b].@mouseOut]);
                    
                    if ( xml.surface[a].face[b].hasOwnProperty("@mouseOver") )
                        addEventListener(MouseEvent3D.MOUSE_OVER, main[xml.surface[a].face[b].@mouseOver]);
                    
                    if ( xml.surface[a].face[b].hasOwnProperty("@mouseUp") )
                        addEventListener(MouseEvent3D.MOUSE_UP , main[xml.surface[a].face[b].@mouseUp]);
                    
                    if ( xml.surface[a].face[b].hasOwnProperty("@mouseWheel") )
                        addEventListener(MouseEvent3D.MOUSE_WHEEL, main[xml.surface[a].face[b].@mouseWheel]);
                }
                
                
                /**
                 * setUVsToFace
                 */
                if ("UVs" in xml.surface[a].face[b]) {
                    with ( xml.surface[a].face[b].UVs ) {
                        _mesh.setUVsToFace(
                            new Point(aUV.@x, aUV.@y),
                            new Point(bUV.@x, bUV.@y),
                            new Point(cUV.@x, cUV.@y),
                            faceName
                        );
                    }
                }
                
                /**
                 * push Faces
                 */
                faces.push(faceName);
            }
            
            /**
             * createSurface
             */
            _mesh.createSurface(faces, surfaceName);
            
            with ( _mesh.getSurfaceById(surfaceName) ) {
                if ( xml.surface[a].hasOwnProperty("@click") )
                    addEventListener(MouseEvent3D.CLICK , main[xml.surface[a].@click]);
                
                if ( xml.surface[a].hasOwnProperty("@mouseDown") )
                    addEventListener(MouseEvent3D.MOUSE_DOWN, main[xml.surface[a].@mouseDown]);
                
                if ( xml.surface[a].hasOwnProperty("@mouseMove") )
                    addEventListener(MouseEvent3D.MOUSE_MOVE , main[xml.surface[a].@mouseMove]);
                
                if ( xml.surface[a].hasOwnProperty("@mouseOut") )
                    addEventListener(MouseEvent3D.MOUSE_OUT, main[xml.surface[a].@mouseOut]);
                
                if ( xml.surface[a].hasOwnProperty("@mouseOver") )
                    addEventListener(MouseEvent3D.MOUSE_OVER, main[xml.surface[a].@mouseOver]);
                
                if ( xml.surface[a].hasOwnProperty("@mouseUp") )
                    addEventListener(MouseEvent3D.MOUSE_UP , main[xml.surface[a].@mouseUp]);
                
                if ( xml.surface[a].hasOwnProperty("@mouseWheel") )
                    addEventListener(MouseEvent3D.MOUSE_WHEEL, main[xml.surface[a].@mouseWheel]);
            }
            
            
            /**
             * push
             */
            surfaces.push(surfaceName);
            
            /**
             * setMaterialToSurface
             */
            _mesh.setMaterialToSurface(
                createMaterial(
                    xml.surface[a],
                    ( materialType == TEXTURE || materialType == MOVIECLIP ) ? textures[xml.surface[a].@name] : null),
                surfaceName
            );
        }
        
        return _mesh;
    }
    
    /**
     * マテリアルを作成
     * @param    material マテリアル情報が記載されたXML
     * @return SurfaceMaterial
     * @exampleText XMLの例を示します
     * <listing version="3.0">
     * <surface materialType={EZCreateMesh.FILL} color="0x99ab4e" wirethickness="1" wirecolor="0x7b8d42" />
     * <surface materialType="TextureMaterial" repeat="true" smooth="true" src="image" precision="BEST" />
     * </listing>
     */
    public static function createMaterial(material:XML, texture:* = null):SurfaceMaterial {
        with ( material ) {
            switch ( @materialType.toString() ) {
                
                case DEV :
                    return new DevMaterial(
                        hasOwnProperty("@parametertype") ? @parametertype : 0,
                        hasOwnProperty("@color") ? @color: 0xffffff * Math.random(),
                        hasOwnProperty("@maxparametervalue") ? @maxparametervalue : 20,
                        hasOwnProperty("@shownormals") ? @shownormals : false,
                        hasOwnProperty("@normalscolor") ? @normalscolor : 0x00FFFF,
                        hasOwnProperty("@minmobility") ? @minmobility : 0,
                        hasOwnProperty("@maxmobility") ? @maxmobility : 255,
                        hasOwnProperty("@alpha") ? @alpha : 1,
                        hasOwnProperty("@blendmode") ? @blendmode : BlendMode.NORMAL,
                        hasOwnProperty("@wirethickness") ? @wirethickness : -1,
                        hasOwnProperty("@wirecolor") ? @wirecolor : 0
                    );
                break;
                
                case FILL :
                    return new FillMaterial(
                        hasOwnProperty("@color") ? @color: 0xffffff * Math.random(),
                        hasOwnProperty("@alpha") ? @alpha : 1,
                        hasOwnProperty("@blendmode") ? @blendmode : BlendMode.NORMAL,
                        hasOwnProperty("@wirethickness") ? @wirethickness : -1,
                        hasOwnProperty("@wirecolor") ? @wirecolor : 0
                    );
                break;
                
                case TEXTURE :
                    return new TextureMaterial(
                    new Texture(texture),
                    hasOwnProperty("@alpha") ? @alpha : 1,
                    hasOwnProperty("@repeat") ? (@repeat == "true" ? true : false) : true,
                    hasOwnProperty("@smooth") ? (@smooth == "true" ? true : false) : false,
                    hasOwnProperty("@blendmode") ? @blendmode : BlendMode.NORMAL,
                    hasOwnProperty("@wirethickness") ? @wirethickness : -1,
                    hasOwnProperty("@wirecolor") ? @wirecolor : 0,
                    hasOwnProperty("@precision") ? @precision : 10
                    );
                break;
                
                case WIRE :
                    return new WireMaterial(
                        hasOwnProperty("@thickness") ? @thickness : 0,
                        hasOwnProperty("@color") ? @color : 0xffffff * Math.random(),
                        hasOwnProperty("@alpha") ? @alpha : 1,
                        hasOwnProperty("@blendmode") ? @blendmode : BlendMode.NORMAL
                    );
                break;
                
                case MOVIECLIP :
                    return new MovieClipMaterial(
                        MovieClip( texture ),
                        @textureWidth,
                        @textureHeight,
                        new Rectangle(
                            hasOwnProperty("@clipX") ? @clipX : 0,
                            hasOwnProperty("@clipY") ? @clipY : 0,
                            hasOwnProperty("@clipWidth") ? @clipWidth : 0,
                            hasOwnProperty("@clipHeight") ? @clipHeight : 0
                        ),
                        new Matrix(
                            hasOwnProperty("@a") ? @a : 1,
                            hasOwnProperty("@b") ? @b : 0,
                            hasOwnProperty("@c") ? @c : 0,
                            hasOwnProperty("@d") ? @d : 1,
                            hasOwnProperty("@tx") ? @tx : 0,
                            hasOwnProperty("@ty") ? @ty : 0
                        ),
                        hasOwnProperty("@smooth") ? (@smooth == "true" ? true : false) : false,
                        hasOwnProperty("@precision") ? @precision : 10,
                        hasOwnProperty("@fillColor") ? @fillColor : 0xffffff * Math.random(),
                        hasOwnProperty("@refreshRate") ? @refreshRate : 1
                    );
                break;
                
                default :
                    return null;
                break;
            }
        }
    }
    
    
    /**
     * PRIMITIVE
     */
    public static const CIRCLE:String = "Circle";
    
    /**
     * 頂点の情報を返します UV情報は含まれません。
     * @param    primitive
     * @return
     */
    public static function createVerticesPrimitive(primitive:XML):XMLList {
        
        var _vertices:XML = <vertices></vertices>;
        
        with (primitive) {
            switch ( @primitive.toString() ) {
                case CIRCLE : return buildCircleVertices(@tx, @ty, @tz, @r, @rp);
                default : return new XMLList();
            }
        }
        
        
        function buildCircleVertices(tx: Number, ty: Number, tz:Number, r:Number, rp:Number): XMLList {
            
            for (var rad:int = 0; rad < 360; rad += rp) {
                v(Math.cos(rad * _PI / 180) * r, Math.sin(rad * _PI / 180) * r,  tz);
            }
            
            return _vertices.vertex
        }
        
        /**
         * create v
         * @param    _x
         * @param    _y
         * @param    _z
         */
        function v(_x:Number, _y:Number, _z:Number):void {
            _vertices.appendChild(<vertex x={_x} y={_y} z={_z} />);
        }
    }
}


class HitTest {
    /**
     * hitTestR2R3D
     * @param    pEyeLine
     * @param    pPlayer
     * @param    pTarget
     * @param    radius
     * @return
     */
    public static function R2R3D(pEyeLine:Point3D, pPlayer:Point3D, pTarget:Point3D, radius:Number):Boolean {
        const _PI:Number = 3.141592653589793;
        
        var  playerPoint2DXY:Point  = new Point(pPlayer.x, pPlayer.y);
        var targetPoint2DXY:Point = new Point(pTarget.x, pTarget.y);
        var playerSubtractEyeLine2DXY:Point = playerPoint2DXY.subtract(new Point(pEyeLine.x, pEyeLine.y));
        var playerSubtractTarget2DXY:Point = targetPoint2DXY.subtract(new Point(pPlayer.x, pPlayer.y));
        var radian2DXY:Number = Math.atan2(playerSubtractTarget2DXY.y, playerSubtractTarget2DXY.x) + _PI * .5;
        var playerSubtractOnRadiusPointA2DXY:Point = playerPoint2DXY.subtract(targetPoint2DXY.add(Point.polar(radius, radian2DXY)));
        var playerSubtractOnRadiusPointB2DXY:Point = playerPoint2DXY.subtract(targetPoint2DXY.add(Point.polar(radius, radian2DXY + _PI)));
        var radA2DXY:Number = Math.atan2(playerSubtractOnRadiusPointA2DXY.y, playerSubtractOnRadiusPointA2DXY.x);
        var radB2DXY:Number = Math.atan2(playerSubtractOnRadiusPointB2DXY.y, playerSubtractOnRadiusPointB2DXY.x);
        var radP2T2DXY:Number = Math.atan2(playerSubtractEyeLine2DXY.y, playerSubtractEyeLine2DXY.x);
        
        /**
         * XY
         */
        if(
            ((radA2DXY < 0 && radB2DXY > 0) && (radA2DXY > radP2T2DXY || radB2DXY < radP2T2DXY)) ||
            ((radA2DXY > 0 && radB2DXY < 0) && ((radA2DXY > radP2T2DXY && radP2T2DXY > 0) || (radB2DXY < radP2T2DXY && radP2T2DXY < 0) ||(radP2T2DXY > 3))) ||
            (((radA2DXY < radP2T2DXY && radP2T2DXY < radB2DXY) || (radA2DXY > radP2T2DXY && radP2T2DXY > radB2DXY)))
        )
        {
            var playerPoint2DXZ:Point  = new Point(pPlayer.x, pPlayer.z);
            var targetPoint2DXZ:Point = new Point(pTarget.x, pTarget.z);
            var playerSubtractEyeLine2DXZ:Point = playerPoint2DXZ.subtract(new Point(pEyeLine.x, pEyeLine.z));
            var playerSubtractTarget2DXZ:Point = targetPoint2DXZ.subtract(new Point(pPlayer.x, pPlayer.z));
            var radian2DXZ:Number = Math.atan2(playerSubtractTarget2DXZ.y, playerSubtractTarget2DXZ.x) + _PI * .5;
            var playerSubtractOnRadiusPointA2DXZ:Point = playerPoint2DXZ.subtract(targetPoint2DXZ.add(Point.polar(radius, radian2DXZ)));
            var playerSubtractOnRadiusPointB2DXZ:Point = playerPoint2DXZ.subtract(targetPoint2DXZ.add(Point.polar(radius, radian2DXZ + _PI)));
            var radA2DXZ:Number = Math.atan2(playerSubtractOnRadiusPointA2DXZ.y, playerSubtractOnRadiusPointA2DXZ.x);
            var radB2DXZ:Number = Math.atan2(playerSubtractOnRadiusPointB2DXZ.y, playerSubtractOnRadiusPointB2DXZ.x);
            var radP2T2DXZ:Number = Math.atan2(playerSubtractEyeLine2DXZ.y, playerSubtractEyeLine2DXZ.x);
            
            /**
             * XZ
             */
            if(
            ((radA2DXZ < 0 && radB2DXZ > 0) && (radA2DXZ > radP2T2DXZ || radB2DXZ < radP2T2DXZ)) ||
            ((radA2DXZ > 0 && radB2DXZ < 0) && ((radA2DXZ > radP2T2DXZ && radP2T2DXZ > 0) || (radB2DXZ < radP2T2DXZ && radP2T2DXZ < 0) || radP2T2DXZ > 3)) ||
            (((radA2DXZ < radP2T2DXZ && radP2T2DXZ < radB2DXZ) || (radA2DXZ > radP2T2DXZ && radP2T2DXZ > radB2DXZ)))
            ) return true;
        }
        
        /**
         * NO_HIT
         */
        return false;
    }
}


class Wonderfl_Resource {
    public static const STAGES:XML = <data>
        <stages>
            <stage name="Tutorial Stage" src="../../up/files/FFPS/res/stages/debugStage.xml" />
        </stages>
    </data>;
    
    public static const RANGE:XML = <data>
    <info>
        <config>
            <startPeriod name="Start" />
            <variables>
                <variable name="hoge" value="foobar" />
                <variable name="houseWidth" value="100" />
            </variables>
            <!--<player walkSpeed="400" walkSpeedZoomed="200" jumpSpeed="600" gravity="3000" height="1" viewSpeed="0.008" viewSpeedZoomed="0.002" waggle="0.01" waggleZoomed="0.001" footstepSound="footstep" />-->
            <player flyMode="false" defaultX="0" defaultY="0" defaultZ="100" walkSpeed="400" walkSpeedZoomed="0" jumpSpeed="0" gravity="3000" height="1" waggle="0.01" waggleZoomed="0.001" />
        </config>
    </info>
    <weapons>
        <!--<weapon name="0.2" recoil = "0.002" enlargement = "0.2" magazine = "12" reloadtime = "2000" speed = "2" range = "20000" zeroin = "2" waggle = "0.001" waggleZoomed = "0.0007" viewSpeed="0.008" viewSpeedZoomed="0.0003"  interval = "1500" reticleLookingScopeName="LookingScope" reticleNoLookingScopeName="NoLookingScope" shootSound="shoot" reloadSound="reloading"  loadSound="gunshell" supplyType="Automatic"/>-->
        <weapon name="0.2" recoil = "0.002" enlargement = "0.2" magazine = "12" reloadtime = "2000" speed = "2" range = "20000" zeroin = "2" waggle = "0.001" waggleZoomed = "0.0007" viewSpeed="0.008" viewSpeedZoomed="0.0003"  interval = "1500" reticleLookingScopeName="LookingScope" reticleNoLookingScopeName="NoLookingScope" supplyType="Automatic"/>
        <weapon name="0.08" recoil = "0.0004" enlargement = "0.08" magazine = "12" reloadtime = "2000" speed = "2" range = "20000" zeroin = "2" waggle = "0.001" waggleZoomed = "0.0005" viewSpeed="0.008" viewSpeedZoomed="0.0001"  interval = "1500" reticleLookingScopeName="LookingScope" reticleNoLookingScopeName="NoLookingScope" supplyType="Automatic"/>
        <weapon name="0.5" recoil = "0.004" enlargement = "0.5" magazine = "10" reloadtime = "2000" speed = "2" range = "200000" zeroin = "2" waggle = "0.001" waggleZoomed = "0.002" viewSpeed="0.008" viewSpeedZoomed="0.0005"  interval = "1000" reticleLookingScopeName="LookingScope" reticleNoLookingScopeName="NoLookingScope" supplyType="BoltAction" />
 <weapon name="M249 Para" recoil = "0.001" enlargement = "0.5" magazine = "100" reloadtime = "2000" speed = "2" range = "200000" zeroin = "2" waggle = "0.001" waggleZoomed = "0.002" viewSpeed="0.008" viewSpeedZoomed="0.0005"  interval = "10" reticleLookingScopeName="LookingScope" reticleNoLookingScopeName="NoLookingScope" supplyType="Automatic" />
    </weapons>
    <!-- <resources>
        <sounds>
            <sound name="shoot" src="../../up/files/FFPS/res/sounds/shot.mp3" />
            <sound name="reloading" src="../../up/files/FFPS/res/sounds/reloading.mp3" />
            <sound name="loading" src="../../up/files/FFPS/res/sounds/loading.mp3" />
            <sound name="gunshell" src="../../up/files/FFPS/res/sounds/gunshellconcrete.mp3" />
            <sound name="footstep" src="../../up/files/FFPS/res/sounds/footstep.mp3" />
        </sounds>
        <images>
            <image name="cloud" src="../../up/files/FFPS/res/images/cloud.png" />
            <image name="target" src="../../up/files/FFPS/res/images/target.png" />
        </images>
    </resources> -->
    <reticles>
        <svg name="NoLookingScope">
            <g stroke="#0" opacity="0.3">
                <line x1="300" y1="240" x2="320" y2="240" />
                <line x1="400" y1="240" x2="420" y2="240" />
                <line x1="360" y1="180" x2="360" y2="200" />
                <line x1="360" y1="280" x2="360" y2="300" />
            </g>
        </svg>
        <svg name="LookingScope">
          <g stroke="#0">
                <line x1="180" y1="240" x2="280" y2="240" stroke-width="3" />
                <line x1="440" y1="240" x2="540" y2="240" stroke-width="3" />
                <line x1="340" y1="240" x2="380" y2="240" />
                <line x1="280" y1="240" x2="310" y2="240" />
                <line x1="410" y1="240" x2="440" y2="240" />
                <line x1="360" y1="220" x2="360" y2="260" />
                <line x1="360" y1="280" x2="360" y2="290" />
                <line x1="325" y1="255" x2="325" y2="270" />
                <line x1="395" y1="255" x2="395" y2="270" />
                <line x1="360" y1="310" x2="360" y2="320" />
                <line x1="340" y1="300" x2="350" y2="300" />
                <line x1="370" y1="300" x2="380" y2="300" />
                <line x1="220" y1="370" x2="350" y2="370" />
                <line x1="370" y1="370" x2="500" y2="370" />
                <line x1="360" y1="380" x2="360" y2="400" />
                <line x1="360" y1="420" x2="360" y2="430" />
                <line x1="340" y1="410" x2="350" y2="410" />
                <line x1="370" y1="410" x2="380" y2="410" />
                <line x1="235" y1="356" x2="265" y2="356" />
                <line x1="270" y1="350" x2="300" y2="350" />
                <line x1="305" y1="344" x2="335" y2="344" />
                <line x1="385" y1="331" x2="415" y2="331" />
                <line x1="420" y1="325" x2="450" y2="325" />
                <line x1="455" y1="319" x2="485" y2="319" />
            </g>
            <g stroke="none" fill="#0">
                <circle cx="325" cy="240" r="1" />
                <circle cx="395" cy="240" r="1" />
                <circle cx="360" cy="270" r="1" />
                <circle cx="360" cy="300" r="1" />
                <circle cx="360" cy="370" r="1" />
                <circle cx="360" cy="410" r="1" />
            </g>
            <g stroke="#0" fill="none">
                <circle cx="250" cy="360" r="3" />
                <circle cx="285" cy="355" r="4" />
                <circle cx="320" cy="350" r="5" />
                <circle cx="400" cy="340" r="8" />
                <circle cx="435" cy="335" r="9" />
                <circle cx="470" cy="330" r="10" />
            </g>
        </svg>
    </reticles>
    <meshes>
        <mesh name="Geo">
                <surface materialType="FillMaterial" color="0x99ab4e" wirethickness="1" wirecolor="0x7b8d42">
                        <face>
                                <vertex x="100000" y="100000" z="0" />
                                <vertex x="-100000" y="100000" z="0" />
                                <vertex x="-100000" y="-100000" z="0" />
                                <vertex x="100000" y="-100000" z="0" />
                        </face>
                </surface>
        </mesh>
        <mesh name="Sky">
                <surface materialType="FillMaterial" repeat="true" smooth="true" name="cloud" precision="VERY_LOW" >
                        <face>
                                <UVs>
                                    <aUV x="0" y="0" />
                                    <bUV x="0" y="1" />
                                    <cUV x="1" y="1" />
                                </UVs>
                                <vertex x="100000" y="100000" z="0" />
                                <vertex x="-100000" y="100000" z="0" />
                                <vertex x="-100000" y="-100000" z="0" />
                                <vertex x="100000" y="-100000" z="0" />
                        </face>
                </surface>
        </mesh>
        <mesh name="House">
                <surface materialType="FillMaterial" color="0x6c848d" wirethickness="1" wirecolor="0x4c6473">
                        <face>
                                <vertex x="1000" y="1000" z="0" />
                                <vertex x="-1000" y="1000" z="0" />
                                <vertex x="-1000" y="-1000" z="0" />
                                <vertex x="1000" y="-1000" z="0" />
                        </face>
                        <face>
                                <vertex x="-1000" y="1000" z="0" />
                                <vertex x="-1000" y="1000" z="500" />
                                <vertex x="-1000" y="-1000" z="500" />
                                <vertex x="-1000" y="-1000" z="0" />
                        </face>
                        <face>
                                <vertex x="1000" y="-1000" z="500" />
                                <vertex x="-1000" y="-1000" z="500" />
                                <vertex x="-1000" y="1000" z="500" />
                                <vertex x="1000" y="1000" z="500" />
                        </face>
                        <face>
                                <vertex x="-1000" y="-1000" z="0" />
                                <vertex x="-1000" y="-1000" z="500" />
                                <vertex x="1000" y="-1000" z="500" />
                                <vertex x="1000" y="-1000" z="0" />
                        </face>
                        <face>
                                <vertex x="1000" y="-1000" z="0" />
                                <vertex x="1000" y="-1000" z="500" />
                                <vertex x="1000" y="1000" z="500" />
                                <vertex x="1000" y="1000" z="0" />
                        </face>
                        <face>
                                <vertex x="1000" y="1000" z="0" />
                                <vertex x="1000" y="1000" z="150" />
                                <vertex x="-1000" y="1000" z="150" />
                                <vertex x="-1000" y="1000" z="0" />
                        </face>
                        <face>
                                <vertex x="1000" y="1000" z="150" />
                                <vertex x="1000" y="1020" z="150" />
                                <vertex x="-1000" y="1020" z="150" />
                                <vertex x="-1000" y="1000" z="150" />
                        </face>
                        <face>
                                <vertex x="-1000" y="1000" z="300" />
                                <vertex x="-1000" y="1020" z="300" />
                                <vertex x="1000" y="1020" z="300" />
                                <vertex x="1000" y="1000" z="300" />
                        </face>
                        <face>
                                <vertex x="1000" y="1000" z="150" />
                                <vertex x="1000" y="1000" z="300" />
                                <vertex x="1000" y="1020" z="300" />
                                <vertex x="1000" y="1020" z="150" />
                        </face>
                        <face>
                                <vertex x="-1000" y="1020" z="150" />
                                <vertex x="-1000" y="1020" z="300" />
                                <vertex x="-1000" y="1000" z="300" />
                                <vertex x="-1000" y="1000" z="150" />
                        </face>
                        <face>
                                <vertex x="1000" y="1000" z="300" />
                                <vertex x="1000" y="1000" z="500" />
                                <vertex x="-1000" y="1000" z="500" />
                                <vertex x="-1000" y="1000" z="300" />
                        </face>
                </surface>
        </mesh>
        <mesh name="Sign">
            <surface materialType="FillMaterial" color="0x426579">
                <face>
                        <vertex x="100" y="30" z="0" />
                        <vertex x="-100" y="30" z="0" />
                        <vertex x="-150" y="0" z="0" />
                        <vertex x="-100" y="-30" z="0" />
                        <vertex x="-10" y="-30" z="0" />
                        <vertex x="-10" y="-100" z="0" />
                        <vertex x="10" y="-100" z="0" />
                        <vertex x="10" y="-30" z="0" />
                        <vertex x="100" y="-30" z="0" />
                </face>
            </surface>
        </mesh>
        <mesh name="Target">
                <surface materialType="FillMaterial" color="0xFF0000" repeat="true" smooth="true" name="target" precision="VERY_LOW">
                        <face>
                                <UVs>
                                    <aUV x="0" y="0" />
                                    <bUV x="0" y="1" />
                                    <cUV x="1" y="1" />
                                </UVs>
                                <vertex x="100" y="100" z="0" />
                                <vertex x="-100" y="100" z="0" />
                                <vertex x="-100" y="-100" z="0" />
                                <vertex x="100" y="-100" z="0" />
                        </face>
                        <face>
                                <UVs>
                                    <aUV x="0" y="0" />
                                    <bUV x="0" y="1" />
                                    <cUV x="1" y="1" />
                                </UVs>
                                <vertex x="100" y="-100" z="0" />
                                <vertex x="-100" y="-100" z="0" />
                                <vertex x="-100" y="100" z="0" />
                                <vertex x="100" y="100" z="0" />
                        </face>
                </surface>
        </mesh>
    </meshes>
    <map>
        <!--
        Type
        * allTimes
        -->
        <set type="allTimes">
            <mesh name="Geo" z="-1" y="99000" />
            <mesh name="House" />
            <mesh name="Sign" x="300" y="10000" z="100" rotationX="90" />
            <mesh name="Sign" x="300" y="30000" z="100" rotationX="90" />
            <mesh name="Sign" x="300" y="50000" z="100" rotationX="90" />
            <mesh name="Sign" x="300" y="70000" z="100" rotationX="90" />
            <mesh name="Sign" x="300" y="90000" z="100" rotationX="90" />
        </set>
    </map>
    <tweens>
        <tween name="Down">
            <to rotationX="0" />
        </tween>
        <tween name="Up">
            <to rotationX="1.57079633" />
        </tween>
    </tweens>
    <periods>
        <period name="Start" signalEvent="AllTargetsBreaking" nextPeriod="P2">
            <addTargets>
                <addTarget name="Target" numLife="1" rotationX="90" y="5000" z="100" collisionRadius="200" />
            </addTargets>
        </period>
        <period name="P2" signalEvent="AllTargetsBreaking" nextPeriod="P3">
            <addTargets>
                <addTarget name="Target" numLife="1" rotationX="90" x="0" y="10000" z="100" collisionRadius="200" />
                <addTarget name="Target" numLife="1" rotationX="90" x="-1000" y="10000" z="100" collisionRadius="200" />
            </addTargets>
        </period>
        <period name="P3" signalEvent="AllTargetsBreaking" nextPeriod="P4">
            <addTargets>
                <addTarget name="Target" numLife="1" rotationX="90" x="0" y="20000" z="100" collisionRadius="200" />
            </addTargets>
        </period>
        <period name="P4" signalEvent="AllTargetsBreaking" nextPeriod="P5">
            <addTargets>
                <addTarget name="Target" numLife="1" rotationX="90" x="0" y="30000" z="100" collisionRadius="200" />
            </addTargets>
        </period>
        <period name="P5" signalEvent="AllTargetsBreaking" nextPeriod="P6">
            <addTargets>
                <addTarget name="Target" numLife="1" rotationX="90" x="-1000" y="10000" z="100" collisionRadius="200" />
                <addTarget name="Target" numLife="1" rotationX="90" x="-500" y="20000" z="100" collisionRadius="200" />
                <addTarget name="Target" numLife="1" rotationX="90" x="0" y="40000" z="100" collisionRadius="200" />
            </addTargets>
        </period>
        <period name="P6" signalEvent="AllTargetsBreaking" nextPeriod="P7">
            <addTargets>
                <addTarget name="Target" numLife="1" rotationX="90" x="0" y="50000" z="500" collisionRadius="200" />
            </addTargets>
        </period>
        <period name="P7" signalEvent="AllTargetsBreaking" nextPeriod="Start">
            <addTargets>
                <addTarget name="Target" numLife="1" rotationX="90" x="0" y="70000" z="500" collisionRadius="200" />
                <addTarget name="Target" numLife="1" rotationX="90" x="-2000" y="60000" z="100" collisionRadius="200" />
            </addTargets>
        </period>
    </periods>
    </data>;
}