void ReuseRemovedFood(FoodItems _food) { // After drop down the foods, there is hole at the top, fill it up with the food we removed and give it a new food type from prefab int foodType = Random.Range(0, foodPrefabs.Length); _food.rowIndex = (int)Def.rowCount; _food.CreateFood(foodType, foodPrefabs[foodType]); // Put it at the top frist _food.UpdatePosition(_food.rowIndex, _food.columIndex); // Drop it down slowly _food.rowIndex--; SetFoodItem(_food.rowIndex, _food.columIndex, _food); _food.UpdatePosition(_food.rowIndex, _food.columIndex, true); }
FoodItems AddRandomFoodItem(int _rowIndex, int _columIndex) { // Spawn a gameobject under the foodSpawner int foodType = Random.Range(0, foodPrefabs.Length); GameObject item = new GameObject("Item"); item.transform.SetParent(foodSpawner, false); // Give the new spawned gameobject a boxcollider2d and the fooditems.cs we made item.AddComponent <BoxCollider2D>().size = Vector2.one * Def.cellSize; FoodItems fooditems = item.AddComponent <FoodItems>(); // Give the new spawned a new position and image var its row and colum and prefab fooditems.UpdatePosition(_rowIndex, _columIndex); fooditems.CreateFood(foodType, foodPrefabs[foodType]); return(fooditems); }
void DropDownNewFood() { // Loop all the holes in the game from match food arraylist for (int i = 0; i < matchFoods.Count; i++) { FoodItems food = matchFoods[i] as FoodItems; // Drop down the food that theres a hole below it for (int j = food.rowIndex + 1; j < Def.rowCount; j++) { FoodItems dropDownFood = GetFoodItems(j, food.columIndex); dropDownFood.rowIndex--; SetFoodItem(dropDownFood.rowIndex, dropDownFood.columIndex, dropDownFood); dropDownFood.UpdatePosition(dropDownFood.rowIndex, dropDownFood.columIndex, true); } ReuseRemovedFood(food); } }
void Exchange(FoodItems _item1, FoodItems _item2) { // Get the two food we want to exchange, get there row and colum. SetFoodItem(_item1.rowIndex, _item1.columIndex, _item2); SetFoodItem(_item2.rowIndex, _item2.columIndex, _item1); // Exchange there row and colum index int tmp = 0; tmp = _item1.rowIndex; _item1.rowIndex = _item2.rowIndex; _item2.rowIndex = tmp; tmp = _item1.columIndex; _item1.columIndex = _item2.columIndex; _item2.columIndex = tmp; // Exchange there position var index _item1.UpdatePosition(_item1.rowIndex, _item1.columIndex, true); _item2.UpdatePosition(_item2.rowIndex, _item2.columIndex, true); // Clear the cuurentSelectFood currentSelectFood = null; }