forked from: コリントゲーム

by ohisama forked from コリントゲーム (diff: 128)
♥0 | Line 137 | Modified 2013-03-04 08:19:10 | MIT License
play

ActionScript3 source code

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

// forked from kuma360's コリントゲーム
// 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, {gravityY : 1});            
            var QC : QuickContacts;
            var BALL : QuickObject ;
            //QB2.addCircle({x : 14, y : 2, radius : 0.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 : 0.5 , density : 0});
            QB2.addCircle({x : 12.5, y : 7.5 , radius : 0.5 , density : 0});
            QB2.addCircle({x : 2.5, y : 12.5, radius : 0.5 , density : 0});
            QB2.addCircle({x : 7.5, y : 12.5, radius : 0.5 , density : 0});
            QB2.addCircle({x : 12.5, y : 12.5, radius : 0.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 + " ten";
            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 + " ten";
                    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 : 0.5, lineThickness : 6, fillColor : 0xFFf030, 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 = L / -20; 
                    }
                    BALL.body.SetLinearVelocity(new b2Vec2(L, Y / X * L - 1.0));
                }
            });
            addEventListener(Event.ENTER_FRAME, function(e : Event) : void 
            {
                var G : Graphics = S.graphics;
                G.clear();
                if (DIRC) 
                {
                    G.lineStyle(1, 0xFF0000, 0.5);
                    G.moveTo(mouseX , mouseY);
                    G.lineTo(14 * 30 , 2 * 30);
                }
                if (0 < -- Impact.z) 
                {
                    G.beginFill(0xFF0000, 0.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;
                        });
                    });
                }
            });
        }
    }
}