止めてみやがれ!(Stop the Slot Machine)
コインが続く限り思わず押し続けたくなるボタンといえば、スロットマシーンではないでしょうか。
ただ、このスロットマシーンは数字が揃っても何も賞品は出ませんので悪しからず。
あっそれから、このスロットマシーンは時々爆・・・
/**
* Copyright mousepancyo ( http://wonderfl.net/user/mousepancyo )
* MIT License ( http://www.opensource.org/licenses/mit-license.php )
* Downloaded from: http://wonderfl.net/c/pF63
*/
// forked from Event's Button
package {
import flash.display.Sprite;
import flash.display.StageScaleMode;
import flash.display.StageAlign;
import flash.display.BitmapData;
import flash.display.Bitmap;
import flash.events.Event;
import flash.events.TimerEvent;
import flash.events.MouseEvent;
import flash.utils.Timer;
import flash.geom.Point;
import flash.geom.Rectangle;
import flash.text.TextField;
import flash.text.TextFormat
[SWF(width=465, height=465, backgroundColor=0, frameRate=30)]
public class Main extends Sprite {
private const W:int = 465;
private const H:int = 465;
private var _timer:Timer;
private var _container:Sprite;
private var _sec:int;
private var _sPanelListRL:Vector.<TimePanel> = new Vector.<TimePanel>();
private var _xListL:Vector.<Number> = new Vector.<Number>();
private var _yListL:Vector.<Number> = new Vector.<Number>();
private var _zListL:Vector.<Number> = new Vector.<Number>();
private var _sizeListL:Vector.<Number> = new Vector.<Number>();
private var _sPanelListRC:Vector.<TimePanel> = new Vector.<TimePanel>();
private var _xListC:Vector.<Number> = new Vector.<Number>();
private var _yListC:Vector.<Number> = new Vector.<Number>();
private var _zListC:Vector.<Number> = new Vector.<Number>();
private var _sizeListC:Vector.<Number> = new Vector.<Number>();
private var _sPanelList:Vector.<TimePanel> = new Vector.<TimePanel>();
private var _xListR:Vector.<Number> = new Vector.<Number>();
private var _yListR:Vector.<Number> = new Vector.<Number>();
private var _zListR:Vector.<Number> = new Vector.<Number>();
private var _sizeListR:Vector.<Number> = new Vector.<Number>();
private var _offsetL:int = -150;
private var _offsetC:int = 0;
private var _offsetR:int = 150;
private var _rad: Number = 250;
private var _grovalZ: Number = 150;
private var _centerZ: Number = 380;
private var _countL:Number = 0
private var _countC:Number = 0
private var _countR:Number = 0
private var _isLeft:Boolean = true;
private var _isCenter:Boolean = true;
private var _isRight:Boolean = true;
private var _isSlottle:Boolean;
private var _numL:int;
private var _numC:int;
private var _numR:int;
private var _clickCount:int;
private var _limit:int
private var bt0:Btn;
private var bt1:Btn;
private var bt2:Btn;
private var _fmt:TextFormat = new TextFormat("_typewriter", 14, 0xFFFFFF, true, false, false, null, null, "center", null, null, null, 2);
private var msg:TextField = new TextField();
private var _particleList:Vector.<Particle> = new Vector.<Particle>;
public function Main() {
graphics.beginFill(0)
graphics.drawRect(0, 0, W, H)
graphics.endFill()
//
initView();
//
for(var i:int=0; i<3; i++){
this["bt"+i] = new Btn(40);
this["bt"+i].x = W/4 * (i+1);
this["bt"+i].y = 410;
addChild(this["bt"+i]);
}
btnActive();
//
msg.defaultTextFormat = _fmt;
msg.width = W;
msg.y = 10;
msg.selectable = false;
msg.visible = false;
addChild(msg);
}
private function initView():void {
stage.align = StageAlign.TOP_LEFT;
stage.scaleMode = StageScaleMode.NO_SCALE;
//
_container = new Sprite();
_container.x = W * .5;
_container.y = H * .45;
addChild(_container);
_container.visible = false;
//
createSlot(_sPanelListRL, _xListL, _yListL, _zListL, _sizeListL, 10, _offsetL);
createSlot(_sPanelListRC, _xListC, _yListC, _zListC, _sizeListC, 10, _offsetC);
createSlot(_sPanelList, _xListR, _yListR, _zListR, _sizeListR, 10, _offsetR);
//
_limit = Math.random() * 10 + 5;
slottleStart();
}
private function slottleStart():void{
_timer = new Timer(33);
_timer.addEventListener(TimerEvent.TIMER, onTimer);
_timer.start();
_isSlottle = true;
}
private function onTimer(e:TimerEvent):void {
var time:Date = new Date;
var hour:int = time.getHours();
var min:int = time.getMinutes();
var sec:int = time.getSeconds();
var nx:Number = 0;
var ny:Number = 0;
var ns:Number = 0;
//
_container.visible = true;
//
if(!_isLeft && _countL == (_countL|0)){
_numL = checkNumber(_countL);
}else{
updateSlot(_sPanelListRL, _xListL, _yListL, _zListL, _sizeListL, 10, _countL);
_countL += 0.25;
if(_countL >= 10){
_countL = 0;
}
}
//
if(!_isCenter && _countC == (_countC|0)){
_numC = checkNumber(_countC);
}else{
updateSlot(_sPanelListRC, _xListC, _yListC, _zListC, _sizeListC, 10, _countC)
_countC += 0.25;
if(_countC >= 10){
_countC = 0;
}
}
//
if(!_isRight && _countR == (_countR|0)){
_numR = checkNumber(_countR);
stop_or_restart();
}else{
updateSlot(_sPanelList, _xListR, _yListR, _zListR, _sizeListR, 10, _countR)
_countR += 0.25;
if(_countR >= 10){
_countR = 0;
}
}
//
function stop_or_restart():void{
if(_clickCount > _limit){
_timer.stop();
_isSlottle = false;
msg.visible = true;
msg.text = "Oh No!\nClick to challenge the stage again.";
stage.addEventListener(MouseEvent.CLICK, restart);
createPeace();
}else{
if(_numL == _numC && _numC == _numR){
_timer.stop();
_isSlottle = false;
msg.visible = true;
msg.text = "Good Job!\nClick to challenge the stage again.";
stage.addEventListener(MouseEvent.CLICK, restart)
}else{
if(!_isLeft && !_isCenter && !_isRight){
_isRight = _isCenter = _isLeft = true;
_numL = _numC = _numR = 0;
btnActive();
}
}
}
}
}
private function btnActive():void{
for(var i:int=0; i<3; i++){
this["bt"+i].visible = true;
this["bt"+i].addEventListener(MouseEvent.CLICK, btnClick);
this["bt"+i].knockout = false;
}
}
private function checkNumber(num:Number):int{
var n:int;
if((num|0) == 0){
n = 9;
}else{
n = (num|0)-1
}
return n;
}
private function btnClick(e:MouseEvent):void{
switch(e.target as Btn){
case bt0:
_isLeft = false;
bt0.knockout = true;
bt0.removeEventListener(MouseEvent.CLICK, btnClick);
break;
case bt1:
_isCenter = false;
bt1.knockout = true;
bt1.removeEventListener(MouseEvent.CLICK, btnClick);
break;
case bt2:
_isRight = false;
bt2.knockout = true;
bt2.removeEventListener(MouseEvent.CLICK, btnClick);
break;
}
_clickCount++
}
private function restart(e:MouseEvent):void{
stage.removeEventListener(MouseEvent.CLICK, restart)
_timer.start();
_isSlottle = _isRight = _isCenter = _isLeft = true;
_clickCount = 0;
_limit = Math.random() * 10 + 5;
msg.visible = false;
//
btnActive();
}
//created clock init view
private function createSlot(panelList:Vector.<TimePanel>, xList:Vector.<Number>, yList:Vector.<Number>, zList:Vector.<Number>, sizeList:Vector.<Number>, count:int, offset:int):void{
for(var i:Number = 0; i < count; i++){
panelList.push(new TimePanel());
panelList[panelList.length-1].tx.numStr = i.toString();
_container.addChild(panelList[panelList.length-1]);
xList.push(offset);
yList.push(0);
zList.push(0);
sizeList.push(1);
}
}
//update clock view
private function updateSlot(panelList:Vector.<TimePanel>, xList:Vector.<Number>, yList:Vector.<Number>, zList:Vector.<Number>, sizeList:Vector.<Number>, count:int, time:int):void{
for(var i:Number = 0; i < count; i++){
var angle:Number = (time/count * Math.PI * 2 - i/count * Math.PI * 2);
var py:Number = _rad*Math.sin(angle);
var pz:Number = _centerZ - _rad*Math.cos(angle);
yList[i] += (py - yList[i])/2;
zList[i] += (pz - zList[i])/2;
if(i == time){
sizeList[i] += (4 - sizeList[i])/2;
}else{
sizeList[i] += (1 - sizeList[i])/2;
}
panelList[i].x = xList[i] * _grovalZ/zList[i];
panelList[i].y = yList[i] * _grovalZ/zList[i];
panelList[i].scaleX = sizeList[i] * _grovalZ/zList[i];
panelList[i].scaleY = sizeList[i] * _grovalZ/zList[i];
}
}
//Perticle
private function createPeace():void{
var image:BitmapData = new BitmapData(W, H, true, 0);
image.draw(stage);
//
for(var i:int=0; i<93; i++){
for(var j:int=0; j<93; j++){
var bmd:BitmapData = new BitmapData(5, 5, true);
bmd.copyPixels(image, new Rectangle(j*5, i*5, 5, 5), new Point(0, 0));
//
var bm:Particle = new Particle(bmd);
var radius:Number = Math.sqrt(Math.random())*10;
var angle:Number = Math.random() * (Math.PI)*2;
bm.x = j * 5;
bm.y = i * 5;
bm.homeX = bm.x;
bm.homeY = bm.y;
bm.vx = Math.cos(angle) * radius;
bm.vy = Math.sin(angle) * radius;
addChild(bm);
//
_particleList.push(bm);
}
}
//
image.dispose()
breakInterval();
}
private function breakInterval():void{
var timer:Timer = new Timer(1000, 1);
timer.addEventListener(TimerEvent.TIMER_COMPLETE, imgBreak);
timer.start();
//
function imgBreak(e:TimerEvent):void{
timer.removeEventListener(TimerEvent.TIMER_COMPLETE, imgBreak);
addEventListener(Event.ENTER_FRAME, update);
_timer.stop();
_container.visible = false;
bt0.visible = false;
bt1.visible = false;
bt2.visible = false;
}
}
private function update(e:Event):void{
var n:int = _particleList.length;
while (n--) {
var v:Number = Math.random() * 0.5 + 0.8;
var p:Particle = _particleList[n];
p.vy += 0.5;
p.vx *= v * .95;
p.vy *= v;
p.x += p.vx;
p.y += p.vy;
//
if(p.x < -100 || p.x > W + 100 || p.y < -100 || p.y > H * 2){
removeChild(_particleList[n]);
_particleList.splice(n, 1);
if(_particleList.length == 0){
removeEventListener(Event.ENTER_FRAME, update);
}
}
}
}
}
}
//class TimePanel
import flash.display.Sprite;
import flash.display.Shape;
class TimePanel extends Sprite{
private var _tx:NumText = new NumText()
public function TimePanel(){
this.cacheAsBitmap = true;
var size:int = 30;
var shape:Shape = new Shape();
shape.graphics.beginFill(0, 0);
shape.graphics.drawRect(-size/2, -size/2, size, size);
shape.graphics.endFill();
//;
_tx.selectable = false
_tx.width = size;
_tx.height = size;
_tx.x = -size/2;
_tx.y = -size/3;
//
addChild(shape);
addChild(_tx);
}
public function get tx():NumText{
return _tx;
}
}
//class NumText
import flash.text.TextField;
import flash.text.TextFormat;
import flash.events.Event;
class NumText extends TextField{
private var _fmt:TextFormat = new TextFormat(null, null, 0xFFFFFF, true, false, false, null, null, "center", null, null, null, 2);
private var _Rosewood:FontEmbed;
public var numStr:String;
public function NumText(){
this.defaultTextFormat = _fmt;
_Rosewood = new FontEmbed("http://www.digifie.jp/files/Rosewood.swf", "Rosewood");
_Rosewood.addEventListener(FontEmbed.FONT_LOADED, onFontLoaded);
}
private function onFontLoaded(e:Event):void {
_Rosewood.embetedFont(this, "Rosewood Std", 30, _fmt);
this.text = numStr;
}
}
//FontEmbed
import flash.events.Event;
import flash.events.ProgressEvent;
import flash.events.EventDispatcher;
import flash.display.Loader;
import flash.display.LoaderInfo;
import flash.net.URLRequest;
import flash.net.URLLoader;
import flash.text.TextField;
import flash.text.TextFormat;
import flash.text.Font;
import flash.system.LoaderContext;
import flash.system.ApplicationDomain;
import flash.system.SecurityDomain;
import flash.system.Security;
class FontEmbed extends EventDispatcher {
private var _fontClassName:String;
private var _loader:Loader = new Loader();
public var prigress:int;
public static const FONT_LOADED:String = "font_loaded";
public function FontEmbed(fontPath:String, fontClassName:String) {
Security.loadPolicyFile("http://www.digifie.jp/crossdomain.xml");
Security.allowDomain("www.digifie.jp");
swfLoad(fontPath);
_fontClassName = fontClassName;
}
//Load FontSwf
private function swfLoad(fontPath:String):void{
var context:LoaderContext = new LoaderContext();
context.checkPolicyFile = true;
context.securityDomain = SecurityDomain.currentDomain;
context.applicationDomain = ApplicationDomain.currentDomain;
var req:URLRequest = new URLRequest(fontPath);
_loader.contentLoaderInfo.addEventListener(Event.COMPLETE, swfLoadComplete);
_loader.contentLoaderInfo.addEventListener(ProgressEvent.PROGRESS,onProgressListener);
_loader.load(req, context);
}
//Progress
private function onProgressListener(e:ProgressEvent):void {
prigress = e.bytesLoaded/e.bytesTotal*100;
}
//Load Complete
private function swfLoadComplete(e:Event):void {
_loader.contentLoaderInfo.removeEventListener(Event.COMPLETE,swfLoadComplete);
_loader.contentLoaderInfo.removeEventListener(ProgressEvent.PROGRESS,onProgressListener);
//
var fontClass:Class = _loader.contentLoaderInfo.applicationDomain.getDefinition(_fontClassName) as Class;
try{
Font.registerFont(fontClass);
}catch(e:Error){
//
}
dispatchEvent(new Event(FontEmbed.FONT_LOADED));
}
//Embeted Font
public function embetedFont(txt:TextField, fontname:String, size:Number, fmt:TextFormat):void {
var tfmt:TextFormat = fmt
tfmt.font = fontname;
tfmt.size = size;
txt.embedFonts = true;
txt.defaultTextFormat = tfmt;
}
}
//Btn
import flash.display.Sprite;
import flash.filters.GlowFilter;
import flash.filters.BevelFilter;
class Btn extends Sprite{
private var _glow:GlowFilter;
private var _bevel:BevelFilter;
private var _knockout:Boolean;
public function Btn(size:int, color:int=0xFFFFFF){
var colors:Array = [color, 0xFF9F00];
var alphas:Array = [1, 1];
var ratios:Array = [0, 40];
graphics.lineStyle(2, 0x606060, 1);
graphics.beginGradientFill("radial", colors, alphas, ratios);
graphics.drawCircle(0,0,size/2);
graphics.endFill();
//
_glow = new GlowFilter(0xFFFFFF,0.5,12,12,4,2,false,false);
_bevel = new BevelFilter(20,90,0xFFFFFF,1,0x000000,0.3,32,32,1.4,1,"inner",_knockout)
this.filters = [_bevel, _glow];
this.buttonMode = true;
}
public function set knockout(flg:Boolean):void{
_bevel.knockout = flg;
this.filters = [_bevel, _glow];
}
}
//Particle
import flash.display.Bitmap;
import flash.display.BitmapData;
class Particle extends Bitmap{
public var homeX:Number = 0;
public var homeY:Number = 0;
public var vx:Number = 0;
public var vy:Number = 0;
public function Particle(bmd:BitmapData, snap:String = "auto", somooth:Boolean = false){
super(bmd, snap, somooth);
}
}