2019-04-28 21:50:15 UNSELECTED

Unknown type code

Copy Copied! Full
--簡略化 ASET = vci.assets STAT = vci.state VEC001 = Vector3.__new(0, 0, 1) --Unity駒の名称 FRM_STR = { "Frame1", "Frame2", "Frame3", "Frame4", "Frame5", "Frame6", "Frame7", "Frame8", "Frame9", "Frame10", "Frame11", "Frame12", "Frame13", "Frame14", "Frame15", "Frame16", "Frame17", "Frame18", "Frame19", "Frame20", "Frame21", "Frame22", "Frame23", "Frame24", "Frame25", "Frame26", "Frame27", "Frame28", "Frame29", "Frame30", "Frame31", "Frame32", "Frame33", "Frame34", "Frame35", "Frame36", "Frame37", "Frame38", "Frame39", "Frame40", "Frame41", "Frame42", "Frame43", "Frame44", "Frame45", "Frame46", "Frame47", "Frame48", "Frame49", "Frame50", "Frame51", "Frame52", "Frame53", "Frame54", "Frame55", "Frame56", "Frame57", "Frame58", "Frame59", "Frame60", "Frame61", "Frame62", "Frame63", "Frame64" } --FRM_STR使用されているかどうか FRM_FLG = { 1, 1, 1, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 } TARG_NUM = 0 --FRM_STRの掴んだ番号 STAT.Set("TARG_NUM", 0) --盤面に置かれているFRM_STRの番号 BRD_FLG = { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 2, 0, 0, 0, 0, 0, 0, 3, 4, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 } --どの方向を向いているか(0:黒、90:駒なし、180:白) BRD_ANG = { 90, 90, 90, 90, 90, 90, 90, 90, 90, 90, 90, 90, 90, 90, 90, 90, 90, 90, 90, 90, 90, 90, 90, 90, 90, 90, 90, 180, 0, 90, 90, 90, 90, 90, 90, 0, 180, 90, 90, 90, 90, 90, 90, 90, 90, 90, 90, 90, 90, 90, 90, 90, 90, 90, 90, 90, 90, 90, 90, 90, 90, 90, 90, 90 } GRIP_FLG = false --グリップ判定 STAT.Set("GRIP_FLG", GRIP_FLG) USE_FLG = false --使用判定 STAT.Set("USE_FLG", USE_FLG) BLACK_FLG = false --黒カプセルが押された STAT.Set("BLACK_FLG", BLACK_FLG) WHITE_FLG = false --白カプセルが押された STAT.Set("WHITE_FLG", WHITE_FLG) FIRST_FLG = true --初期化 STAT.Set("FIRST_FLG", FIRST_FLG) ang = 0 ANG=0 --現在の手番を表す function update() BLACK_FLG = STAT.Get("BLACK_FLG") WHITE_FLG = STAT.Get("WHITE_FLG") OBJ = ASET.GetSubItem("White") --ゲーム初期化 if WHITE_FLG == true then ang = 0 for i = 1, #FRM_FLG do if i > 4 then FRM_FLG[i] = 0 end if i == 28 then BRD_FLG[i] = 1 BRD_ANG[i] = 180 elseif i == 37 then BRD_FLG[i] = 2 BRD_ANG[i] = 180 elseif i == 29 then BRD_FLG[i] = 3 BRD_ANG[i] = 0 elseif i == 36 then BRD_FLG[i] = 4 BRD_ANG[i] = 0 else BRD_FLG[i] = 0 BRD_ANG[i] = 90 end end BLACK_FLG = true --下も起動 WHITE_FLG = false STAT.Set("WHITE_FLG", WHITE_FLG) end OBJ = ASET.GetSubItem("Black") --駒を黒カプセル周辺に集める if BLACK_FLG == true then OBJ = ASET.GetSubItem("Black") POS = OBJ.GetPosition() for i = 1, #FRM_FLG do if FRM_FLG[i] == 0 then OBJ = ASET.GetSubItem(FRM_STR[i]) OBJ.SetPosition( Vector3.__new( POS.x + 0.35 * math.sin(2 * math.pi * i / 54), POS.y, POS.z + 0.35 * math.cos(2 * math.pi * i / 54) ) ) end end BLACK_FLG = false STAT.Set("BLACK_FLG", BLACK_FLG) end FIRST_FLG = STAT.Get("FIRST_FLG") if FIRST_FLG == true then Move_STROBJ() FIRST_FLG = false STAT.Set("FIRST_FLG", FIRST_FLG) end --グリップされていたならば GRIP_FLG = STAT.Get("GRIP_FLG") if GRIP_FLG == true then --ターゲット番号を読み取り TARG_NUM = STAT.Get("TARG_NUM") min = 0 --近傍マス目 min_loc = 0.06 --最近傍距離 --現在持っている駒の位置と盤面のマス目の最近傍を求める for i = 1, #BRD_FLG do if BRD_FLG[i] == 0 then OBJ = ASET.GetSubItem("Board") POS = OBJ.GetPosition() ANG = Vector3.Angle(VEC001, OBJ.GetForward()) if OBJ.GetForward().x < 0 then ANG = -1 * ANG end sho = (-3.5 + math.floor((i - 1) / 8)) * 0.08 ama = (-3.5 + (i - 1) % 8) * 0.08 OBJ = ASET.GetSubItem(FRM_STR[TARG_NUM]) ANG2 = Vector3.Angle(VEC001, Vector3.__new(sho, 0, ama).normalized) if sho < 0 then ANG2 = -1 * ANG2 end pow1 = sho * sho pow2 = ama * ama POS2 = POS POS2.Set( POS.x + math.sqrt(pow1 + pow2) * math.sin(math.pi * (ANG2 - ANG) / 180), POS.y + 0.1, POS.z - math.sqrt(pow1 + pow2) * math.cos(math.pi * (ANG2 - ANG) / 180) ) POS = OBJ.GetPosition() loc = math.sqrt((POS.x - POS2.x) * (POS.x - POS2.x) + (POS.z - POS2.z) * (POS.z - POS2.z)) if min_loc > loc then min_loc = loc min = i end end end --luaでは配列[0]エラーになるから、それ以外の時補助の駒を動かす if min > 0 then OBJ = ASET.GetSubItem("Board") POS = OBJ.GetPosition() ANG = Vector3.Angle(VEC001, OBJ.GetForward()) if OBJ.GetForward().x < 0 then ANG = -1 * ANG end sho = (-3.5 + math.floor((min - 1) / 8)) * 0.08 ama = (-3.5 + (min - 1) % 8) * 0.08 OBJ = ASET.GetSubItem("Frame100") ANG2 = Vector3.Angle(VEC001, Vector3.__new(sho, 0, ama).normalized) if sho < 0 then ANG2 = -1 * ANG2 end pow1 = sho * sho pow2 = ama * ama OBJ.SetPosition( Vector3.__new( POS.x + math.sqrt(pow1 + pow2) * math.sin(math.pi * (ANG2 - ANG) / 180), POS.y + 0.1, POS.z - math.sqrt(pow1 + pow2) * math.cos(math.pi * (ANG2 - ANG) / 180) ) ) OBJ.SetRotation(Quaternion.Euler(ang, 0, 0)) else OBJ = ASET.GetSubItem("Frame100") pow1 = sho * sho pow2 = ama * ama OBJ.SetPosition( Vector3.__new( POS.x + math.sqrt(pow1 + pow2) * math.sin(math.pi * (ANG2 - ANG) / 180), 0, POS.z - math.sqrt(pow1 + pow2) * math.cos(math.pi * (ANG2 - ANG) / 180) ) ) end --使用されたならば USE_FLG = STAT.Get("USE_FLG") STAT.Set("USE_FLG", false) if USE_FLG == true then if min > 0 then --ここから横縦斜めの、駒置けるか判断する処理 ama = (min - 1) % 8 num = 0 FLG = false for i = 1, 7 - ama do if not (BRD_ANG[min + i] == ang) then if BRD_ANG[min + i] == 90 then break else num = num + 1 end else if num > 0 then FLG = true end break end end if FLG == true then for i = 1, num do BRD_ANG[min + i] = ang end BRD_FLG[min] = TARG_NUM end num = 0 FLG = false for i = 1, ama do if not (BRD_ANG[min - i] == ang) then if BRD_ANG[min - i] == 90 then break else num = num + 1 end else if num > 0 then FLG = true end break end end if FLG == true then for i = 1, num do BRD_ANG[min - i] = ang end BRD_FLG[min] = TARG_NUM end sho = math.floor((min - 1) / 8) num = 0 FLG = false for i = 1, 7 - sho do if not (BRD_ANG[min + i * 8] == ang) then if BRD_ANG[min + i * 8] == 90 then break else num = num + 1 end else if num > 0 then FLG = true end break end end if FLG == true then for i = 1, num do BRD_ANG[min + i * 8] = ang end BRD_FLG[min] = TARG_NUM end num = 0 FLG = false for i = 1, sho do if not (BRD_ANG[min - i * 8] == ang) then if BRD_ANG[min - i * 8] == 90 then break else num = num + 1 end else if num > 0 then FLG = true end break end end if FLG == true then for i = 1, num do BRD_ANG[min - i * 8] = ang end BRD_FLG[min] = TARG_NUM end --斜 num = 0 FLG = false if sho < ama then data = 7 - sho else data = 7 - ama end for i = 1, data do if min + i * 9 < 65 then if not (BRD_ANG[min + i * 9] == ang) then if BRD_ANG[min + i * 9] == 90 then break else num = num + 1 end else if num > 0 then FLG = true end break end else break end end if FLG == true then for i = 1, num do BRD_ANG[min + i * 9] = ang end BRD_FLG[min] = TARG_NUM end num = 0 FLG = false if sho < ama then data = sho else data = ama end for i = 1, data do if min - i * 9 > 0 then if not (BRD_ANG[min - i * 9] == ang) then if BRD_ANG[min - i * 9] == 90 then break else num = num + 1 end else if num > 0 then FLG = true end break end else break end end if FLG == true then for i = 1, num do BRD_ANG[min - i * 9] = ang end BRD_FLG[min] = TARG_NUM end num = 0 FLG = false if sho < (7 - ama) then data = sho else data = 7 - ama end for i = 1, data do if min - i * 7 > 0 then if not (BRD_ANG[min - i * 7] == ang) then if BRD_ANG[min - i * 7] == 90 then break else num = num + 1 end else if num > 0 then FLG = true end break end else break end end if FLG == true then for i = 1, num do BRD_ANG[min - i * 7] = ang end BRD_FLG[min] = TARG_NUM end num = 0 FLG = false if (7 - sho) < ama then data = 7 - sho else data = ama end for i = 1, data do if min + i * 7 < 65 then if not (BRD_ANG[min + i * 7] == ang) then if BRD_ANG[min + i * 7] == 90 then break else num = num + 1 end else if num > 0 then FLG = true end break end else break end end if FLG == true then for i = 1, num do BRD_ANG[min + i * 7] = ang end BRD_FLG[min] = TARG_NUM end --駒をとれた(置けた)ならば次の人 if BRD_FLG[min] > 0 then BRD_ANG[min] = ang FRM_FLG[TARG_NUM] = 1 if ang == 0 then ang = 180 else ang = 0 end end end FIRST_FLG = true STAT.Set("FIRST_FLG", FIRST_FLG) end end end function onUse(use) --駒を使用したならば for i = 1, #FRM_STR do if FRM_FLG[i] == 0 then if use == FRM_STR[i] then USE_FLG = true STAT.Set("USE_FLG", USE_FLG) end end end if use == "White" then WHITE_FLG = true STAT.Set("WHITE_FLG", WHITE_FLG) FIRST_FLG = true STAT.Set("FIRST_FLG", FIRST_FLG) end if use == "Black" then BLACK_FLG = true STAT.Set("BLACK_FLG", BLACK_FLG) end end function onTriggerExit(it, h) Velo_Ang_Zero(it) end function onCollisionExit(it, h) Velo_Ang_Zero(it) end function onGrab(tar) --駒を握ったならば for i = 1, #FRM_STR do if FRM_FLG[i] == 0 then if tar == FRM_STR[i] then TARG_NUM = i GRIP_FLG = true STAT.Set("TARG_NUM", TARG_NUM) STAT.Set("GRIP_FLG", GRIP_FLG) end end end end function onUngrab(tar) --駒を離したならば for i = 1, #FRM_STR do if FRM_FLG[i] == 0 then if tar == FRM_STR[i] then TARG_NUM = 0 GRIP_FLG = false STAT.Set("TARG_NUM", TARG_NUM) STAT.Set("GRIP_FLG", GRIP_FLG) end end end end function Velo_Ang_Zero(it) OBJ = ASET.GetSubItem(it) OBJ.SetVelocity(Vector3.__new(0, 0, 0)) OBJ.SetAngularVelocity(Vector3.__new(0, 0, 0)) if it == "Board" then OBJ.SetRotation(Quaternion.Euler(0, ANG, 0)) end FIRST_FLG = true STAT.Set("FIRST_FLG", FIRST_FLG) end --駒をBRD_FLGに従い配置 function Move_STROBJ() --駒をBRD_FLGに従い配置 for i = 1, #BRD_FLG do if BRD_FLG[i] > 0 then OBJ = ASET.GetSubItem("Board") POS = OBJ.GetPosition() ANG = Vector3.Angle(VEC001, OBJ.GetForward()) if OBJ.GetForward().x < 0 then ANG = -1 * ANG end sho = (-3.5 + math.floor((i - 1) / 8)) * 0.08 ama = (-3.5 + (i - 1) % 8) * 0.08 OBJ = ASET.GetSubItem(FRM_STR[BRD_FLG[i]]) --if OBJ.IsMine == true then ANG2 = Vector3.Angle(VEC001, Vector3.__new(sho, 0, ama).normalized) if sho < 0 then ANG2 = -1 * ANG2 end pow1 = sho * sho pow2 = ama * ama OBJ.SetPosition( Vector3.__new( POS.x + math.sqrt(pow1 + pow2) * math.sin(math.pi * (ANG2 - ANG) / 180), POS.y + 0.1, POS.z - math.sqrt(pow1 + pow2) * math.cos(math.pi * (ANG2 - ANG) / 180) ) ) OBJ.SetRotation(Quaternion.Euler(BRD_ANG[i], 0, 0)) -- end end end end
RECOMMEND