var masuList:Array; // マスの配列
var masuObjectList:Array; // マスオブジェクトの配列
var gameStatus:int; // 0:wait 1:waitDiceClick 2:diceWait 3:playerMenuSelectWait 4:playerMove 5:userWaySelect 6:clear
var mainCamera:GameObject;
//-------------------- UIまわり ------------------
var menuObject:GameObject;
var limitMoveText:GameObject;
var limitValue:int; // 実際に動ける残りの数
var allows:GameObject; // →
//-------------------- ステージ -----------------
var startObject:GameObject;
var goalObject:GameObject;
//-------------------- さいころ ------------------
var diceCamera:GameObject;
var diceObject:GameObject; // さいころ
var diceStartFlg:boolean; // さいころ転がり中フラグ
//-------------------- ターン -----------------
var diceValue:int; // 出た目
//-------------------- Clear ----------------
var clearText:GameObject;
function ChangeGameStatus(status:int){
if(status == 1 || status == 2){
diceObject.transform.position = Vector3(3, 1, -8);
diceCamera.SetActive(true);
diceCamera.SetActive(false);
menuObject.SetActive(true);
menuObject.SetActive(false);
if(status == 4 || status == 5){
limitMoveText.SetActive(true);
limitMoveText.GetComponent(TextMesh).text = "残り"+ diceValue + "マス";
limitMoveText.SetActive(false);
var pos:Vector3 = chara.transform.position;
clearText.transform.position = pos;
clearText.SetActive(true);
clearText.SetActive(false);
private function CharaMove(){
yield WaitForSeconds(0.2);
var charaObject:PlayerObject = chara.GetComponent(PlayerObject);
var charaDir:String = charaObject.dir;
var pos:Vector2 = charaObject.pos;
if(GetMasuData(pos.x , pos.y) == "G"){
// 現在位置から自分が来た方向以外の方向のますをチェック
var upFlg:boolean = false;
var downFlg:boolean = false;
var leftFlg:boolean = false;
var rightFlg:boolean = false;
var nextPosList:Array = new Array();
var nextDirList:Array = new Array();
if(charaDir != "left" && pos.x != masuColSize - 1 && GetMasuData(pos.x + 1, pos.y) != "#"){
nextPosList.push(new Vector2(pos.x + 1, pos.y));
nextDirList.push("right");
if(charaDir != "right" && pos.x != 0 && GetMasuData(pos.x - 1, pos.y) != "#"){
nextPosList.push(new Vector2(pos.x - 1, pos.y));
nextDirList.push("left");
if(charaDir != "down" && pos.y != 0 && GetMasuData(pos.x, pos.y - 1) != "#"){
nextPosList.push(new Vector2(pos.x, pos.y - 1));
if(charaDir != "up" && pos.y != masuRowSize - 1 && GetMasuData(pos.x, pos.y + 1) != "#"){
nextPosList.push(new Vector2(pos.x, pos.y + 1));
nextDirList.push("down");
limitMoveText.GetComponent(TextMesh).text = "残り"+ limitValue + "マス";
var nextPos:Vector2 = nextPosList[0];
var nextMasuObject:GameObject = GameObject.Find("Masu" + nextPos.x + nextPos.y);
iTween.MoveTo(chara, iTween.Hash("x", nextMasuObject.transform.position.x, "y", nextMasuObject.transform.position.y,"delay", 0, "time", 0.5, "oncomplete", "CharaMove", "oncompletetarget", this.gameObject));
charaObject.dir = nextDirList[0];
charaObject.pos = nextPosList[0];
allows.transform.position = chara.transform.position;
allows.GetComponent(ArrowObject).SetDir(nextDirList);
private function CharaCreate(){
chara = Instantiate(Resources.Load("Prefabs/Object/Chara"));
chara.transform.position = startObject.transform.position;
var charaObject:PlayerObject = chara.GetComponent(PlayerObject);
charaObject.pos = startPos;
private function GetMasuData(x:int, y:int){
return masuList[x + y * masuColSize];
private function StageCreate(){
masuObjectList = new Array();
var stageStrList:Array = DataBase.Stage1;
masuRowSize = stageStrList.length;
for(var y:int = 0; y < stageStrList.length; y++){
var str:String = stageStrList[y];
masuColSize = str.Length;
for(var x:int = 0; x < str.Length; x++){
var masuStr:String = str.Substring(x, 1);
var masuObject:GameObject = null;
masuList[x + y * str.Length] = masuStr;
masuObject = Instantiate(Resources.Load("Prefabs/Object/Masu"), new Vector3(1.0* x, -1.0 * y, 0) ,Quaternion.identity);
masuObject.name = "Masu"+ x + y;
}else if(masuStr == "0"){
}else if(masuStr == "S"){
var tex:tk2dSprite = masuObject.GetComponent(tk2dSprite);
mainCamera.transform.position.x = masuObject.transform.position.x;
mainCamera.transform.position.y = masuObject.transform.position.y;
startObject = masuObject;
startPos = new Vector2(x,y);
}else if(masuStr == "G"){
tex = masuObject.GetComponent(tk2dSprite);
goalPos = new Vector2(x,y);
masuObjectList.push(masuObject);
var rollTarget:Vector3 = Vector3.zero + new Vector3(2 + 7 * Random.value, .5F + 4 * Random.value, -2 - 3 * Random.value);
return Vector3.Lerp(diceObject.transform.position, rollTarget, 1).normalized * (-35 - Random.value * 20);
if(gameStatus == 1 && Input.GetMouseButtonDown(0)){
//diceObject.rigidbody.AddExplosionForce(00, diceObject.transform.position - Vector3.left * 3.0, 10, 3.0);
diceObject.rigidbody.AddForce(Force(),ForceMode.Impulse);
diceObject.rigidbody.AddTorque(new Vector3(-50 * Random.value * diceObject.transform.localScale.magnitude, -50 * Random.value * diceObject.transform.localScale.magnitude, -50 * Random.value * diceObject.transform.localScale.magnitude), ForceMode.Impulse);
if(diceObject.rigidbody.velocity.magnitude == 0){
function UserSelectArrow(dir:String){
limitMoveText.GetComponent(TextMesh).text = "残り"+ limitValue + "マス";
var charaObject:PlayerObject = chara.GetComponent(PlayerObject);
var pos:Vector2 = charaObject.pos;
nextPos = new Vector2(pos.x - 1, pos.y);
}else if(dir == "right"){
nextPos = new Vector2(pos.x + 1, pos.y);
nextPos = new Vector2(pos.x, pos.y -1);
nextPos = new Vector2(pos.x, pos.y + 1);
var nextMasuObject:GameObject = GameObject.Find("Masu" + nextPos.x + nextPos.y);
iTween.MoveTo(chara, iTween.Hash("x", nextMasuObject.transform.position.x, "y", nextMasuObject.transform.position.y,"delay", 0, "time", 0.7, "oncomplete", "CharaMove", "oncompletetarget", this.gameObject));
charaObject.pos = nextPos;
diceValue = diceObject.GetComponent(Die).value;
yield WaitForSeconds(1.5);
diceValue = diceObject.GetComponent(Die).value;
diceObject.rigidbody.AddForce(Force(),ForceMode.Impulse);
yield WaitForSeconds(2.0);