//Rockからよう 移動 成功ならtrue失敗ならfalse public bool RockDestroyM(o_Rock rockA, int row) { //Rockの位置検索 for (int listNum = 0; listNum < rocksCol; listNum++) { if (rockA.EqualsRocksPos(list_rocksR[listNum][row])) { if (rockA.Equals(list_rocksR[listNum][row])) { list_rocksR[listNum][row] = null; } else { list_rocksR[listNum][row].CalcMass(); } return(true); } else if (rockA.EqualsRocksPos(list_rocksL[listNum][row])) { if (rockA.Equals(list_rocksL[listNum][row])) { list_rocksL[listNum][row] = null; } else { list_rocksL[listNum][row].CalcMass(); } return(true); } } return(false); }
public void SetRock(o_Rock o_rock, MOVE right_left, int rockCol, int rockRow) { o_rock.Move(this, right_left, rockCol, rockRow, CalcMoveToPosition((int)right_left, rockCol, rockRow)); if (right_left == MOVE.RIGHT) { list_rocksR[rockCol][rockRow] = o_rock; return; } list_rocksL[rockCol][rockRow] = o_rock; }
public bool GetOffRock() { if (ridingRock != null) { ridingRock.ridedRock = null; ridingRock = null; return(true); } return(false); }
public bool EqualsRocksPos(o_Rock rockA) { if (Equals(rockA)) { return(true); } else if (rockA != null && rockA.ridedRock != null && Equals(rockA.ridedRock)) { return(true); } return(false); }
//RockManager用 public bool RideRock(o_Rock rideR) { if (ridedRock == null) { rideR.GetOffRock(); ridedRock = rideR; ridedRock.ridingRock = this; rideR.rideNum = rideNum + 1; return(true); } else { return(false); } }
// Update is called once per frame void Update() { if (Input.GetKeyDown(KeyCode.Q)) { actionMode_ = !actionMode_; sc_.ModeChange(); rock_ = null; Keeprock_ = false; } if (!actionMode_) { // 左に移動 if (Input.GetKey(KeyCode.W)) { zPosition += 6.0f * Time.deltaTime; //this.transform.Translate(-0.1f, 0.0f, 0.0f); } // 右に移動 if (Input.GetKey(KeyCode.S)) { zPosition -= 6.0f * Time.deltaTime; } // 前に移動 if (Input.GetKey(KeyCode.A)) { angle_ -= 3.0f * Time.deltaTime; //this.transform.Translate(0.0f, 0.0f, 0.1f); } // 後ろに移動 if (Input.GetKey(KeyCode.D)) { angle_ += 3.0f * Time.deltaTime; //this.transform.Translate(0.0f, 0.0f, -0.1f); } //transform.position = obj.transform.position; x = radius * Mathf.Sin(angle_) + obj.transform.position.x; z = zPosition + obj.transform.position.z; y = radius * Mathf.Cos(angle_) + obj.transform.position.y; transform.position = new Vector3(x, y, z); Vector3 _look = obj.transform.position; _look.z = z; this.transform.LookAt(_look); } else { if (Input.GetKeyDown(KeyCode.K)) { hakai_ = !hakai_; Keeprock_ = false; if (hakai_) { var kari = this.GetComponent <MeshRenderer>(); kari.material = _break; } else { var kari = this.GetComponent <MeshRenderer>(); kari.material = _Idou; } } if (Input.GetMouseButtonDown(0)) //マウスがクリックされたら { Ray ray = camera.ScreenPointToRay(Input.mousePosition); //マウスのポジションを取得してRayに代入 if (Physics.Raycast(ray, out hit)) //マウスのポジションからRayを投げて何かに当たったらhitに入れる { string objectName = hit.collider.gameObject.name; //オブジェクト名を取得して変数に入れる if (hakai_) { rock_ = hit.collider.gameObject.GetComponent <o_Rock>(); rock_.RockDestroy(); } else { rock_ = hit.collider.gameObject.GetComponent <o_Rock>(); rock_.OnSelected(); Keeprock_ = true; } } } if (Keeprock_) { if (Input.GetKeyDown(KeyCode.W)) { Debug.Log(transform.localEulerAngles.y); if (transform.transform.localEulerAngles.y > 269) { angle_ -= 0.3f; //rock_.RockMove(o_RockManager.MOVE.UP); rock_.RockMove(Vector3.up); } else { angle_ += 0.3f; //rock_.RockMove(o_RockManager.MOVE.UP); rock_.RockMove(Vector3.up); } } if (Input.GetKeyDown(KeyCode.S)) { Debug.Log(transform.transform.localEulerAngles.y); if (transform.localEulerAngles.y > 269) { angle_ += 0.3f; //rock_.RockMove(o_RockManager.MOVE.DOWN); rock_.RockMove(Vector3.down); } else { angle_ -= 0.3f; // rock_.RockMove(o_RockManager.MOVE.DOWN); rock_.RockMove(Vector3.down); } } if (Input.GetKeyDown(KeyCode.A)) { Debug.Log(transform.transform.localEulerAngles.y); if (transform.localEulerAngles.y < 269) { zPosition += 0.5f; rock_.RockMove(o_RockManager.MOVE.FRONT); } else { zPosition -= 0.5f; rock_.RockMove(o_RockManager.MOVE.BACK); } } if (Input.GetKeyDown(KeyCode.D)) { Debug.Log(transform.transform.localEulerAngles.y); if (transform.localEulerAngles.y > 269) { zPosition += 0.5f; rock_.RockMove(o_RockManager.MOVE.FRONT); } else { zPosition -= 0.5f; rock_.RockMove(o_RockManager.MOVE.BACK); } } } else { if (Input.GetKey(KeyCode.W)) { radius -= 4.0f * Time.deltaTime; //this.transform.Translate(-0.1f, 0.0f, 0.0f); } if (Input.GetKey(KeyCode.S)) { radius += 4.0f * Time.deltaTime; //this.transform.Translate(-0.1f, 0.0f, 0.0f); } } x = radius * Mathf.Sin(angle_) + obj.transform.position.x; z = zPosition + obj.transform.position.z; y = radius * Mathf.Cos(angle_) + obj.transform.position.y; transform.position = new Vector3(x, y, z); //カメラの位置計算 x = (radius + Camera_radius) * Mathf.Sin(angle_) + obj.transform.position.x; z = zPosition + obj.transform.position.z; y = (radius + Camera_radius) * Mathf.Cos(angle_) + obj.transform.position.y; camera.transform.position = new Vector3(x, y, z); } }
//Rockからよう 移動 成功ならtrue失敗ならfalse public bool RockMoveM(o_Rock rockA /*, int col*/, int row, o_RockManager.MOVE caseNum) { int[] adr = new int[2] { 0, 0 }; //Rockの位置検索 for (int listNum = 0; listNum < rocksCol; listNum++) { if (rockA.EqualsRocksPos(list_rocksR[listNum][row])) { adr[0] = (int)MOVE.RIGHT; adr[1] = listNum; break; } else if (rockA.EqualsRocksPos(list_rocksL[listNum][row])) { adr[0] = (int)MOVE.LEFT; adr[1] = listNum; break; } } //移動先岩マネージャー o_RockManager moveToRockManager = this; //移動先用アドレス int[] adr2 = { adr[0], adr[1], row }; //移動先調整 switch (caseNum) { case MOVE.UP: adr2[1]--; if (adr2[1] < 0) { adr2[1]++; if (adr[0] == (int)MOVE.RIGHT) { adr2[0] = (int)MOVE.LEFT; } else { adr2[0] = (int)MOVE.RIGHT; } } break; case MOVE.DOWN: adr2[1]++; if (adr2[1] >= rocksCol) { adr2[1]--; if (adr[0] == (int)MOVE.RIGHT) { adr2[0] = (int)MOVE.LEFT; } else { adr2[0] = (int)MOVE.RIGHT; } } break; case MOVE.FRONT: adr2[2]--; if (adr2[2] < 0) { if (moveToRockManager.frontRM == null) { return(false); } moveToRockManager = moveToRockManager.frontRM; adr2[2] = moveToRockManager.rocksRow - 1; } break; case MOVE.BACK: adr2[2]++; if (adr2[2] >= rocksRow) { if (moveToRockManager.backRM == null) { return(false); } moveToRockManager = moveToRockManager.backRM; adr2[2] = 0; } break; default: break; } //Debug.Log("adr2:" + adr2[0] + adr2[1] + adr2[2]); //移動 成功ならtrue失敗ならfalse switch (adr2[0]) { case (int)MOVE.RIGHT: //移動先が空なら突っ込む if (moveToRockManager.list_rocksR[adr2[1]][adr2[2]] == null) { moveToRockManager.list_rocksR[adr2[1]][adr2[2]] = rockA; if (!rockA.GetOffRock()) { if (adr[0] == (int)MOVE.RIGHT) { list_rocksR[adr[1]][row] = null; } else { list_rocksL[adr[1]][row] = null; } } else { if (adr[0] == (int)MOVE.RIGHT) { list_rocksR[adr[1]][row].CalcMass(); } else { list_rocksL[adr[1]][row].CalcMass(); } } } //移動先にあるなら乗せる else if (moveToRockManager.list_rocksR[adr2[1]][adr2[2]].RideRock(rockA)) { if (adr[0] == (int)MOVE.RIGHT) { if (rockA.Equals(list_rocksR[adr[1]][row])) { list_rocksR[adr[1]][row] = null; } else { list_rocksR[adr[1]][row].CalcMass(); } } else { if (rockA.Equals(list_rocksL[adr[1]][row])) { list_rocksL[adr[1]][row] = null; } else { list_rocksL[adr[1]][row].CalcMass(); } } } else { //乗せるのに失敗したらfalse return(false); } // rockA.Move(moveToRockManager, (MOVE)adr2[0], adr2[1], adr2[2], CalcMoveToPosition(adr2[0], adr2[1], adr2[2])); moveToRockManager.list_rocksR[adr2[1]][adr2[2]].CalcMass(); CalcMassRL(); return(true); break; case (int)MOVE.LEFT: if (moveToRockManager.list_rocksL[adr2[1]][adr2[2]] == null) { moveToRockManager.list_rocksL[adr2[1]][adr2[2]] = rockA; if (!rockA.GetOffRock()) { if (adr[0] == (int)MOVE.RIGHT) { list_rocksR[adr[1]][row] = null; } else { list_rocksL[adr[1]][row] = null; } } else { if (adr[0] == (int)MOVE.RIGHT) { list_rocksR[adr[1]][row].CalcMass(); } else { list_rocksL[adr[1]][row].CalcMass(); } } } else if (moveToRockManager.list_rocksL[adr2[1]][adr2[2]].RideRock(rockA)) { if (adr[0] == (int)MOVE.RIGHT) { if (rockA.Equals(list_rocksR[adr[1]][row])) { list_rocksR[adr[1]][row] = null; } else { list_rocksR[adr[1]][row].CalcMass(); } } else { if (rockA.Equals(list_rocksL[adr[1]][row])) { list_rocksL[adr[1]][row] = null; } else { list_rocksL[adr[1]][row].CalcMass(); } } } else { //乗せるのに失敗したらfalse return(false); } rockA.Move(moveToRockManager, (MOVE)adr2[0], adr2[1], adr2[2], CalcMoveToPosition(adr2[0], adr2[1], adr2[2])); moveToRockManager.list_rocksL[adr2[1]][adr2[2]].CalcMass(); CalcMassRL(); return(true); break; } return(false); }