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: Slot Machine Rendering f.f.: 朝青龍ゲーム

クリックとキーでそろう。
ブラー追加。
リールが独立している。
/**
 * Copyright dannnn ( http://wonderfl.net/user/dannnn )
 * MIT License ( http://www.opensource.org/licenses/mit-license.php )
 * Downloaded from: http://wonderfl.net/c/fONr
 */

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

// forked from dannnn's forked from: forked from: forked from: 朝青龍ゲーム
// forked from takaHanada's forked from: forked from: 朝青龍ゲーム
// forked from takaHanada's forked from: 朝青龍ゲーム
// forked from o8que's 朝青龍ゲーム
// リール回転+モーションブラー
/* -------------------------------------------------------------------
 * いきおいで作ってしまった。反省はしていない。
 * 
 * [inspired by]
 * 昼青龍「朝青龍がやられたようだな・・・」:アルファルファモザイク
 * http://alfalfalfa.com/archives/384861.html
 * 簡単にそろうようにした@貴花田
 * -------------------------------------------------------------------
 * [遊び方]
 * 真ん中のボタンをクリックして朝青龍を完成させてください。
 * (完成しても何も起きませんが、気持ちいいと思います)
 * -------------------------------------------------------------------
 * [いじりどころ]
 * SLOT_TEXTの中身を変えるだけで自分だけのスロットマシーンを作れます。
 * -------------------------------------------------------------------
 */
package {
    import flash.events.KeyboardEvent;
    import com.bit101.components.PushButton;
    import flash.display.Sprite;
    import flash.events.Event;
    
    public class MorningBlueDragon extends Sprite {
        public static const SLOT_NUM:int = 9;
        public static const SLOT_LEFT0:int = 0;
        public static const SLOT_LEFT1:int = 3;
        public static const SLOT_LEFT2:int = 6;
        public static const SLOT_MIDDLE0:int = 1;
        public static const SLOT_MIDDLE1:int = 4;
        public static const SLOT_MIDDLE2:int = 7;
        public static const SLOT_RIGHT0:int = 2;
        public static const SLOT_RIGHT1:int = 5;
        public static const SLOT_RIGHT2:int = 8;
        public static const SLOT_SIZE:int = 140;
        private static const SLOT_TEXT:Array = 
        [["replay", "cherry", "bell", "watermelon", "bar", "b7", "r7"],
         ["replay", "cherry", "bell", "watermelon", "bar", "b7", "r7"],
         ["replay", "cherry", "bell", "watermelon", "bar", "b7", "r7"],
         ["replay", "cherry", "bell", "watermelon", "bar", "b7", "r7"],
         ["replay", "cherry", "bell", "watermelon", "bar", "b7", "r7"],
         ["replay", "cherry", "bell", "watermelon", "bar", "b7", "r7"],
         ["replay", "cherry", "bell", "watermelon", "bar", "b7", "r7"],
         ["replay", "cherry", "bell", "watermelon", "bar", "b7", "r7"],
         ["replay", "cherry", "bell", "watermelon", "bar", "b7", "r7"]];
        private var _slots:Array;
        private var _stopped:int;

        public function MorningBlueDragon() {
            _slots = [];
            for (var i:int = 0; i < SLOT_NUM; i++) {
                var slot:Slot = new Slot((i % 3) * SLOT_SIZE + 10, Math.floor(i / 3) * SLOT_SIZE + 10);
                slot.setTextList(SLOT_TEXT[i]);
                _slots.push(slot);
                addChild(slot);
            }
            new PushButton(this, SLOT_SIZE + 30, SLOT_SIZE*3 + 20, "click!", clickButton);
            addEventListener(KeyboardEvent.KEY_DOWN, stop);
            addEventListener(Event.ENTER_FRAME, update);
        }
        
        private function clickButton(e:Event):void {
            var i:int;
            for (i = 0; i < SLOT_NUM; i++) {
                if (_slots[i].roll) {
                    _slots[i].roll = false;
                    break;
                }
            }
            if (i == SLOT_NUM) {
                for (var j:int = 0; j < SLOT_NUM; j++) {
                    _slots[j].roll = true;
                }
            }
        }
        
        private function stop(event:KeyboardEvent):void 
        {
            if (event.keyCode == 81)    // 'q'
            {
                _slots[SLOT_LEFT0].roll = false;
                trace("leftq");
            }
            if(event.keyCode == 65)    // 'a'
            {
                _slots[SLOT_LEFT1].roll = false;
                trace("lefta");
            }
            if(event.keyCode == 90)    // 'z'
            {
                _slots[SLOT_LEFT2].roll = false;
                trace("leftz");
            }
            if(event.keyCode == 87)    // 'w'
            {
                _slots[SLOT_MIDDLE0].roll = false;
                trace("middlew");
            }
            if(event.keyCode == 83)    // 's'
            {
                _slots[SLOT_MIDDLE1].roll = false;
                trace("middles");
            }
            if(event.keyCode == 88)    // 'x'
            {
                _slots[SLOT_MIDDLE2].roll = false;
                trace("middlex");
            }
            if(event.keyCode == 69)    // 'e'
            {
                _slots[SLOT_RIGHT0].roll = false;
                trace("righte");
            }
            if(event.keyCode == 68)    // 'd'
            {
                _slots[SLOT_RIGHT1].roll = false;
                trace("rightd");
            }
            if(event.keyCode == 67)    // 'c'
            {
                _slots[SLOT_RIGHT2].roll = false;
                trace("rightc");
            }
            if (event.keyCode == 82)    //'r'
            {
                if (_slots[SLOT_LEFT0].roll || _slots[SLOT_MIDDLE0].roll || _slots[SLOT_RIGHT0].roll) {
                    _slots[SLOT_LEFT0].roll = false;
                    _slots[SLOT_MIDDLE0].roll = false;
                    _slots[SLOT_RIGHT0].roll = false;
                }
                trace("rowr");
            }
            if (event.keyCode == 82)    //'r'
            {
                if (_slots[SLOT_LEFT0].roll || _slots[SLOT_MIDDLE0].roll || _slots[SLOT_RIGHT0].roll) {
                    _slots[SLOT_LEFT0].roll = false;
                    _slots[SLOT_MIDDLE0].roll = false;
                    _slots[SLOT_RIGHT0].roll = false;
                }
                trace("rowr");
            }
            if (event.keyCode == 70)    //'f'
            {
                if (_slots[SLOT_LEFT1].roll || _slots[SLOT_MIDDLE1].roll || _slots[SLOT_RIGHT1].roll) {
                    _slots[SLOT_LEFT1].roll = false;
                    _slots[SLOT_MIDDLE1].roll = false;
                    _slots[SLOT_RIGHT1].roll = false;
                }
                trace("rowf");
            }
            if (event.keyCode == 86)    //'v'
            {
                if (_slots[SLOT_LEFT2].roll || _slots[SLOT_MIDDLE2].roll || _slots[SLOT_RIGHT2].roll) {
                    _slots[SLOT_LEFT2].roll = false;
                    _slots[SLOT_MIDDLE2].roll = false;
                    _slots[SLOT_RIGHT2].roll = false;
                }
                trace("rowv");
            }
            if (event.keyCode == 37 /*|| event.keyCode == 65*/)//left or 'a'
            {
                if (_slots[SLOT_LEFT0].roll || _slots[SLOT_LEFT1].roll || _slots[SLOT_LEFT2].roll) {
                    _slots[SLOT_LEFT0].roll = false;
                    _slots[SLOT_LEFT1].roll = false;
                    _slots[SLOT_LEFT2].roll = false;
                }
                trace("left");
            }
            if (event.keyCode == 40 /*|| event.keyCode == 83*/)//down or 's'        
            {
                if (_slots[SLOT_MIDDLE0].roll||_slots[SLOT_MIDDLE1].roll||_slots[SLOT_MIDDLE2].roll) {
                    _slots[SLOT_MIDDLE0].roll = false;
                    _slots[SLOT_MIDDLE1].roll = false;
                    _slots[SLOT_MIDDLE2].roll = false;
                }
                trace("middle");
            }
            if (event.keyCode == 39 /*|| event.keyCode == 68*/)//right or 'd'
            {
                if (_slots[SLOT_RIGHT0].roll||_slots[SLOT_RIGHT1].roll||_slots[SLOT_RIGHT2].roll) {
                    _slots[SLOT_RIGHT0].roll = false;
                    _slots[SLOT_RIGHT1].roll = false;
                    _slots[SLOT_RIGHT2].roll = false;
                }
                trace("right");
            }
        }
        
        private function update(e:Event):void {
             /*for (var i:int = 0; i < SLOT_NUM; i++) {
                if (_slots[i].roll) {
                    _slots[i].setTextList(SLOT_TEXT[i][Math.floor(SLOT_TEXT[i].length * Math.random())]);
                }*/
            _stopped = 0;
            for (var i:int=0; i<SLOT_NUM; i++) _stopped += _slots[i].update();
        }
    }
}

