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: forked from: 3DLang

Get Adobe Flash player
by h_sakurai 06 Jan 2009
// forked from h_sakurai's forked from: 3DLang
// forked from h_sakurai's 3DLang
package {
    import flash.display.*;
    import flash.text.*;
    import flash.events.*;

    [SWF(backgroundColor="0x222222", frameRate="30")]
    public class SpaceLang extends Sprite {
        private var key:Key = new Key(stage, logTxt);
        public var ship:Ship = new Ship(230,450);
        private var enemy:Enemy = new Enemy();
        private var ev:EnemyV = new EnemyV(200,200);
        private var camera:Camera = new Camera();
        private var beam:Beam = new Beam();
        static private var logTxt:TextField = new TextField();
        static private var statusTxt:TextField = new TextField();
        public function SpaceLang () {
            main = this;
            addChild(new BeamV());
            addChild(camera);
            addChild(ev);
            addChild(ship);
            with (logTxt) {
                text = "";
                width = 400;
                height = 400;
                textColor = 0x00ff00;
            }
            addChild(logTxt);
            with (statusTxt) {
                text = "";
                width = 400;
                height = 400;
                textColor = 0x00ff00;
            }
            addChild(statusTxt);
            addEventListener(Event.ENTER_FRAME, onEnter);
        }
        static public function log(s:String):void {
            logTxt.text = s+"\n"+logTxt.text;
        }
        static public function status(s:String):void {
            statusTxt.text = s;
        }
        private function onEnter(e:Event):void {
            enemy.move();
            ship.move();
            beam.move();
            if(ship.y-205-10 > camera.Y*3) camera.Y += 2;
            else if(ship.y-205+10 < camera.Y*3) camera.Y -= 2;

            ev.x = enemy.x/enemy.z + 225;
            ev.y = enemy.y/enemy.z-(camera.Y*ZOOM)/(enemy.z)+camera.Y + 225;
            ev.scaleX = ev.scaleY = ZOOM/enemy.z;

            camera.move();
        }
    }
}
const ZOOM:Number = 300;
var main:Sprite;
import flash.display.*;
import flash.text.*;
import flash.events.*;
class Camera extends Sprite {
    public var Y:Number=0;
    public var Z:Number=0;
    public function move():void {
        graphics.clear();
        var z:Number;
        Z-=0.3;
        if(Z < 1)Z+=10;
        for(z=Z;z < 58; z+=2){
        graphics.beginFill(0x0000ff);
            graphics.drawRect(0,225/z*10,465,2);
        graphics.endFill();
        }
        graphics.beginFill(0x0000ff);
        graphics.drawRect(0,0,465,40);
        graphics.endFill();

//        SpaceLang.log(""+Y);
        scaleY = (-Y+225)/225;
        y=Y+225;
    }
}
class Key {
    function Key(stage:Stage,txt:TextField) {
        var kmap:Object = {37:"left", 38:"up",39:"right",40:"down",90:"shot"};
        for each(var i:String in kmap) Key[i]=false;
        stage.addEventListener("keyDown",function(e:KeyboardEvent):void {
//            txt.text = ""+e.keyCode + ":"+kmap[e.keyCode];
            if(e.keyCode in kmap) Key[kmap[e.keyCode]] = true;
        });
        stage.addEventListener("keyUp",function(e:KeyboardEvent):void {
            if(e.keyCode in kmap) Key[kmap[e.keyCode]] = false;
        });
    }
}
class Ship extends Sprite{
    private var speed:Number = 15;
    public function Ship(x:Number, y:Number) {
        this.x = x;
        this.y = y;
        graphics.beginFill(0xffff0000);
        graphics.drawRect(-5,-5,10,10);
        graphics.endFill();
    }
    private var oldX:Number;
    private var oldY:Number;
    public function move():void {
        if(oldX != main.stage.mouseX)
            oldX = x = main.stage.mouseX;
        if(oldY != main.stage.mouseY)
            oldY = y = main.stage.mouseY;
        if(Key["left" ])x -= speed;
        if(Key["right"])x += speed;
        if(Key["up"   ])y -= speed;
        if(Key["down" ])y += speed;
        if(x < 0) x = 5; else if(x > 465) x = 465 - 5;
        if(y < 0) y = 5; else if(y > 465) y = 465 - 5;

    }
}
class EnemyV extends Sprite {
    public function EnemyV(w:int,h:int) {
        this.graphics.beginFill(0xffffff);
        this.graphics.drawRoundRect (-w/2,-w/2,h,h,w/5,w/5);
        this.graphics.endFill();  
    }
}
class BeamV extends Sprite {
    public function BeamV () {
        const w = 100;
        const h = 100;
        this.graphics.beginFill(0x44ffaa);
        this.graphics.drawRoundRect (-w/2,-w/2,h,h,w/5,w/5);
        this.graphics.endFill(); 
    }
}

