玉転がしin迷路
迷路が回転します
クリックで玉を追加できます
/**
* Copyright aduonety ( http://wonderfl.net/user/aduonety )
* MIT License ( http://www.opensource.org/licenses/mit-license.php )
* Downloaded from: http://wonderfl.net/c/dOIP
*/
// forked from figma000's 迷路(くっつける練習)
// forked from aduonety's forked from: forked from: [QuickBox2D] Doll in space_2
// forked from a24's forked from: [QuickBox2D] Doll in space
// forked from paq's [QuickBox2D] Doll in space
package
{
import flash.display.AVM1Movie;
import Box2D.Common.Math.b2Vec2;
import Box2D.Dynamics.b2Body;
import com.actionsnippet.qbox.objects.CircleObject;
import com.actionsnippet.qbox.QuickBox2D;
import com.actionsnippet.qbox.QuickObject;
import flash.display.MovieClip;
import flash.display.StageScaleMode;
import flash.events.Event;
import frocessing.math.*;
import flash.geom.Rectangle;
import flash.events.MouseEvent;
import jp.progression.commands.lists.*;
import flash.display.SimpleButton;
import flash.text.TextField;
import flash.text.TextFormat;
import flash.display.Sprite;
[SWF(width = 465, height = 465, backgroundColor = 0x000000, frameRate = 60)]
public class Sample extends MovieClip
{
private var sim:QuickBox2D;
private var fixedPoint:b2Vec2 = new b2Vec2(7.25, 7.25);
private var scale:Number = 10;
private var balls:Array = new Array();
private var list:SerialList = new SerialList();
public var data:Array = new Array(16);
private var boxA:QuickObject;
private var boxB:QuickObject;
private var parts:Array = [];
private var tf:TextField;
// /*
// public var existBlock:Boolean;
//*/
//フラグ用の配列の生成
public function Makearray():void
{
{
for (var i_m:int = 0; i_m < 16; i_m++)
{
data[i_m] = new Array(16);
}
for(var i:int = 0; i<16; i++){
for(var j:int = 0; j<16; j++)
{
data[i][j]= 0; //初期値0
}
}
}
}
// 配列の値を返す
public function CheckExistBox(xe:int, ye:int):int
{
var value:int = data[xe][ye];
//var up:State = new State(0x0);
// var over:State = new State(0xFF4500);
// button.addEventListener(MouseEvent.CLICK, onMouseClick);
return value;
}
public function Sample():void
{
// addEventListener(MouseEvent.CLICK,mouseClickonBlock);
// if(existBlock == false){
stage.addEventListener(MouseEvent.CLICK,mouseClick);
// }
if (stage) init();
else addEventListener(Event.ADDED_TO_STAGE, init);
}
private function init(e:Event = null):void
{
removeEventListener(Event.ADDED_TO_STAGE, init);
stage.scaleMode = StageScaleMode.NO_BORDER;
sim = new QuickBox2D(this);
sim.gravity = new b2Vec2(0, 30);
sim.iterations = 10;
sim.setDefault( { fillColor:0xFFFFFF, lineColor:0x333333 } );
// button.x = (stage.stageWidth - button.width) / 2;
// button.y = (stage.stageHeight - button.height) / 2;
// button.addEventListener(MouseEvent.CLICK, onMouseClick);
Makearray();
//玉の生成_上
for (var i:int = 0; i < 350; i++)
{
var color:String = "0x";
for(var ic:int = 0; ic < 6; ic++){
var color_parts:int = int(Math.random() * 16);
color += color_parts.toString(16);
}
balls.push(sim.addCircle( { x:Math.random() * 12 + 1, y:Math.random() * 1 + 1, radius:0.15 ,fillColor:color} ));
}
{
//枠生成
for(var ix:int = 0; ix < 15; ix++){
for(var iy:int = 0; iy < 15; iy++){
if(ix == 0 || ix == 14 || iy == 0 || iy == 14){
parts.push(sim.addBox( { x:ix, y:iy, width:1, height:1} ));
}
}
}
//枠の中身
{
for(var ix_d:int = 1; ix_d < 14; ix_d++){
for(var iy_d:int = 1; iy_d < 14; iy_d++){
if(ix_d % 2 == 0 && iy_d % 2 == 0){
parts.push(sim.addBox( { x:ix_d, y:iy_d, width:1, height:1} ));
switch (int(Math.random() * 4)) // 0~3のランダム値を生成
{
// 右に倒す
case 0: ix_d++;
parts.push(sim.addBox( { x:ix_d, y:iy_d, width:1, height:1,density:0 } ));
data[ix_d][iy_d] = 1;
ix_d--;
break;
// 左
case 1: ix_d--;
if(CheckExistBox(ix_d,iy_d) == 1){
ix_d++;
iy_d--;
break;
}
else {
parts.push(sim.addBox( { x:ix_d, y:iy_d, width:1, height:1,density:0 } ));
data[ix_d][iy_d] = 1;
ix_d++;
break;
}
// 下
case 2: iy_d++;
parts.push(sim.addBox( { x:ix_d, y:iy_d, width:1, height:1,density:0 } ));
data[ix_d][iy_d] = 1;
iy_d--;
break;
// 上
case 3: iy_d--;
if(CheckExistBox(ix_d,iy_d) == 1){
break;
}
else{
parts.push(sim.addBox( { x:ix_d, y:iy_d, width:1, height:1,density:0 } ));
data[ix_d][iy_d] = 1;
iy_d++;
break;
}
}
}
}
}
}
}
boxA = sim.addGroup({objects:parts, x:0, y:0, angle:0});
boxB = sim.addJoint({type:"revolute", a:boxA.body, b:sim.w.GetGroundBody()});
sim.start();
sim.mouseDrag();
}
//クリックで玉追加
public function mouseClick(event:MouseEvent):void
{
var _x:int = int(mouseX);
var _y:int = int(mouseY);
var color:String = "0x";
for(var ic:int = 0; ic < 6; ic++){
var color_parts:int = int(Math.random() * 16);
color += color_parts.toString(16);
}
sim.addCircle( { x: _x/30, y: _y/30, radius:0.25, fillColor:color} );
// existBlock = false;
}
//ブロックの大きさ変更
private function onButtonClick(event:MouseEvent):void
{
trace("ブロックの大きさ変更")
}
/*
public function mouseClickonBlock(event:MouseEvent):void
{
existBlock = true;
trace(999);
}
*/
private function loop(e:Event):void
{
for ( var i:int = 0; i < balls.length; i ++ )
{
var ball:QuickObject = balls[i];
var fp:b2Vec2 = fixedPoint.Copy();
fp.Subtract(ball.body.GetPosition());
fp.Normalize();
fp.Multiply(50);
balls.push(sim.addCircle( { x:Math.random() * 15.5, y:Math.random() * 7, radius:0.6 } ));
ball.body.ApplyForce(fp, ball.body.GetWorldCenter());
ball.body.ApplyForce(new b2Vec2(0, -30), ball.body.GetWorldCenter());
}
}
}
}
var trace:Function = Wonderfl.log;