portal
いわゆるあれ
・青から入ってオレンジから出てくる
・青とオレンジはドラッグ可能
/**
* Copyright Scmiz ( http://wonderfl.net/user/Scmiz )
* MIT License ( http://www.opensource.org/licenses/mit-license.php )
* Downloaded from: http://wonderfl.net/c/wAVa
*/
package {
import flash.display.Graphics;
import flash.display.Sprite;
import flash.events.Event;
import flash.events.MouseEvent;
import flash.text.TextField;
public class FlashTest extends Sprite {
private var _data:/*Datum*/Array;
private var _in:Sprite;
private var _out:Sprite;
private const WIDTH:Number = 48;
private const HEIGHT:Number = 8;
public function FlashTest() {
_in = new Sprite();
_in.graphics.beginFill(0x8080ff);
_in.graphics.drawRect(-WIDTH * 0.5, -HEIGHT * 0.5, WIDTH, HEIGHT);
_in.graphics.endFill();
_in.x = 200;
_in.y = 100;
_in.addEventListener(MouseEvent.MOUSE_DOWN, inMouseDown);
_in.addEventListener(MouseEvent.MOUSE_UP, inMouseUp);
this.addChild(_in);
_out = new Sprite();
_out.graphics.beginFill(0xffb040);
_out.graphics.drawRect(-HEIGHT * 0.5, -WIDTH * 0.5, HEIGHT, WIDTH);
_out.graphics.endFill();
_out.x = 300;
_out.y = 200;
_out.addEventListener(MouseEvent.MOUSE_DOWN, outMouseDown);
_out.addEventListener(MouseEvent.MOUSE_UP, outMouseUp);
this.addChild(_out);
_data = new Array();
this.addEventListener(Event.ENTER_FRAME, proc);
}
private function inMouseDown(e:MouseEvent):void {
_in.startDrag();
}
private function inMouseUp(e:MouseEvent):void {
_in.stopDrag();
}
private function outMouseDown(e:MouseEvent):void {
_out.startDrag();
}
private function outMouseUp(e:MouseEvent):void {
_out.stopDrag();
}
private function proc(e:Event):void {
add();
update();
draw();
}
private function add():void {
var datum:Datum = new Datum();
datum.pos.x = 200 + (Math.random() * 65);
datum.pos.y = -10;
datum.speed.y = 1 + (Math.random() * 1.5);
var r:uint = 128 + (Math.random() * 128);
var g:uint = 128 + (Math.random() * 128);
var b:uint = 128 + (Math.random() * 128);
datum.color = (r << 16) + (g << 8) + (b << 0);
_data.push(datum);
}
private function update():void {
for (var index:uint = 0; index < _data.length; ++index) {
_data[index].pos.x += _data[index].speed.x;
_data[index].pos.y += _data[index].speed.y;
if (_data[index].pos.x > _in.x - (WIDTH * 0.5)
&& _data[index].pos.x < _in.x + (WIDTH * 0.5)
&& _data[index].pos.y > _in.y - (HEIGHT * 0.5)
&& _data[index].pos.y < _in.y + (HEIGHT * 0.5)
&& _data[index].speed.y > 0
) {
_data[index].pos.y = _out.y - (_in.x - _data[index].pos.x);
_data[index].pos.x = _out.x;
_data[index].speed.x = -_data[index].speed.y;
_data[index].speed.y = 0;
}
if ((_data[index].pos.x < -20)
|| (_data[index].pos.x > 485)
|| (_data[index].pos.y < -20)
|| (_data[index].pos.y > 485)
) {
_data.splice(index, 1);
--index;
continue;
}
}
}
private function draw():void {
var g:Graphics = this.graphics;
g.clear();
g.beginFill(0x404040);
g.drawRect(0, 0, 465, 465);
g.endFill();
for (var index:uint = 0; index < _data.length; ++index) {
g.beginFill(_data[index].color);
g.drawCircle(_data[index].pos.x, _data[index].pos.y, 2);
g.endFill();
}
}
}
}
import flash.geom.Point;
class Datum {
public var pos:Point = new Point();
public var speed:Point = new Point();
public var color:uint = 0xffffff;
}