class Beam {
    public var x:Number;
    public var y:Number;
    public var z:Number;
    public var vx:Number;
    public var vy:Number;
    public var vz:Number;
    public var visible:Boolean;
    public function Beam() {
        visible = false;
    }
    public function init(x:Number, y:Number):void {
        vz = 10;
        vy = 0;
        vx = 0;
        this.x = x;
        this.y = y;
        this.visible = true;
    }
    public function move():void {
        x += vx; y += vy; z += vz;
        if (z > 30) visible = false;        
    }
}

class Enemy {
    public var x:Number;
    public var y:Number;
    public var z:Number;
    public var s:Number;
    private var prev:int;
    private var key:int;
    private var index:int;
    private var frame:int;
    protected function addKey(key:int, x:Number, y:Number, s:Number, curv:Boolean=false):void {
        if(keyMap == null) {// 最初のフレーム
            keyMap = [];
            index = key;
            frame = key;
            this.key = key;
            prev=-1;
        } else {
            keyMap[prev].next = key;
        }
        var z:Number = ZOOM/ s;
        keyMap[key]={x:x*z, y:y*z, z:z, curv:curv, prev:prev, next:0};
        prev=key;
    }
    protected function addAction(key:int, fun:Function):void {
        actionMap[key]=fun;
    }
    public function log(str:String):void {
        SpaceLang.log(str);
    }
    private var keyMap:Object;
    private var actionMap:Object = {};
    private var names:Array = ["x","y","z"];
    public function move():void {
        var v1:Number;
        var v2:Number;
        if(frame in keyMap) key = frame;
        var next:int = keyMap[key].next;
        var prev:int = keyMap[key].prev;
        // 補完
        var t:Number = (frame - key)/(next-key);
        var t2:Number = 1 - t;
        for(var i:int = 0; i < names.length; i++) {
            var name:String = names[i];
            if(!keyMap[key].curv) {// 角
                if(!keyMap[next].curv) {// 角
                    this[name] = keyMap[key][name] * t2 + keyMap[next][name] * t;
                } else {// 次が丸
                    this[name] =
                        keyMap[key][name]   * -(t-1) * (2-t)/2 + // 0と1のとき0 -1のとき1
                        keyMap[next][name]  *       (1-(t-1))*(1+(t-1))  + // -1と1のとき0
                        keyMap[keyMap[next].next][name] * (t-1)  * (1+(t-1))/2;
                }
            } else { // 丸
                // 次も丸
                if(keyMap[next].curv) {
                    v1 =
                        keyMap[prev][name] * -t * (1-t)/2 + // 0と1のとき0 -1のとき1
                        keyMap[key][name]  *      (1-t)*(1+t)  + // -1と1のとき0
                        keyMap[next][name] * t  * (1+t)/2;
                    t2 = t - 1
                    v2 =
                        keyMap[key][name] * -t2 * (1-t2)/2 + // 0と1のとき0 -1のとき1
                        keyMap[next][name]  *      (1-t2)*(1+t2)  + // -1と1のとき0
                        keyMap[keyMap[next].next][name] * t2  * (1+t2)/2;
                    this[name] = v1*(1-t)+v2*t;
                } else {
                // 次:角
                // これは只の2時曲線
                // t=-1のとき
                    this[name] = 
                        keyMap[prev][name] * -t * (1-t)/2 + // 0と1のとき0 -1のとき1
                        keyMap[key][name]  *      (1-t)*(1+t)  + // -1と1のとき0
                        keyMap[next][name] * t  * (1+t)/2;
                }
            }
        }
        if(key==frame){
            if(key in actionMap) {
                actionMap[key]();
            }
        }
        if(next == 0 && frame > key) {
            frame = index;
            key = frame;
            mode++;
            init();
        } else {
            frame = frame + 1;
        }
    }
    private var mode:int = 0;
    public function Enemy() {
        init();
    }
    public function init():void {
        keyMap = null;
        SpaceLang.status("mode " + mode);
        switch(mode){
case 1:
addKey(0,-225,-205,1/30);
addKey(18,-5,-205,1/30);
addKey(30,215,-205,1/30);
addKey(60,-225,225,1/1);
break;
case 2:
addKey(0,-225,225,1/1);
addKey(30,215,-205,1/30);
addKey(60,-225,-205,1/30);
break;
case 3:
addKey(0,-225,225,1/1);
addKey(30,215,-205,1/30);
addKey(60,-125,-205,1/30);
addKey(90,-125,225,1/1);
break;
case 4:
addKey(0,-225,225,1/1);
addKey(30,215,-205,1/30);
addKey(50,-5,-205,1/30);
addKey(80,-5,225,1/1);
break;
case 5:
addKey(0,-225,225,1/1);
addKey(30,215,-205,1/30);
addKey(40,155,-205,1/30);
addKey(70,155,225,1/1);
break;
case 6:
addKey(0,155,-5,1/30);
addKey(30,155,55,1/7.5);
addKey(60,155,-205,1/3.75);
addKey(90,155,225,1/1);
break;
case 7:
addKey(0,0,-5,1/30);
addKey(30,0,55,1/7.5);
addKey(60,0,-205,1/3.75);
addKey(90,0,225,1/1);
break;
case 8:
addKey(0,-155,-5,1/30);
addKey(30,-155,55,1/20,true);
addKey(60,-155,-205,1/10,true);
addKey(90,-155,225,1/1);
break;
case 9:
addKey( 0,-225,175,1/1);
addKey(30, 155, -5,1/5, true);
addKey(60,-105, -5,1/5, true);
addKey(90, 275,175,1/1);
break;
case 10:
addKey(0,-225,175,1/30);
addKey(30,-125,-5,1/30,true);
addKey(60,-25,175,1/30,true);
addKey(90,75,-5,1/30);
break;
case 11:
addKey(0,-225,225,  1/1);
addKey(20,15,-105,  1/6,true);
addKey(50,-205,-185,1/20,true);
addKey(90,415,225,1/1);
break;
case 12:
addKey(0,0,0,1/30);
addKey(50,0,125,1/1);
addKey(90,0,-325,1/1);
break;
case 13: // ドム 左
addKey(0,-140,0,1/30);
addKey(30,-140,30,1/20);
addKey(45,-70,-70,1/20,true);
addKey(60,0,30,1/20);
addKey(90,-140,30,1/20);
addKey(120,200,75,1/10);
addKey(135,150,-75,1/10,true);
addKey(150,100,75,1/10);
addKey(180,200,75,1/10);
addKey(210,-325,125,1/1);
break;
case 14: // ドム 右
addKey(0, 140,0,1/30);
addKey(30,140,30,1/20);
addKey(45, 70,-70,1/20,true);
addKey(60,   0,30,1/20);
addKey(90,140,30,1/20);
addKey(120,-200,75,1/10);
addKey(135,-150,-75,1/10,true);
addKey(150,-100,75,1/10);
addKey(180,-200,75,1/10);
addKey(210,325,125,1/1);
break;
case 15: // トモス 丸いやつ 上
addKey(0,    0,   0,1/30);
addKey(30,   0,- 80,1/9);
addKey(90,   0,- 80,1/9);
addKey(120,  0,-120,1/3);
addKey(180,  0,-120,1/3);
addKey(210,  0,-150,1/1);
addKey(240,  0,-150,1/1);
addKey(250,  0,   0,1/100);
break;
case 16: // トモス 丸いやつ 左
addKey(0,     0,   0,1/30);
addKey(30, - 65,  46,1/9);
addKey(90, - 65,  46,1/9);
addKey(120,- 98,  70,1/3);
addKey(180,- 98,  70,1/3);
addKey(210,-122,  87,1/1);
addKey(240,-122,  87,1/1);
addKey(250,   0,   0,1/100);
break;
case 17: // トモス 丸いやつ 右
addKey(0,    0,   0,1/30);
addKey(30,  65,  46,1/9);
addKey(90,  65,  46,1/9);
addKey(120, 98,  70,1/3);
addKey(180, 98,  70,1/3);
addKey(210,122,  87,1/1);
addKey(240,122,  87,1/1);
addKey(250,  0,   0,1/100);
break;
case 18: // ドム 赤いやつ
addKey(0,  -100,   0,1/30);

addKey(15, -100,  46,1/9);
addKey(22,    0, -46,1/9,true);
addKey(30,  100,  46,1/9);

addKey(45, -120,  60,1/3);
addKey(52,    0, -60,1/3,true);
addKey(60,  120,  60,1/3);

addKey(75, -130,  80,1/2);
addKey(82,    0, -80,1/2,true);
addKey(90,  130,  80,1/2);
addKey(105, -150, 150,  1);
break;

        default: mode = 1; init();
            break;
        }
    }
    private function fire():void {
        //log("fire");
    }
}