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

コリントゲーム

/**
 * Copyright kuma360 ( http://wonderfl.net/user/kuma360 )
 * MIT License ( http://www.opensource.org/licenses/mit-license.php )
 * Downloaded from: http://wonderfl.net/c/7X6w
 */

// forked from kuma360's コリントゲーム(演出皆無ver)
// forked from kuma360's スコアランキングのテスト
package
{
    import Box2D.Common.Math.b2Vec2;
    import com.actionsnippet.qbox.*;
    import flash.display.Bitmap;
    import flash.display.BitmapData;
    import flash.display.Graphics;
    import flash.display.MovieClip;
    import flash.display.Sprite;
    import flash.events.Event;
    import flash.events.MouseEvent;
    import flash.geom.Matrix;
    import flash.geom.Point;
    import flash.geom.Vector3D;
    import flash.text.TextField;
    
    import org.si.sion.*;
    import org.si.sion.utils.*;
    import org.si.sion.sequencer.SiMMLTrack;
    
    import com.bit101.components.Component;
    import com.bit101.components.PushButton;
    import net.wonderfl.score.basic.BasicScoreForm;
    import net.wonderfl.score.basic.BasicScoreRecordViewer;
    import net.wonderfl.utils.FontLoader;
    
    public class Main extends MovieClip
    {
        public function Main():void
        {
            /////////////////////
            Component.initStage ( stage ) ;    
            
            
            
            /////////////////////
            var SCORE:int = 0 ;
            var CHK:Boolean = true ;
            var DIRC:Boolean = false ;
            var Impact:Vector3D = new Vector3D ;
            
            
            /////////////////////
            var QB2:QuickBox2D = new QuickBox2D(this);
            var QC:QuickContacts;
            var BALL:QuickObject ;
            
            QB2.addCircle ( { x:14, y:2, radius:.5 , fillColor:0x505050 , density:0 , categoryBits:0x0002 , groupIndex:-1 } ) ;
            QB2.addBox ( { x:0 , y:7, width:1 , height:20 , density:0 } ) ;
            QB2.addBox ( { x:15.5, y:7, width:1 , height:20 , density:0 } ) ;
            QB2.addBox ( { x:7 , y:0, width:20, height:1 , density:0 } ) ;
            QB2.addCircle ( { x: 5 , y: 5 , radius:1 , density:0 } ) ;
            QB2.addCircle ( { x:10 , y: 5 , radius:1 , density:0 } ) ;
            QB2.addCircle ( { x: 5 , y:10 , radius:1 , density:0 } ) ;
            QB2.addCircle ( { x:10 , y:10 , radius:1 , density:0 } ) ;
            QB2.addCircle ( { x:2.5 , y:7.5 , radius:.5 , density:0 } ) ;
            QB2.addCircle ( { x:12.5, y:7.5 , radius:.5 , density:0 } ) ;
            QB2.addCircle ( { x:2.5 , y:12.5, radius:.5 , density:0 } ) ;
            QB2.addCircle ( { x:7.5 , y:12.5, radius:.5 , density:0 } ) ;
            QB2.addCircle ( { x:12.5, y:12.5, radius:.5 , density:0 } ) ;
            
            
            /////////////////////
            var _driver:SiONDriver = new SiONDriver();
            var _scale:Scale = new Scale("Cmp"); 
            var _preset:SiONPresetVoice = new SiONPresetVoice();
            var _voiceList:Array = [
                "valsound.piano9",
                "valsound.piano11",
                "midi.piano1",
                "midi.piano8"
            ];
            
            _driver.noteOnExceptionMode = SiONDriver.NEM_SHIFT;
            _driver.play ( null ) ;
            
            /////////////////////
            var S:Sprite = new Sprite ;
            addChild ( S ) ;
            
            
            /////////////////////
            var TF :TextField = new TextField ;
            TF.x = 20 ;
            TF.y = 20 ;
            TF.text = ""+SCORE ;
            addChild ( TF ) ;
            
            
            /////////////////////
            QC = QB2.addContactListener ( ) ;
            QC.addEventListener (
                QuickContacts.ADD ,
                function ( e:Event ) : void {
                    
                    var vel:Number = ( QC.currentPoint.velocity.LengthSquared ( ) - 3 ) ;
                    if ( vel > 0) {
                        
                        _driver.noteOn ( 
                            _scale.getNote ( ( int )( Math.random ( ) * 5 ) ) , 
                            _preset[ _voiceList[ Math.floor ( Math.random() * _voiceList.length ) ] ] , 
                            1, 
                            0, 
                            1
                        ) ;
                    
                        SCORE += vel ;
                        TF.text = "" + SCORE ;
                        
                        Impact.x = BALL.x * 30 ;
                        Impact.y = BALL.y * 30 ;
                        Impact.z = 30 ;
                        
                   }
                    
                }
            ) ;
            
            QB2.start ( ) ;
            
            
            stage.addEventListener (
                MouseEvent.MOUSE_DOWN ,
                function ( e:MouseEvent ) :void {
                    if ( CHK ) {
                        DIRC = true ;
                    }
                    
                }
            );
            
            /////////////////////
            stage.addEventListener (
                MouseEvent.MOUSE_UP ,
                function ( e:MouseEvent ) :void {
                    
                    DIRC = false ;
                    
                    if ( CHK ) {
                        
                        CHK = false ;
                        
                        BALL = QB2.addCircle ( { x:14, y:2, radius:.5 , lineThickness:8 , fillColor:0xFFA0A0 , restitution:1 , groupIndex:-1 } ) ;
                        var X:Number = mouseX - 14 * 30 ;
                        var Y:Number = mouseY - 2 * 30 ;
                        var L:Number = Math.sqrt ( X * X + Y * Y ) ;
                        if ( L ) { L = 1 / L * 30 ; }
                        BALL.body.SetLinearVelocity ( new b2Vec2 ( - X * L , - Y * L ) ) ;
                    }
                }
            ) ;
            
            /////////////////////
            addEventListener (
                Event.ENTER_FRAME ,
                function ( e:Event ) :void {

                    var G:Graphics = S.graphics ;
                    G.clear ( ) ;
                    
                    if ( DIRC ) {
                        G.lineStyle ( 1 , 0xFF0000 , .5 ) ;
                        G.moveTo ( mouseX , mouseY ) ;
                        G.lineTo ( 14 * 30 , 2 * 30 ) ;
                    }
                    
                    if ( 0 < -- Impact.z ) {
                        G.beginFill ( 0xFF0000 , .5 ) ;
                        G.drawCircle ( Impact.x , Impact.y , Impact.z ) ;
                        G.endFill ( ) ;
                    }
                    
                    
                    if ( BALL && 20 < BALL.y ) {
                        
                        BALL.destroy ( ) ;
                        BALL = null;
                        
                        var FORM:BasicScoreForm = new BasicScoreForm (
                            stage,
                            100,
                            100,
                            SCORE ,
                            "SAVE SCORE" ,
                            function ( $didSavedScore:Boolean ) :void {
                                stage.removeChild ( FORM ) ;
                                var FORM2:BasicScoreRecordViewer = new BasicScoreRecordViewer (
                                    stage,
                                    100,
                                    100 ,
                                    "RANKING" ,
                                    20 ,
                                    true ,
                                    function ( ) :void {
                                        stage.removeChild ( FORM2 ) ;
                                        CHK = true ;
                                        SCORE = 0 ;
                                    }
                                ) ;
                            }
                        );
                        
                    }
                    
                }
            ) ;
            
        }
    }
    
}