forked from: forked from: forked from: Slot Machine Rendering f.f.: 朝青龍ゲーム
リール回転+モーションブラー
-------------------------------------------------------------------
いきおいで作ってしまった。反省はしていない。
[inspired by]
昼青龍「朝青龍がやられたようだな・・・」:アルファルファモザイク
http://alfalfalfa.com/archives/384861.html
-------------------------------------------------------------------
[遊び方]
真ん中のボタンをクリックして朝青龍を完成させてください。
(完成しても何も起きませんが、気持ちいいと思います)
-------------------------------------------------------------------
[いじりどころ]
SLOT_TEXTの中身を変えるだけで自分だけのスロットマシーンを作れます。
-------------------------------------------------------------------
/**
* Copyright tommy ( http://wonderfl.net/user/tommy )
* MIT License ( http://www.opensource.org/licenses/mit-license.php )
* Downloaded from: http://wonderfl.net/c/a7j4
*/
// forked from tatzuya83's forked from: forked from: Slot Machine Rendering f.f.: 朝青龍ゲーム
// forked from tommy's forked from: Slot Machine Rendering f.f.: 朝青龍ゲーム
// forked from keim_at_Si's Slot Machine Rendering f.f.: 朝青龍ゲーム
// forked from o8que's 朝青龍ゲーム
// リール回転+モーションブラー
/* -------------------------------------------------------------------
* いきおいで作ってしまった。反省はしていない。
*
* [inspired by]
* 昼青龍「朝青龍がやられたようだな・・・」:アルファルファモザイク
* http://alfalfalfa.com/archives/384861.html
* -------------------------------------------------------------------
* [遊び方]
* 真ん中のボタンをクリックして朝青龍を完成させてください。
* (完成しても何も起きませんが、気持ちいいと思います)
* -------------------------------------------------------------------
* [いじりどころ]
* SLOT_TEXTの中身を変えるだけで自分だけのスロットマシーンを作れます。
* -------------------------------------------------------------------
*/
package {
import com.bit101.components.PushButton;
import flash.display.Sprite;
import flash.events.Event;
public class MorningBlueDragon extends Sprite {
public static const SLOT_NUM:int = 3;
public static const SLOT_SIZE:int = 140;
private static const SLOT_TEXT:Array =
[["朝", "昼", "夕", "夜"],
["青", "白", "朱", "玄"],
["龍", "虎", "雀", "武"]];
private var _slots:Array;
private var _stopped:int;
public function MorningBlueDragon() {
//This is all the initialization you need in your main class
inittrace(stage);
_slots = [];
for (var i:int = 0; i < SLOT_NUM; i++) {
var slot:Slot = new Slot((i * SLOT_SIZE) + 10, 10);
slot.setTextList(SLOT_TEXT[i]);
_slots.push(slot);
addChild(slot);
}
new PushButton(this, SLOT_SIZE + 30, SLOT_SIZE + 20, "click!", clickButton);
addEventListener(Event.ENTER_FRAME, update);
}
private function clickButton(e:Event):void {
if (_stopped == 3) for (var i:int=0; i<SLOT_NUM; i++) _slots[i].roll = true;
else _slots[_stopped].roll = false;
}
private function update(e:Event):void {
_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.*;
import flash.net.*;
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);
private var loader:Loader;
private var _texts:Array
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;
loader = new Loader();
var uRLRequest:URLRequest = new URLRequest("http://assets.wonderfl.net/images/related_images/b/b1/b1a6/b1a642c6afafa6148d3be3e2732c5627a9e490bb");
loader.load(uRLRequest);
loader.contentLoaderInfo.addEventListener(Event.COMPLETE,onComplete);
}
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));
//_list[i] = new BitmapData(_screen.width, _screen.height, true, 0);
//_list[i].draw(loader.content);
trace("draw end");
}
trace("loop end");
}
//ロードが終了後のイベント
private function onComplete(event:Event):void{
trace("complete");
} //onComplete
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;
}
}
// From http://wonderfl.net/c/hCok
///// WONDERFL TRACE /////
import flash.display.Sprite;
import flash.display.Stage;
import flash.text.TextField;
import flash.text.TextFormat;
function inittrace(s:Stage):void
{
WTrace.initTrace(s);
}
//global trace function
var trace:Function;
//wtreace class
class WTrace
{
private static var FONT:String = "Arial";
private static var SIZE:Number = 12;
private static var TextFields:Array = [];
private static var trace_stage:Stage;
public static function initTrace(stg:Stage):void
{
trace_stage = stg;
trace = wtrace;
}
private static function scrollup():void
{
// maximum number of lines: 100
if (TextFields.length > 100)
{
var removeme:TextField = TextFields.shift();
trace_stage.removeChild(removeme);
removeme = null;
}
for(var x:Number=0;x<TextFields.length;x++)
{
(TextFields[x] as TextField).y -= SIZE*1.2;
}
}
public static function wtrace(... args):void
{
var s:String="";
var tracefield:TextField;
for (var i:int;i < args.length;i++)
{
// imitating flash:
// putting a space between the parameters
if (i != 0) s+=" ";
s+=args[i].toString();
}
tracefield= new TextField();
tracefield.autoSize = "left";
tracefield.text = s;
tracefield.y = trace_stage.stageHeight - 20;
var tf:TextFormat = new TextFormat(FONT, SIZE);
tracefield.setTextFormat(tf);
trace_stage.addChild(tracefield);
scrollup();
TextFields.push(tracefield);
}
}