// Te enseña el camino hasta el candy public void showPath() { for (int i = 0; i < path_.Count - 1; i++) { Vector3 holi = path_[i].transform.position - path_[i + 1].transform.position; Casilla cel = Instantiate(flechaPrefab, new Vector3(path_[i].transform.position.x, (float)0.3, path_[i].transform.position.z), Quaternion.identity.normalized); if (holi.x == 0 && holi.z > 0) { cel.transform.Rotate(new Vector3(0, 0, 0), Space.Self); } else if (holi.x < 0 && holi.z == 0) { cel.transform.Rotate(new Vector3(0, -90, 0), Space.Self); } else if (holi.x == 0 && holi.z < 0) { cel.transform.Rotate(new Vector3(0, 180, 0), Space.Self); } else if (holi.x > 0 && holi.z == 0) { cel.transform.Rotate(new Vector3(0, 90, 0), Space.Self); } cel.Init(this, 7); flechas_.Add(cel); } }
//Elimina el candy actual y lo sustituye por una casilla pisable cualquiera private void deleteLastCandy() { Casilla cel = null; switch (UnityEngine.Random.Range(0, 3)) { case 0: //Creamos un suelo cel = Instantiate(sueloPrefab, new Vector3(-((casillas_.GetLength(1) / 2.0f) * POSITION_FACTOR_C - (POSITION_FACTOR_C / 2.0f)) + candy_.pos.GetColumn() * POSITION_FACTOR_C, 0, (casillas_.GetLength(0) / 2.0f) * POSITION_FACTOR_R - (POSITION_FACTOR_R / 2.0f) - candy_.pos.GetRow() * POSITION_FACTOR_R), Quaternion.identity); cel.pos = candy_.pos; cel.Init(this, 0); break; case 1: //Creamos un agua cel = Instantiate(aguaPrefab, new Vector3(-((casillas_.GetLength(1) / 2.0f) * POSITION_FACTOR_C - (POSITION_FACTOR_C / 2.0f)) + candy_.pos.GetColumn() * POSITION_FACTOR_C, 0, (casillas_.GetLength(0) / 2.0f) * POSITION_FACTOR_R - (POSITION_FACTOR_R / 2.0f) - candy_.pos.GetRow() * POSITION_FACTOR_R), Quaternion.identity); cel.pos = candy_.pos; cel.Init(this, 1); break; case 2: //Creamos un barro cel = Instantiate(barroPrefab, new Vector3(-((casillas_.GetLength(1) / 2.0f) * POSITION_FACTOR_C - (POSITION_FACTOR_C / 2.0f)) + candy_.pos.GetColumn() * POSITION_FACTOR_C, 0, (casillas_.GetLength(0) / 2.0f) * POSITION_FACTOR_R - (POSITION_FACTOR_R / 2.0f) - candy_.pos.GetRow() * POSITION_FACTOR_R), Quaternion.identity); cel.pos = candy_.pos; cel.Init(this, 2); break; default: break; } if (cel != null) { Destroy(casillas_[candy_.pos.GetRow(), candy_.pos.GetColumn()].gameObject); casillas_[cel.pos.GetRow(), cel.pos.GetColumn()] = cel; } }
//--------------------------------Privates-------------------- //Crea un candy en la posicion de la casilla que le pasas private void createCandy(Casilla c) { if (candy_ != null) { deleteLastCandy(); } Casilla cel = Instantiate(banderaPrefab, new Vector3(-((casillas_.GetLength(1) / 2.0f) * POSITION_FACTOR_C - (POSITION_FACTOR_C / 2.0f)) + c.pos.GetColumn() * POSITION_FACTOR_C, 0, (casillas_.GetLength(0) / 2.0f) * POSITION_FACTOR_R - (POSITION_FACTOR_R / 2.0f) - c.pos.GetRow() * POSITION_FACTOR_R), Quaternion.identity.normalized); cel.transform.Rotate(0, 180, 0, Space.Self); cel.pos = c.pos; cel.Init(this, 4); cel.candy_ = true; setCandy(cel); Destroy(casillas_[c.pos.GetRow(), c.pos.GetColumn()].gameObject); //Borramos la casilla a cambiar casillas_[cel.pos.GetRow(), cel.pos.GetColumn()] = cel; //Asignamos la nueva casilla }
//Seleccionar una casilla con Candy (Solo se usa en el init de game manager para colocar la primera casilla) public void GiveCandy(uint r, uint c) { Casilla cell = casillas_[r, c]; if (cell != null) { cell = null; Destroy(casillas_[r, c].gameObject); } cell = Instantiate(candyPrefab, new Vector3(-((casillas_.GetLength(1) / 2.0f) * POSITION_FACTOR_C - (POSITION_FACTOR_C / 2.0f)) + c * POSITION_FACTOR_C, 0, (casillas_.GetLength(0) / 2.0f) * POSITION_FACTOR_R - (POSITION_FACTOR_R / 2.0f) - r * POSITION_FACTOR_R), Quaternion.identity); cell.candy_ = true; Position pos = new Position(r, c); cell.pos = pos; cell.Init(this, 4); setCandy(cell); casillas_[r, c] = cell; }
// Generador de casillas private void GenerateCasillas(Map m) { if (m == null) { throw new ArgumentNullException(nameof(m)); } var rows = casillas_.GetLength(0); var cols = casillas_.GetLength(1); for (var r = 0u; r < rows; r++) { for (var c = 0u; c < cols; c++) { //Creamos la casilla en una row y col del vector de casillas Casilla cel = casillas_[r, c]; // Le damos esa row y col como posicion Position pos = new Position(r, c); uint value = m.GetValue(pos); if (cel == null) { switch (value) { //Suelo case 0: cel = Instantiate(sueloPrefab, new Vector3(-((casillas_.GetLength(1) / 2.0f) * POSITION_FACTOR_C - (POSITION_FACTOR_C / 2.0f)) + c * POSITION_FACTOR_C, 0, (casillas_.GetLength(0) / 2.0f) * POSITION_FACTOR_R - (POSITION_FACTOR_R / 2.0f) - r * POSITION_FACTOR_R), Quaternion.identity); break; //Agua case 1: cel = Instantiate(aguaPrefab, new Vector3(-((casillas_.GetLength(1) / 2.0f) * POSITION_FACTOR_C - (POSITION_FACTOR_C / 2.0f)) + c * POSITION_FACTOR_C, 0, (casillas_.GetLength(0) / 2.0f) * POSITION_FACTOR_R - (POSITION_FACTOR_R / 2.0f) - r * POSITION_FACTOR_R), Quaternion.identity); break; //Barro case 2: cel = Instantiate(barroPrefab, new Vector3(-((casillas_.GetLength(1) / 2.0f) * POSITION_FACTOR_C - (POSITION_FACTOR_C / 2.0f)) + c * POSITION_FACTOR_C, 0, (casillas_.GetLength(0) / 2.0f) * POSITION_FACTOR_R - (POSITION_FACTOR_R / 2.0f) - r * POSITION_FACTOR_R), Quaternion.identity); break; //Muro case 3: cel = Instantiate(muroPrefab, new Vector3(-((casillas_.GetLength(1) / 2.0f) * POSITION_FACTOR_C - (POSITION_FACTOR_C / 2.0f)) + c * POSITION_FACTOR_C, 0, (casillas_.GetLength(0) / 2.0f) * POSITION_FACTOR_R - (POSITION_FACTOR_R / 2.0f) - r * POSITION_FACTOR_R), Quaternion.identity); break; //Default default: cel = Instantiate(sueloPrefab, new Vector3(-((casillas_.GetLength(1) / 2.0f) * POSITION_FACTOR_C - (POSITION_FACTOR_C / 2.0f)) + c * POSITION_FACTOR_C, 0, (casillas_.GetLength(0) / 2.0f) * POSITION_FACTOR_R - (POSITION_FACTOR_R / 2.0f) - r * POSITION_FACTOR_R), Quaternion.identity); break; } cel.pos = pos; cel.Init(this, value); casillas_[r, c] = cel; } } } }