public myDividedArea(Vector2 iFirstBorder, Vector2 iEndBorder, myDividedArea iLinkToFather, myDividerType iNextType, int iNumberOfRandSamples) { m_divider_type = iNextType; mFirstBorder = iFirstBorder; mEndBorder = iEndBorder; mLinkToFather = iLinkToFather; //mLeftChild = null; //mRightChild = null; numberOfRandSamples = iNumberOfRandSamples; }
//public GameObject[] EnemyInfo; //ArrayList myEnemies; //public int EnemyNumbers = 5; //public int numberOfFollowingEnemies = 0; ////Add a selection of enemies randomized //void initialization() /////////////////////////////////////////////////////////////////////Do everything related to the level here: initialization for level //{ // int mLevel = Application.loadedLevel; // myEnemies = new ArrayList(); // for (int i = 0; i < EnemyNumbers; i++) // { // int random = UnityEngine.Random.Range(0, EnemyInfo.Length); // GameObject newEnemy = Instantiate(EnemyInfo[random]) as GameObject; // newEnemy.name = "Enemy" + i.ToString(); // EnemyScript mEnemy_i_script = newEnemy.GetComponent<EnemyScript>(); // mEnemy_i_script.setEnemyType(EnemyScript.myEnemyType.NotFollowingPlayer); // mEnemy_i_script.Enemy_ith_Place = i; // if (numberOfFollowingEnemies > 0) // { // newEnemy.GetComponent<EnemyScript>().setEnemyType(EnemyScript.myEnemyType.FollowingPlayer); // numberOfFollowingEnemies--; // } // myEnemies.Add(newEnemy); // } //} // Use this for initialization void Start() { //initialization(); //Automatically set N, M and Plane // N = GetComponent<Playground>().width; // M = GetComponent<Playground>().height; myAreaDivider = new myDividedArea(new Vector2(1, 1), new Vector2(N - 2, M - 2), numberOfRandSamples); initializing_Map(N, M); myAreaDivider.myDivideAreaFunc(myMap, myAreaDivider); myWriteMap(); myGameObjects = new ArrayList(); Transform mPlane_Transform = this.transform; Vector3 plane_3d_size = 10 * mPlane_Transform.localScale; grid_size = new Vector3(plane_3d_size[0] / (float)N, 0.5f, plane_3d_size[2] / (float)M); first_cube_location = mPlane_Transform.localPosition - new Vector3(plane_3d_size[0] / 2, 0f, plane_3d_size[2] / 2) + new Vector3(plane_3d_size[0] / (2 * N), 0f, plane_3d_size[2] / (2 * M)); myCreateScene(grid_size, first_cube_location); }
public void myDivideAreaFunc(ArrayList iMap, myDividedArea iSubArea) { int started_empty_poses = 0; int end_empty_poses = 0; if (iSubArea.mFirstBorder[0] == iSubArea.mEndBorder[0] || iSubArea.mFirstBorder[1] == iSubArea.mEndBorder[1]) return; ArrayList setEmptyPoses = new ArrayList(); int x_sample = 0; int y_sample = 0; myDividerType next_type; Vector2 left_child_boundary_start; Vector2 left_child_boundary_end; Vector2 right_child_boundary_start; Vector2 right_child_boundary_end; if (iSubArea.m_divider_type == myDividerType.X)//take the first sample to divide X, other samples to place holes on X walls { x_sample = UnityEngine.Random.Range((int) iSubArea.mFirstBorder[0] + 1, (int) iSubArea.mEndBorder[0] - 1 + 1); //for placing holes in the wall started_empty_poses = (int) iSubArea.mFirstBorder[1]; end_empty_poses = (int) iSubArea.mEndBorder[1]; if (getMapVal(iMap, x_sample, started_empty_poses - 1) == 0) { setEmptyPoses.Add(new Vector2(x_sample, started_empty_poses)); } if (getMapVal(iMap, x_sample, end_empty_poses + 1) == 0) { setEmptyPoses.Add(new Vector2(x_sample, end_empty_poses)); } y_sample = started_empty_poses; for (int j = 0; j < numberOfRandSamples; j++) { y_sample = UnityEngine.Random.Range(started_empty_poses, end_empty_poses + 1); setEmptyPoses.Add(new Vector2(x_sample, y_sample)); } next_type = myDividerType.Y; left_child_boundary_start = new Vector2(iSubArea.mFirstBorder[0], iSubArea.mFirstBorder[1]); if (x_sample - 1 >= iSubArea.mFirstBorder[0]) left_child_boundary_end = new Vector2(x_sample - 1, iSubArea.mEndBorder[1]); else left_child_boundary_end = new Vector2(iSubArea.mFirstBorder[0], iSubArea.mEndBorder[1]); if (x_sample + 1 <= iSubArea.mEndBorder[0]) right_child_boundary_start = new Vector2(x_sample + 1, iSubArea.mFirstBorder[1]); else right_child_boundary_start = new Vector2(iSubArea.mEndBorder[0], iSubArea.mFirstBorder[1]); right_child_boundary_end = new Vector2(iSubArea.mEndBorder[0], iSubArea.mEndBorder[1]); } else { y_sample = UnityEngine.Random.Range((int) iSubArea.mFirstBorder[1] + 1, (int) iSubArea.mEndBorder[1] - 1 + 1); //for placing holes in the wall started_empty_poses = (int) iSubArea.mFirstBorder[0]; end_empty_poses = (int) iSubArea.mEndBorder[0]; if (getMapVal(iMap, started_empty_poses - 1, y_sample) == 0) { setEmptyPoses.Add(new Vector2(started_empty_poses, y_sample)); } if (getMapVal(iMap, end_empty_poses + 1, y_sample) == 0) { setEmptyPoses.Add(new Vector2(end_empty_poses, y_sample)); } x_sample = started_empty_poses; for (int j = 0; j < numberOfRandSamples; j++) { x_sample = UnityEngine.Random.Range(started_empty_poses, end_empty_poses + 1); setEmptyPoses.Add(new Vector2(x_sample, y_sample)); } next_type = myDividerType.X; left_child_boundary_start = new Vector2(iSubArea.mFirstBorder[0], iSubArea.mFirstBorder[1]); if (y_sample - 1 >= iSubArea.mFirstBorder[1]) left_child_boundary_end = new Vector2(iSubArea.mEndBorder[0], y_sample - 1); else left_child_boundary_end = new Vector2(iSubArea.mEndBorder[0], iSubArea.mFirstBorder[1]); if (y_sample + 1 <= iSubArea.mEndBorder[1]) right_child_boundary_start = new Vector2(iSubArea.mFirstBorder[0], y_sample + 1); else right_child_boundary_start = new Vector2(iSubArea.mFirstBorder[0], iSubArea.mEndBorder[1]); right_child_boundary_end = new Vector2(iSubArea.mEndBorder[0], iSubArea.mEndBorder[1]); } myMakeWall(iMap, new Vector2(x_sample, y_sample), iSubArea.m_divider_type, setEmptyPoses, iSubArea.mFirstBorder, iSubArea.mEndBorder); myDividedArea left_divided_area = new myDividedArea(left_child_boundary_start, left_child_boundary_end, this, next_type, numberOfRandSamples); myDividedArea right_divided_area = new myDividedArea(right_child_boundary_start, right_child_boundary_end, this, next_type, numberOfRandSamples); myDivideAreaFunc(iMap, left_divided_area); myDivideAreaFunc(iMap, right_divided_area); return; }
public myDividedArea(Vector2 iFirstBorder, Vector2 iEndBorder, myDividedArea iLinkToFather, myDividerType iNextType) { m_divider_type = iNextType; mFirstBorder = iFirstBorder; mEndBorder = iEndBorder; mLinkToFather = iLinkToFather; //mLeftChild = null; //mRightChild = null; }
public myDividedArea(Vector2 iFirstBorder, Vector2 iEndBorder) { m_divider_type = myDividerType.X; mFirstBorder = iFirstBorder; mEndBorder = iEndBorder; mLinkToFather = null; //mLeftChild = null; //mRightChild = null; }
// Use this for initialization void Start() { myAreaDivider = new myDividedArea(new Vector2(1, 1), new Vector2(N - 2, M - 2)); initializing_Map(N, M); myAreaDivider.myDivideAreaFunc(myMap, myAreaDivider); myWriteMap(); myGameObjects = new ArrayList(); RectTransform plane_transform = plane.GetComponent<RectTransform>(); Vector2 plane_2d_size = plane_transform.sizeDelta; myCreateScene(new Vector3(plane_2d_size[0] / N, plane_2d_size[1] / M, 0.5f), plane_transform.transform.position - new Vector3(plane_2d_size[0]/2, plane_2d_size[1]/2, 0f) + new Vector3(plane_2d_size[0] / (2*N), plane_2d_size[1] / (2*M), 0f)); }
public void myDivideAreaFunc(ArrayList iMap, myDividedArea iSubArea) { int started_empty_poses = 0; int end_empty_poses = 0; if (iSubArea.mFirstBorder[0] == iSubArea.mEndBorder[0] || iSubArea.mFirstBorder[1] == iSubArea.mEndBorder[1]) { return; } ArrayList setEmptyPoses = new ArrayList(); int x_sample = 0; int y_sample = 0; myDividerType next_type; Vector2 left_child_boundary_start; Vector2 left_child_boundary_end; Vector2 right_child_boundary_start; Vector2 right_child_boundary_end; if (iSubArea.m_divider_type == myDividerType.X)//take the first sample to divide X, other samples to place holes on X walls { x_sample = UnityEngine.Random.Range((int)iSubArea.mFirstBorder[0] + 1, (int)iSubArea.mEndBorder[0] - 1 + 1); //for placing holes in the wall started_empty_poses = (int)iSubArea.mFirstBorder[1]; end_empty_poses = (int)iSubArea.mEndBorder[1]; if (getMapVal(iMap, x_sample, started_empty_poses - 1) == 0) { setEmptyPoses.Add(new Vector2(x_sample, started_empty_poses)); } if (getMapVal(iMap, x_sample, end_empty_poses + 1) == 0) { setEmptyPoses.Add(new Vector2(x_sample, end_empty_poses)); } y_sample = started_empty_poses; for (int j = 0; j < numberOfRandSamples; j++) { y_sample = UnityEngine.Random.Range(started_empty_poses, end_empty_poses + 1); setEmptyPoses.Add(new Vector2(x_sample, y_sample)); } next_type = myDividerType.Y; left_child_boundary_start = new Vector2(iSubArea.mFirstBorder[0], iSubArea.mFirstBorder[1]); if (x_sample - 1 >= iSubArea.mFirstBorder[0]) { left_child_boundary_end = new Vector2(x_sample - 1, iSubArea.mEndBorder[1]); } else { left_child_boundary_end = new Vector2(iSubArea.mFirstBorder[0], iSubArea.mEndBorder[1]); } if (x_sample + 1 <= iSubArea.mEndBorder[0]) { right_child_boundary_start = new Vector2(x_sample + 1, iSubArea.mFirstBorder[1]); } else { right_child_boundary_start = new Vector2(iSubArea.mEndBorder[0], iSubArea.mFirstBorder[1]); } right_child_boundary_end = new Vector2(iSubArea.mEndBorder[0], iSubArea.mEndBorder[1]); } else { y_sample = UnityEngine.Random.Range((int)iSubArea.mFirstBorder[1] + 1, (int)iSubArea.mEndBorder[1] - 1 + 1); //for placing holes in the wall started_empty_poses = (int)iSubArea.mFirstBorder[0]; end_empty_poses = (int)iSubArea.mEndBorder[0]; if (getMapVal(iMap, started_empty_poses - 1, y_sample) == 0) { setEmptyPoses.Add(new Vector2(started_empty_poses, y_sample)); } if (getMapVal(iMap, end_empty_poses + 1, y_sample) == 0) { setEmptyPoses.Add(new Vector2(end_empty_poses, y_sample)); } x_sample = started_empty_poses; for (int j = 0; j < numberOfRandSamples; j++) { x_sample = UnityEngine.Random.Range(started_empty_poses, end_empty_poses + 1); setEmptyPoses.Add(new Vector2(x_sample, y_sample)); } next_type = myDividerType.X; left_child_boundary_start = new Vector2(iSubArea.mFirstBorder[0], iSubArea.mFirstBorder[1]); if (y_sample - 1 >= iSubArea.mFirstBorder[1]) { left_child_boundary_end = new Vector2(iSubArea.mEndBorder[0], y_sample - 1); } else { left_child_boundary_end = new Vector2(iSubArea.mEndBorder[0], iSubArea.mFirstBorder[1]); } if (y_sample + 1 <= iSubArea.mEndBorder[1]) { right_child_boundary_start = new Vector2(iSubArea.mFirstBorder[0], y_sample + 1); } else { right_child_boundary_start = new Vector2(iSubArea.mFirstBorder[0], iSubArea.mEndBorder[1]); } right_child_boundary_end = new Vector2(iSubArea.mEndBorder[0], iSubArea.mEndBorder[1]); } myMakeWall(iMap, new Vector2(x_sample, y_sample), iSubArea.m_divider_type, setEmptyPoses, iSubArea.mFirstBorder, iSubArea.mEndBorder); myDividedArea left_divided_area = new myDividedArea(left_child_boundary_start, left_child_boundary_end, this, next_type, numberOfRandSamples); myDividedArea right_divided_area = new myDividedArea(right_child_boundary_start, right_child_boundary_end, this, next_type, numberOfRandSamples); myDivideAreaFunc(iMap, left_divided_area); myDivideAreaFunc(iMap, right_divided_area); return; }