import flash.display.*;
import flash.filters.*;
import flash.events.*;
import flash.geom.*;
import flash.text.*;

class Slot extends Sprite {
    public var roll:Boolean;
    private var _list:Vector.<BitmapData> = new Vector.<BitmapData>();
    private var _screen:BitmapData;
    private var _index:Number, _vel:Number;
    private var _pt:Point = new Point(0, 0);
    private var _blur:BlurFilter = new BlurFilter(1, 16);
    
    public function Slot(posx:int, posy:int) {
        var size:int = MorningBlueDragon.SLOT_SIZE;
        x = posx;
        y = posy;
        buttonMode = true;
        graphics.lineStyle(2, 0x808080);
        graphics.drawRect(0,0,size,size);
        addChild(new Bitmap(_screen = new BitmapData(size, size, false, 0xffffff)));
        addEventListener("click", function(e:Event) : void { roll = false; } );
        _index = 0;
        _vel = 0;
        roll =    false;
    }
    
    public function setTextList(texts:Array):void {
        var tf:TextField = new TextField();
        tf.defaultTextFormat = new TextFormat(null, _screen.width);
        tf.width = tf.height = _screen.width;
        _list.length = texts.length;
        for (var i:int=0; i<texts.length; i++) {
            tf.text = texts[i];
            _list[i] = new BitmapData(_screen.width, _screen.height, true, 0);
            _list[i].draw(tf, null, new ColorTransform(1,1,1,0.4,(i==0)?255:0));
        }
    }
    
    public function update() : int {
        var i0:int, i1:int, i:int;
        _screen.fillRect(_screen.rect, 0xffffff);
        for (i=0; i<6; i++) {
            i0 = int(_index);
            i1 = (i0+1) % _list.length;
            _pt.y = (_index - i0) * _screen.height;
            _screen.copyPixels(_list[i0], _screen.rect, _pt);
            _pt.y -= _screen.height;
            _screen.copyPixels(_list[i1], _screen.rect, _pt);
            _index += _vel;
            if (_index >= _list.length) _index -= _list.length;
            _vel += (roll) ? 0.001 : -0.01;
            if (_vel > 0.05) _vel = 0.05;
            else if (_vel < 0) {
                _vel = 0;
                _index = int(_index+0.5) % _list.length;
            }
        }
        if (_vel > 0.03) _screen.applyFilter(_screen, _screen.rect, _screen.rect.topLeft, _blur);
        return (roll) ? 0 : 1;
    }
}