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

Crane Game with scores - forked from: forked from: forked from: flash on 2010-5-16

Crane Game with scores and some improvements

(scores work now)

forked from kkstudio2007's forked from: forked from: flash on 2010-5-16
forked from dec's forked from: flash on 2010-5-16
forked from dec's flash on 2010-5-16
Get Adobe Flash player
by Glav 21 Feb 2011
// dec's game with scores and some improvements
//
// forked from kkstudio2007's forked from: forked from: flash on 2010-5-16
// forked from dec's forked from: flash on 2010-5-16
// forked from dec's flash on 2010-5-16
package {
    import flash.display.*;
    import flash.events.*;
    import com.actionsnippet.qbox.*;
    import Box2D.Dynamics.Joints.*;
    import Box2D.Common.Math.b2Vec2;
    import flash.text.TextField;
    import net.wonderfl.utils.WonderflAPI;
    
    public class FlashTest extends MovieClip {
        public var ITEMS:Number=10;
        
        public var mouseClicked:Boolean=false;
        public var middle:QuickObject;
        public var lJoint:QuickObject;
        public var rJoint:QuickObject;
        public var dropArea:QuickObject;
        public var contacts:QuickContacts;
        public var prizes:Array=[];
        public var horizSpeed:Number=0, vertSpeed:Number=0;
        
        public var m_Score:int = 10000;
        public var m_ScoreText:TextField = new TextField();
        
        public var IsEnd:Boolean = false;
        
        public function FlashTest() {
            ScoreWindowLoader.init(this, new WonderflAPI(loaderInfo.parameters));
            
            m_ScoreText.selectable = false;
            m_ScoreText.text = 'Score: ' + m_Score.toString();
            addChild(m_ScoreText);
            m_ScoreText.x = 15;
            m_ScoreText.y = 12;
            
            var sim:QuickBox2D=new QuickBox2D(this);
            sim.setDefault({fillColor:0xff00000});
            sim.createStageWalls();
            sim.addBox({x:13.6,y:0,width:.2,height:3.5,density:0});
            sim.addBox({x:14.83,y:2.94,width:.2,height:3.5,angle:-45*(Math.PI/180),density:0});
            sim.addBox({x:11.5,y:13,width:.2,height:10,density:0});
            dropArea=sim.addBox({x:13.3,y:15,width:3.3,height:.3,fillColor:0xFFFF00,draggable:false});
            
            sim.setDefault({fillColor:0x00FFFF});
            
            for(var b:int=0;b<ITEMS;b++){
                    if(b%2==0){
                        prizes[b]=sim.addCircle({x:4,y:3,radius:1,draggable:false});
                    }
                    else{
                        prizes[b]=sim.addBox({x:4,y:2,width:1.5,height:1.5,draggable:false});
                    }
            }
            
            middle=sim.addBox({x:10.55,y:4,width:1,height:1,density:10,fixedRotation:true,draggable:false});
            var lClaw:QuickObject=sim.addPoly({x:10,y:5,points:[0,0 , -1,1 , 0,2 , -0.5,1 , 0.5,.05],wireframe:false,draggable:false});
            var rClaw:QuickObject=sim.addPoly({x:11.1,y:5,points:[0,0 , 1,1 , 0,2 , .5,1 , -0.5,.05],wireframe:false,draggable:false});
            
            lJoint=sim.addJoint({type:"revolute",a:lClaw.body,b:middle.body,x1:lClaw.x,y1:lClaw.y,x2:middle.x-1,y2:middle.y-1,enableMotor:true,maxMotorTorque:250,enableLimit:true,lowerAngle:-45*(Math.PI/180),upperAngle:13*(Math.PI/180)});
            rJoint=sim.addJoint({type:"revolute",a:rClaw.body,b:middle.body,x1:rClaw.x,y1:rClaw.y,x2:middle.x+1,y2:middle.y-1,enableMotor:true,maxMotorTorque:250,enableLimit:true,lowerAngle:-13*(Math.PI/180),upperAngle:45*(Math.PI/180)});
            
            contacts=sim.addContactListener();
            contacts.addEventListener(QuickContacts.ADD,onAdd);
            sim.start();
            sim.mouseDrag();
            
            stage.addEventListener(MouseEvent.MOUSE_UP, function(event:MouseEvent):void{mouseClicked=false});
            stage.addEventListener(MouseEvent.MOUSE_DOWN,function(event:MouseEvent):void{mouseClicked=true});
            stage.addEventListener(Event.ENTER_FRAME,loop1);
        }
        private function loop1(event:Event):void{
                var speed:Number=5;
                var j:b2RevoluteJoint=lJoint.joint as b2RevoluteJoint;
                if(mouseClicked){
                    vertSpeed=5;
                    j.SetMotorSpeed(-speed);
                    j=rJoint.joint as b2RevoluteJoint;
                    j.SetMotorSpeed(speed);
                } else{
                  vertSpeed=-3;
                    j.SetMotorSpeed(speed);
                    j=rJoint.joint as b2RevoluteJoint;
                    j.SetMotorSpeed(-speed);
              }
              
              if(mouseX>middle.x*30 + 10){
                  horizSpeed=7;
              }
              else if(mouseX<middle.x*30 -10){
                  horizSpeed=-7;
              }
              else{
                  horizSpeed=0;
              }
              middle.body.SetLinearVelocity(new b2Vec2(horizSpeed,vertSpeed));
              middle.body.SetAngularVelocity(0);
              
              computeScore();
        }
        private function onAdd(event:Event):void{
            for(var i:int=0;i<prizes.length;i++){
                var prize:QuickObject=prizes[i];
                if(contacts.isCurrentContact(prize,dropArea)){
                    prize.destroy();
                    ITEMS--;
                    if (ITEMS == 0) {
                        IsEnd = true;
                        ScoreWindowLoader.show(m_Score);
                    }
                }
            }
        }
        private function computeScore():void {
            if(!IsEnd){
                if(m_Score > 0){m_Score--;}
                m_ScoreText.text = 'score : ';
                m_ScoreText.appendText(m_Score.toString());
            }
        }
    }
}


import flash.display.DisplayObject;
import flash.display.DisplayObjectContainer;
import flash.events.*;
import flash.display.Loader;
import flash.net.URLRequest;
import flash.system.LoaderContext;
import net.wonderfl.utils.WonderflAPI;

class ScoreWindowLoader {
    private static var _top: DisplayObjectContainer;
    private static var _api: WonderflAPI;
    private static var _content: Object;
    private static const URL: String = "http://swf.wonderfl.net/swf/usercode/5/57/579a/579a46e1306b5770d429a3738349291f05fec4f3.swf";
    private static const TITLE: String = "Crane Game";
    private static const TWEET: String = "Crane Game - Score: %SCORE% #wonderfl";

    //初期化
    public static function init(top: DisplayObjectContainer, api: WonderflAPI): void {
        _top = top, _api = api;
        var loader: Loader = new Loader();
        var comp: Function = function(e: Event): void {
            loader.contentLoaderInfo.removeEventListener(Event.COMPLETE, comp);
            _content = loader.content;
        }
        loader.contentLoaderInfo.addEventListener(Event.COMPLETE, comp);
        loader.load(new URLRequest(URL), new LoaderContext(true));
    }

    //表示
    public static function show( score: int): void {
        var window: DisplayObject = _content.makeScoreWindow(_api, score, TITLE, 1, TWEET);
        _top.addChild(window);
    }
    
}