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

flash on 2010-6-9

2010/6/9 ヘリコプターシューティングゲーム作る
Get Adobe Flash player
by shohei909 26 Jun 2010
    Embed
/**
 * Copyright shohei909 ( http://wonderfl.net/user/shohei909 )
 * MIT License ( http://www.opensource.org/licenses/mit-license.php )
 * Downloaded from: http://wonderfl.net/c/hfob
 */

//2010/6/9 ヘリコプターシューティングゲーム作る
package {
    import flash.display.Sprite;
    public class Flash extends Sprite {
        public function Flash() {
            // write as3 code here..
            var battle:Battle = new Battle();
            addChild( battle.view );
        }
    }
}
import flash.display.*;
import flash.events.*;
import flash.filters.*;
import flash.geom.*;

class View extends Bitmap{
    static public var swfWidth:int = 465;
    static public var swfHeight:int = 465;
    
    public var battle:Battle;

    public function View(b:Battle){
        battle = b;
        super(new BitmapData(swfWidth,swfHeight,false,0xEEEEEE) );
    }
    public function drow():void{
        bitmapData.applyFilter(bitmapData,new Rectangle(0,0,swfWidth,swfHeight), new Point(0, 0), new     BlurFilter(3,3,1) );    
        var cut:BitmapData = new BitmapData(swfWidth,swfHeight,false,0xEEEEEE);
        
        
        var sc:Number = swfHeight/(battle.dia+220);
        var cx:Number = (-battle.centerX*sc + swfHeight/2) ;
        var cy:Number = (-battle.centerY*sc + swfHeight/2);
                
        
        
        
        bitmapData.draw(battle,
                        new Matrix(sc, 0,
                                 0, sc,
                                 cx, cy),
                         null,
                         BlendMode.MULTIPLY
        );
        
        
        var mult:uint = 0x30; 
        bitmapData.merge(cut, new Rectangle(0,0,swfWidth,swfHeight), new Point(0, 0),mult,mult,mult,mult);
    }
    
}


class Battle extends Sprite{
    public var fieldWidth:int = 930;
    public var fieldHeight:int = 930;
    public var speed:int = 10;//バトルの速度
    
    
    public var back:Back = new Back;
    public var ship1:Ship;
    public var ship2:Ship;

    public var view:View;
    
    public var dia:Number = 0;
    public var centerX:Number;
    public var centerY:Number;
    
    
    public function Battle(){
        back.scaleX=4;
        back.scaleY=4;
        addChild(back);
        
        ship1 = new Ship(this);
        ship1.x = fieldWidth / 2;
        ship1.y = 200;
        ship1.vx = 10;
        ship1.vy = 8;
        ship1.rotation = 180;
        addChild(ship1);
        
        
        ship2 = new Ship(this);
        ship2.x = fieldWidth / 2;
        ship2.y = fieldWidth - 200;
        ship2.vx = -10;
        ship2.vy = -8;
        addChild(ship2);
        
        view = new View(this);
            
        with(this.graphics){
            beginFill (0xFFFFFF, 1.0);
            drawRect  ( -fieldWidth, -fieldHeight , 2*fieldWidth , 2*fieldHeight );
        }
        
        addEventListener( "enterFrame", onFrame );
    }
    
    
    public function onFrame(e:Event):void{
        var sx:int = ship1.x - ship2.x;
        var sy:int = ship1.y - ship2.y;
        
        var pt:Point = new Point(sx, sy);
        dia = pt.length;
        centerX = ship2.x + sx/2;
        centerY = ship2.y + sy/2;
        
        
        
        
        var d:int = 180 * Math.atan2(sx, sy) / Math.PI;
        
        
        ship1.d = - d;
        ship2.d = 180 - d;
        ship1.move();
        ship2.move();
        view.drow();
    }
}


//ヘリ
class Ship extends Sprite{
    public var vx:Number = 0;
    public var vy:Number = 0;
    public var d:int = 0;    //相手のヘリコプターの方向(ラジアン)
    public var battle:Battle;
    
    public var wing1:Sprite = new Sprite();
    public var interval:int; 
    

    
    public function Ship(b:Battle){
        battle = b;
        drow();
    }
    
    public function move():void{
        x += vx;    
        y += vy;
        vx *= 0.97;
        vy *= 0.97;
        
        
        rotation = d;
        
        
        wing1.rotation += 39;    
        interval = battle.speed * 10;
    }
    
    
    private function drow():void{
        with(this.graphics){
            beginFill (0x999999, 1.0);
            drawRoundRect  ( -10, -20 , 20 , 40 , 18 , 18);
            drawRect  ( -3, 20 , 6 , 20 );
            drawRect  ( -6, 40 , 12 , 7 );
        }
        with(wing1){
            graphics.beginFill (0x999999, 1.0);
            graphics.drawRoundRect  ( -40, -3 , 80 , 6 , 3 , 3);
        }
        addChild(wing1);
    }    
    
    protected function accel( d:int ):void{
    }
}

class ManShip extends Ship{
    public function ManShip(b:Battle){
        addEventListener("keyDown" ,onDown);
        super(b);
    }
    public function onDown(e:Event):void{
        
    }
}
    
class Back extends Sprite{
    public function Back(){
    }
}