void Start_gem_fall()//call from "board_C.turnMovement.Start_update_board()" { if ((number_of_gems_to_move > 0) || (number_of_new_gems_to_create > 0)) { gem_falling_ongoing = true; for (int y = _Y_tiles - 1; y >= 0; y--) { for (int x = 0; x < _X_tiles; x++) { if (board_array_master[x, y, 0] > -1)//if there is a tile { //search free tiles if ((board_array_master[x, y, 1] == -99) && //if this tile is empty (board_array_master[x, y, 13] <= 0)) //and not yet checked { tile_C tile_script = (tile_C)tiles_array[x, y]; tile_script.Make_fall_all_free_gems_over_this_empty_tile(); } } } } } else { if (!gem_falling_ongoing) { Check_ALL_possible_moves(); } } }
void Move_gems_to_target_positions() //call from Switch_gem( or from Update_board_by_one_step( { //Debug.Log("Move_gems_to_target_positions()"); int temp_main_bonus = 0; int temp_minor_bonus = 0; //update color in array board_array_master[main_gem_selected_x, main_gem_selected_y, 1] = minor_gem_color; board_array_master[minor_gem_destination_to_x, minor_gem_destination_to_y, 1] = main_gem_color; //update bonus position temp_main_bonus = board_array_master[main_gem_selected_x, main_gem_selected_y, 4]; temp_minor_bonus = board_array_master[minor_gem_destination_to_x, minor_gem_destination_to_y, 4]; board_array_master[main_gem_selected_x, main_gem_selected_y, 4] = temp_minor_bonus; board_array_master[minor_gem_destination_to_x, minor_gem_destination_to_y, 4] = temp_main_bonus; //update gem representation tile_C tile_script_main_gem = tiles_array[main_gem_selected_x, main_gem_selected_y]; tile_C tile_script_minor_gem = tiles_array[minor_gem_destination_to_x, minor_gem_destination_to_y]; tile_script_main_gem.my_gem = avatar_minor_gem; tile_script_minor_gem.my_gem = avatar_main_gem; SetSwitchGemAnimation(tile_script_main_gem, tile_script_minor_gem); }
void Search_last_empty_tile_under_me() { for (int yy = 1; (_y + yy) <= board._Y_tiles - 1; yy++)//scan tiles under me { if ((board.board_array_master[_x, (_y + yy), 0] == -1) || //if I find no tile (board.board_array_master[_x, _y + yy, 1] >= 0)) //or a tile with something { //move the gem on the tile next up the last tile scanned board.board_array_master[_x, _y + yy - 1, 1] = board.board_array_master[_x, _y, 1]; //color from old tile position board.board_array_master[_x, _y, 1] = -99; //special board.board_array_master[_x, _y + yy - 1, 4] = board.board_array_master[_x, _y, 4]; board.board_array_master[_x, _y, 4] = 0; //the gem go in the new tile position board.board_array_master[_x, _y + yy - 1, 10] = 1; //empty the old tile position board.board_array_master[_x, _y, 10] = 0; //show the falling animation tile_C tile_script = (tile_C)board.tiles_array[_x, (_y + yy - 1)]; tile_script.my_gem = my_gem; tile_script.my_gem_renderer = tile_script.my_gem.GetComponent <SpriteRenderer>(); tile_script.Update_gem_position(); my_gem = null; break; } else if ((_y + yy) == board._Y_tiles - 1) //if I'm on the last row { //move gem color on last tile board.board_array_master[_x, _y + yy, 1] = board.board_array_master[_x, _y, 1]; //remove color from old tile board.board_array_master[_x, _y, 1] = -99; //special board.board_array_master[_x, _y + yy - 1, 4] = board.board_array_master[_x, _y, 4]; board.board_array_master[_x, _y, 4] = 0; //gem go in the new position board.board_array_master[_x, _y + yy, 10] = 1; //empty the old tile board.board_array_master[_x, _y, 10] = 0; //show falling animation tile_C tile_script = (tile_C)board.tiles_array[_x, (_y + yy)]; tile_script.my_gem = my_gem; tile_script.my_gem_renderer = tile_script.my_gem.GetComponent <SpriteRenderer>(); my_gem = null; tile_script.my_gem.transform.parent = tile_script.transform; tile_script.Update_gem_position(); break; } } }
//shuffle gems when no move available void Shuffle()//call from Check_ALL_possible_moves() { if (!shuffle_ongoing) { if (!ShuffleSafetuCheck())//not safe { return; } shuffle_ongoing = true; //Debug.Log("shuffle"); for (int y = 0; y < _Y_tiles; y++) { for (int x = 0; x < _X_tiles; x++) { if ((board_array_master[x, y, 1] >= 0) && (board_array_master[x, y, 1] < 9) && //there is a gem (board_array_master[x, y, 3] == 0)) //and without padlock { number_of_gems_to_mix++; board_array_master[x, y, 1] = UnityEngine.Random.Range(0, gem_length); board_array_master[x, y, 4] = 0; //reset bonus Avoid_triple_color_gem(x, y); //update gem tile_C tile_script = (tile_C)tiles_array[x, y]; tile_script.SetShuffleUpdate(); } } } } }
void Destroy_gem_avatar() { //Debug.Log("--------------- Destroy_gem_avatar() START! x = " + _x + ", y = " + _y); board.Add_time_bonus(board.time_bonus_for_gem_explosion); if (board.explosions_damages_tiles) { Update_tile_hp(); } //damage adjacent blocks if ((_y + 1 < board._Y_tiles) && (board.board_array_master[_x, _y + 1, 14] > 0)) { board.number_of_elements_to_damage++; tile_C script_target_block = (tile_C)board.tiles_array[_x, _y + 1]; script_target_block.Damage_block(); } if ((_y - 1 >= 0) && (board.board_array_master[_x, _y - 1, 14] > 0)) { board.number_of_elements_to_damage++; tile_C script_target_block = (tile_C)board.tiles_array[_x, _y - 1]; script_target_block.Damage_block(); } if ((_x + 1 < board._X_tiles) && (board.board_array_master[_x + 1, _y, 14] > 0)) { board.number_of_elements_to_damage++; tile_C script_target_block = (tile_C)board.tiles_array[_x + 1, _y]; script_target_block.Damage_block(); } if ((_x - 1 >= 0) && (board.board_array_master[_x - 1, _y, 14] > 0)) { board.number_of_elements_to_damage++; tile_C script_target_block = (tile_C)board.tiles_array[_x - 1, _y]; script_target_block.Damage_block(); } blink_time = Time.realtimeSinceStartup; my_gem_renderer = my_gem.GetComponent <SpriteRenderer>(); SetDestroyAnimation(); if (board.play_this_bonus_sfx == -1)//you don't play sound explosion fx if you must play a bonus sfx #if UNITY_WEBGL { board.Play_sfx(board.explosion_sfx_str); } #else { board.Play_sfx(board.explosion_sfx); } #endif //Debug.Log("--------------- Destroy_gem_avatar() END! x = " + _x + ", y = " + _y); }
public void SetEndBadSwitchAnimation() { isEndBadSwitchAnimation = true; tileMain = tiles_array[main_gem_selected_x, main_gem_selected_y]; tileMinor = tiles_array[minor_gem_destination_to_x, minor_gem_destination_to_y]; displacementMain = tileMain.my_gem.transform.position - avatar_main_gem.transform.position; displacementMinor = tileMinor.my_gem.transform.position - avatar_minor_gem.transform.position; directionMain = displacementMain.normalized; directionMinor = displacementMinor.normalized; }
void SetSwitchGemAnimation(tile_C main_tile, tile_C minor_tile) { isSwitchGemAnimation = true; tileMain = main_tile; tileMinor = minor_tile; displacementMain = main_tile.transform.position - main_tile.my_gem.transform.position; displacementMinor = minor_tile.transform.position - minor_tile.my_gem.transform.position; directionMain = displacementMain.normalized; directionMinor = displacementMinor.normalized; }
void Gems_teleport() { if ((board.board_array_master[_x, _y, 1] >= 0) && (board.board_array_master[_x, _y, 1] < 9)) //is a gem { if (board.board_array_master[_x, _y, 3] == 0) //no padlock { if (board.main_gem_selected_x == -10) //select first gem { board.main_gem_selected_x = _x; board.main_gem_selected_y = _y; board.main_gem_color = board.board_array_master[_x, _y, 1]; //Debug.Log("teleport select first gem: " + _x + "," + _y); } else //select second gem { if ((board.main_gem_selected_x == _x) && (board.main_gem_selected_y == _y)) { //you have click on the same gem, so deselect it board.main_gem_selected_x = -10; board.main_gem_selected_y = -10; board.main_gem_color = -10; } else { //board.minor_gem_destination_to_x = _x; //board.minor_gem_destination_to_y = _y; board.minor_gem_color = board.board_array_master[_x, _y, 1]; //Debug.Log("teleport select second gem: " + _x + "," + _y); //activate teleport board.number_of_gems_to_mix = 2; board.player_can_move = false; //change gems board.board_array_master[_x, _y, 1] = board.main_gem_color; board.board_array_master[board.main_gem_selected_x, board.main_gem_selected_y, 1] = board.minor_gem_color; board.Play_bonus_sfx(2); //update gem SetShuffleUpdate(); tile_C tile_script = (tile_C)board.tiles_array[board.main_gem_selected_x, board.main_gem_selected_y]; tile_script.SetShuffleUpdate(); } } } } }
void Generate_new_gems()//call from BoardUpdate() { if (gem_emitter_rule == gem_emitter.off) { number_of_new_gems_to_create = 0; return; } for (int i = 0; i < number_of_tiles_leader; i++) { if (board_array_master[tiles_leader_array[i]._x, tiles_leader_array[i]._y, 11] == 2)//creation { tile_C tile_script = (tile_C)tiles_array[tiles_leader_array[i]._x, tiles_leader_array[i]._y]; tile_script.Create_gem(); } } }
public void Show_all_token_on_board()//call from Create_new_board(), tile_C.Update_tile_hp() { if (!token_showed) { token_showed = true; for (int y = 0; y < _Y_tiles; y++) { for (int x = 0; x < _X_tiles; x++) { if (token_place_card[x, y]) { board_array_master[x, y, 1] = 9; board_array_master[x, y, 4] = -200; tile_C tile_script = (tile_C)tiles_array[x, y]; tile_script.SetShowToken(); } } } } }
void ExecuteChanges() { for (int y = _Y_tiles - 1; y >= 0; y--)//from bottom to top { for (int x = 0; x < _X_tiles; x++) { if (board_array_master[x, y, 1] < 0 || tiles_array[x, y].my_gem == null) //if no tile or no gem { continue; //skip this x,y } if (board_array_master[x, y, 11] == 1 || board_array_master[x, y, 11] == 666) //destroy { board_array_master[x, y, 11] = 111; // explosion ongoing tile_C tile_script = (tile_C)tiles_array[x, y]; tile_script.Explosion(); } else if (board_array_master[x, y, 11] >= 3 && board_array_master[x, y, 11] <= 5)//falling { tile_C tile_script = (tile_C)tiles_array[x, y]; tile_script.Fall_by_one_step(board_array_master[x, y, 11] - 3); } } } }
public void Start_update_board()//call from: tile_C.update.If_all_explosion_are_completed(), tile_C.update.Check_if_gem_movements_are_all_done() { //Debug.Log ("Start_update_board "); //if (!player_can_move_when_gem_falling) cursor.gameObject.SetActive(false); if (diagonal_falling) { //print("diagonal falling"); Check_new_gem_to_generate(); //check vertical falling for (int y = 0; y < _Y_tiles - 1; y++)//don't check last line { for (int x = 0; x < _X_tiles; x++) { if ((board_array_master[x, y, 13] == 0) && (board_array_master[x, y, 10] == 1))//this could be fall { //check if have an empty tile under if ((board_array_master[x, y + 1, 0] > -1) && (board_array_master[x, y + 1, 1] == -99)) { //vertical fall //tiles_array[x,y].GetComponent<Renderer>().material.color = Color.gray; board_array_master[x, y, 11] = 3; //vertical fall board_array_master[x, y, 13] = 1; //tile checked number_of_gems_to_move++; //all empty tiles under this gem are reserved to it for (int yy = y + 1; yy < _Y_tiles; yy++) { if ((board_array_master[x, yy, 0] > -1) && (board_array_master[x, yy, 1] == -99)) { board_array_master[x, yy, 13] = 1; //tiles_array[x,yy].GetComponent<Renderer>().material.color = Color.grey; } else { break; } } } } } } //check diagonal falling diagonal_falling_preference_direction_R = !diagonal_falling_preference_direction_R; for (int y = 0; y < _Y_tiles - 1; y++)//don't check last line { for (int x = 0; x < _X_tiles; x++) { if ((board_array_master[x, y, 13] == 0) && (board_array_master[x, y, 10] == 1))//this could be fall { { if (diagonal_falling_preference_direction_R) { Diagonal_fall_R(x, y); Diagonal_fall_L(x, y); } else { Diagonal_fall_L(x, y); Diagonal_fall_R(x, y); } } } } } //now you know what gems must be fall, so... Update_board_by_one_step(); } else //diagonal falling not allowed { //print("diagonal falling not allowed"); //read board form down to up (and left to right) for (int y = _Y_tiles - 1; y >= 0; y--) { for (int x = 0; x < _X_tiles; x++) { if ((board_array_master[x, y, 0] > -1) && (board_array_master[x, y, 13] == 0))//if there is a tile unchecked... { //...and it is empty if (board_array_master[x, y, 1] == -99) { tile_C tile_script = (tile_C)tiles_array[x, y]; tile_script.Count_how_much_gem_there_are_to_move_over_me(); } } } } //now you know what gems must be fall, so... Start_gem_fall(); } }
public void Make_fall_all_free_gems_over_this_empty_tile() { bool leader_tile_become_empty = false; bool leader_tile_become_active = false; int number_of_gems_that_fall_in_this_column = 0; for (int yy = _y; yy >= 0; yy--)//look all tiles over me { //interrupt the count if if ((board.board_array_master[_x, yy, 0] == -1) ||// no tile (board.board_array_master[_x, yy, 1] >= 0) && (board.board_array_master[_x, yy, 10] == 0)) //or this thing can't fall { break; } else //vertical falling { board.board_array_master[_x, yy, 13] = 1; //annotate this tile as checked if (board.board_array_master[_x, yy, 10] == 1) //if there is something that can fall { //update gem position //gem color go in this tile board.board_array_master[_x, _y - number_of_gems_that_fall_in_this_column, 1] = board.board_array_master[_x, yy, 1]; //cancell gem color from old starting tile board.board_array_master[_x, yy, 1] = -99; //pass special board.board_array_master[_x, _y - number_of_gems_that_fall_in_this_column, 4] = board.board_array_master[_x, yy, 4]; //cancel special board.board_array_master[_x, yy, 4] = 0; //new gem position board.board_array_master[_x, _y - number_of_gems_that_fall_in_this_column, 10] = 1; //cancell gem from old starting tile board.board_array_master[_x, yy, 10] = 0; //update falling block hp board.board_array_master[_x, _y - number_of_gems_that_fall_in_this_column, 14] = board.board_array_master[_x, yy, 14]; board.board_array_master[_x, yy, 14] = 0; //now show the gem avatar fall tile_C script_destination_tile = (tile_C)board.tiles_array[_x, (_y - number_of_gems_that_fall_in_this_column)]; tile_C script_origin_tile = (tile_C)board.tiles_array[_x, yy]; //link the avatar to new tile script_destination_tile.my_gem = script_origin_tile.my_gem; script_destination_tile.my_gem_renderer = script_destination_tile.my_gem.GetComponent <SpriteRenderer>(); //unlik the avater from the old tile script_origin_tile.my_gem = null; //Debug.Log("Make_fall_all_free_gems_over_this_empty_tile"); //Debug.Log("Origin tile x = " + _x + ", y = " + yy); //start the animation script_destination_tile.Update_gem_position(); //update gem moved count number_of_gems_that_fall_in_this_column++; //if a leader tile become empty, create a new gem if (board.board_array_master[_x, yy, 12] == 1)//if this i a leader tile { leader_tile_become_empty = true; if (board.gem_emitter_rule != Board_C.gem_emitter.off) { script_origin_tile.SetCreateFallingGem(); } else { board.number_of_new_gems_to_create = 0; } } } else if (!leader_tile_become_empty && !leader_tile_become_active) { if ((board.board_array_master[_x, yy, 1] == -99) && //this tile is empty (board.board_array_master[_x, yy, 12] == 1)) //and is a leader tile { if (board.gem_emitter_rule != Board_C.gem_emitter.off) { tile_C script_native_tile = (tile_C)board.tiles_array[_x, yy]; script_native_tile.SetCreateFallingGem(); leader_tile_become_active = true; } else { board.number_of_new_gems_to_create = 0; If_all_explosion_are_completed(); } } } } } }
public void Fall_by_one_step(int fall_direction)//0 down, 1 down R, 2 down L { //Debug.Log("Fall_by_one_step"); if (fall_direction == 0) { //move the gem on the tile next up the last tile scanned board.board_array_master[_x, _y + 1, 1] = board.board_array_master[_x, _y, 1]; //color from old tile position board.board_array_master[_x, _y, 1] = -99; //special board.board_array_master[_x, _y + 1, 4] = board.board_array_master[_x, _y, 4]; board.board_array_master[_x, _y, 4] = 0; //the gem go in the new tile position board.board_array_master[_x, _y + 1, 10] = 1; //empty the old tile position board.board_array_master[_x, _y, 10] = 0; //show the falling animation tile_C tile_script = (tile_C)board.tiles_array[_x, _y + 1]; tile_script.my_gem = my_gem; tile_script.my_gem_renderer = tile_script.my_gem.GetComponent <SpriteRenderer>(); my_gem = null; board.board_array_master[_x, _y + 1, 11] = board.board_array_master[_x, _y, 11]; board.board_array_master[_x, _y, 11] = 0; tile_script.Update_gem_position(); } else if (fall_direction == 1) { //move the gem on the tile next up the last tile scanned board.board_array_master[_x + 1, _y + 1, 1] = board.board_array_master[_x, _y, 1]; //color from old tile position board.board_array_master[_x, _y, 1] = -99; //special board.board_array_master[_x + 1, _y + 1, 4] = board.board_array_master[_x, _y, 4]; board.board_array_master[_x, _y, 4] = 0; //the gem go in the new tile position board.board_array_master[_x + 1, _y + 1, 10] = 1; //empty the old tile position board.board_array_master[_x, _y, 10] = 0; //show the falling animation tile_C tile_script = (tile_C)board.tiles_array[_x + 1, _y + 1]; tile_script.my_gem = my_gem; tile_script.my_gem_renderer = tile_script.my_gem.GetComponent <SpriteRenderer>(); my_gem = null; board.board_array_master[_x + 1, _y + 1, 11] = board.board_array_master[_x, _y, 11]; board.board_array_master[_x, _y, 11] = 0; tile_script.Update_gem_position(); } else if (fall_direction == 2) { //move the gem on the tile next up the last tile scanned board.board_array_master[_x - 1, _y + 1, 1] = board.board_array_master[_x, _y, 1]; //color from old tile position board.board_array_master[_x, _y, 1] = -99; //special board.board_array_master[_x - 1, _y + 1, 4] = board.board_array_master[_x, _y, 4]; board.board_array_master[_x, _y, 4] = 0; //the gem go in the new tile position board.board_array_master[_x - 1, _y + 1, 10] = 1; //empty the old tile position board.board_array_master[_x, _y, 10] = 0; //show the falling animation tile_C tile_script = (tile_C)board.tiles_array[_x - 1, _y + 1]; tile_script.my_gem = my_gem; tile_script.my_gem_renderer = tile_script.my_gem.GetComponent <SpriteRenderer>(); my_gem = null; board.board_array_master[_x - 1, _y + 1, 11] = board.board_array_master[_x, _y, 11]; board.board_array_master[_x, _y, 11] = 0; tile_script.Update_gem_position(); } //board.number_of_gems_to_move--; }
public void AfterSwitchAnim() { //if this move make explode something if (This_switch_will_produce_an_explosion()) { //create array to note the explosions position_of_gems_that_will_explode = new bool[2, 8]; if (Main_gem_explode()) { gems_useful_moved++; n_gems_exploded_with_main_gem++; Check_if_this_gem_have_the_same_color_of_the_gem_exploded_in_the_previous_move(board_array_master[minor_gem_destination_to_x, minor_gem_destination_to_y, 1]); Detect_which_gems_will_explode(minor_gem_destination_to_x, minor_gem_destination_to_y, 0); } else { //no color to keep track here if (player_turn) { player_previous_exploded_color[0] = -1; } else { enemy_previous_exploded_color[0] = -1; } } if (Minor_gem_explode()) { gems_useful_moved++; n_gems_exploded_with_minor_gem++; Check_if_this_gem_have_the_same_color_of_the_gem_exploded_in_the_previous_move(board_array_master[main_gem_selected_x, main_gem_selected_y, 1]); Detect_which_gems_will_explode(main_gem_selected_x, main_gem_selected_y, 1); } else { //no color to keep track here if (player_turn) { player_previous_exploded_color[1] = -1; } else { enemy_previous_exploded_color[1] = -1; } } //keep track of score if (player_turn) { if (explode_same_color_again_with > 0) { player_explode_same_color_n_turn++; } else { player_explode_same_color_n_turn = 0; } } else { if (explode_same_color_again_with > 0) { enemy_explode_same_color_n_turn++; } else { enemy_explode_same_color_n_turn = 0; } } Empty_main_and_minor_gem_selections(); } else //this move is useless (no explosions) { //...but is a good move if move a bonus with free_switch if (trigger_by_select == trigger_by.free_switch && ((board_array_master[main_gem_selected_x, main_gem_selected_y, 4] > 0) || (board_array_master[minor_gem_destination_to_x, minor_gem_destination_to_y, 4] > 0))) { //Debug.Log("free switch without main explosion"); //trigger bonus //elements_to_damage_array = new GameObject[15]; if (board_array_master[main_gem_selected_x, main_gem_selected_y, 4] > 0) { tile_C tile_script = (tile_C)tiles_array[main_gem_selected_x, main_gem_selected_y]; tile_script.Trigger_bonus(false); } if (board_array_master[minor_gem_destination_to_x, minor_gem_destination_to_y, 4] > 0) { tile_C tile_script = (tile_C)tiles_array[minor_gem_destination_to_x, minor_gem_destination_to_y]; tile_script.Trigger_bonus(false); } Empty_main_and_minor_gem_selections(); } else //is a bad move //SetStartBadSwitchAnimation(); { SetEndBadSwitchAnimation(); } } if (number_of_elements_to_damage_with_SwitchingGems + number_of_elements_to_damage_with_bonus > 0)//if there is something to explode { Cancell_hint(); if (!player_can_move_when_gem_falling) { Order_to_gems_to_explode(); } } }
void Create_new_board()//call from Awake() { //int leader_tiles_count = 0; if (show_token_after_all_tiles_are_destroyed && win_requirement_selected == win_requirement.take_all_tokens) { token_place_card = new bool[_X_tiles, _Y_tiles]; } for (int y = 0; y < _Y_tiles; y++) { for (int x = 0; x < _X_tiles; x++) { if (board_array_master[x, y, 0] > -1)//if there is a tile { Vector2 this_position = new Vector2(x + pivot_board.position.x, -y + pivot_board.position.y); //generate tile GameObject tileGO = (GameObject)Instantiate(tile_obj, this_position, Quaternion.identity); tiles_array[x, y] = tileGO.GetComponent <tile_C>(); tiles_array[x, y].name = "x:" + x + ",y:" + y; tiles_array[x, y].board = this; //tiles_array[x,y].GetComponent<tile_C>().explosion_score_script = the_gui_score_of_this_move.gameObject.GetComponent<explosion_score>(); tiles_array[x, y].transform.parent = pivot_board; total_tiles++; //search leader tiles if ((y == 0) || ((y > 0) && (board_array_master[x, y - 1, 0] == -1))) //if the tile is on the first row or don't have another tile over { board_array_master[x, y, 12] = 1; //this is a leader tile number_of_tiles_leader++; } //search bottom tiles for everi orientation: //orientation 0 = 0° if ((y == _Y_tiles - 1) || ((y < _Y_tiles - 1) && (board_array_master[x, y + 1, 0] == -1))) { number_of_bottom_tiles[0]++; } //orientation 1 = 90° if ((x == _X_tiles - 1) || ((x < _X_tiles - 1) && (board_array_master[x + 1, 1, 0] == -1))) { number_of_bottom_tiles[1]++; } //orientation 2 = 180° if ((y == 0) || ((y > 0) && (board_array_master[x, y - 1, 0] == -1))) //if the tile is on the first row or don't have another tile over { number_of_bottom_tiles[2]++; } //orientation 3 = 270° if ((x == 0) || ((x > 0) && (board_array_master[x - 1, y, 0] == -1))) //if the tile is on the first row or don't have another tile over { number_of_bottom_tiles[3]++; } } if ((board_array_master[x, y, 4] == -200) && (show_token_after_all_tiles_are_destroyed))//token { //take note of the token position and create a normal gem here number_of_token_to_collect++; token_place_card[x, y] = true; board_array_master[x, y, 4] = 0; board_array_master[x, y, 1] = 10; } if (board_array_master[x, y, 1] == 10)//if there is a random gem here { board_array_master[x, y, 1] = UnityEngine.Random.Range(0, gem_length); } if (board_array_master[x, y, 1] >= 0)//if there is something in this tile { //this thing can fall? if (board_array_master[x, y, 3] == 0) // no restraint { if ((board_array_master[x, y, 1] < 40) || //is a gem, junk or token ((board_array_master[x, y, 1] >= 51) && (board_array_master[x, y, 1] <= 59)) || // is a falling block ((board_array_master[x, y, 1] >= 70) && (board_array_master[x, y, 1] <= 79))) // is a key { board_array_master[x, y, 10] = 1; //if is junk or token: explode when reach the bottom of the board if ((board_array_master[x, y, 1] >= 20) && (board_array_master[x, y, 1] <= 39)) { board_array_master[x, y, 10] = 2; } } } } } } tiles_leader_array = new tile_C[number_of_tiles_leader];//the tiles in this array will create the falling gems int leader_tiles_count = 0; total_gems_on_board_at_start = 0; //feed bottom tiles array: //search most long bottom tile list: int temp_bottom_tiles_array_lenght = 0; for (int i = 0; i < 4; i++) { if (number_of_bottom_tiles[i] > temp_bottom_tiles_array_lenght) { temp_bottom_tiles_array_lenght = number_of_bottom_tiles[i]; } } bottom_tiles_array = new tile_C[4, temp_bottom_tiles_array_lenght]; int[] temp_bottom_tiles_array_count = new int[4]; for (int y = 0; y < _Y_tiles; y++) { for (int x = 0; x < _X_tiles; x++) { if (board_array_master[x, y, 0] > -1)//if there is a tile { Vector2 this_position = new Vector2(x + pivot_board.position.x, -y + pivot_board.position.y); Avoid_triple_color_gem(x, y); //create visual representation //the tile tile_C tile_script = (tile_C)tiles_array[x, y]; tile_script._x = x; tile_script._y = y; //and is leader... if (board_array_master[x, y, 12] == 1) { tiles_leader_array[leader_tiles_count] = tile_script; leader_tiles_count++; } //orientation 0 = 0° if ((y == _Y_tiles - 1) || ((y < _Y_tiles - 1) && (board_array_master[x, y + 1, 0] == -1))) { bottom_tiles_array[0, temp_bottom_tiles_array_count[0]] = tile_script; temp_bottom_tiles_array_count[0]++; } //orientation 1 = 90° if ((x == _X_tiles - 1) || ((x < _X_tiles - 1) && (board_array_master[x + 1, 1, 0] == -1))) { bottom_tiles_array[1, temp_bottom_tiles_array_count[1]] = tile_script; temp_bottom_tiles_array_count[1]++; } //orientation 2 = 180° if ((y == 0) || ((y > 0) && (board_array_master[x, y - 1, 0] == -1))) { bottom_tiles_array[2, temp_bottom_tiles_array_count[2]] = tile_script; temp_bottom_tiles_array_count[2]++; } //orientation 3 = 270° if ((x == 0) || ((x > 0) && (board_array_master[x - 1, y, 0] == -1))) { bottom_tiles_array[3, temp_bottom_tiles_array_count[3]] = tile_script; temp_bottom_tiles_array_count[3]++; } SpriteRenderer sprite_hp = tile_script.GetComponent <SpriteRenderer>(); if ((board_array_master[x, y, 0] == 0) && (board_array_master[x, y, 2] > 0)) //if this is a special tile and is visible { if ((board_array_master[x, y, 2] >= 1) && (board_array_master[x, y, 2] <= 9)) { sprite_hp.sprite = start_goal_path[board_array_master[x, y, 2] - 1]; } else if ((board_array_master[x, y, 2] >= 10) && (board_array_master[x, y, 2] <= 19)) { sprite_hp.sprite = door_color[board_array_master[x, y, 2] - 10]; } } //update hp board HP_board += board_array_master[x, y, 0]; //create gem if ((board_array_master[x, y, 1] >= 0) && (board_array_master[x, y, 1] < 9))//if here go a gem { //I can put the gem on the board total_gems_on_board_at_start++; tile_script.my_gem = (GameObject)Instantiate(tile_content, this_position, Quaternion.identity);//"-y" in order to have 0,0 in the up-left corner tile_script.my_gem.transform.parent = pivot_board.transform; tile_script.my_gem_renderer = tile_script.my_gem.GetComponent <SpriteRenderer>(); tile_sprites_array[x, y] = tile_script.my_gem_renderer; if (x == 0 && y == 0) { topLeftBoardPoint = tile_script.transform.position - new Vector3(0.5f, -0.5f, 0.0f); bottomRightBoardPoint = topLeftBoardPoint + new Vector3(8.0f, -8.0f, 0.0f); } tile_script.my_gem.name = "gem" + board_array_master[x, y, 1].ToString(); //gem color: SpriteRenderer sprite_gem = tile_script.my_gem_renderer; sprite_gem.sprite = gem_colors[board_array_master[x, y, 1]]; //create padlock or ice if (board_array_master[x, y, 3] > 0) { tile_script.my_padlock = (GameObject)Instantiate(over_gem, this_position, Quaternion.identity); tile_script.my_padlock.transform.parent = pivot_board; if (board_array_master[x, y, 3] < 11) { padlock_count++; tile_script.my_padlock.name = "padlock"; SpriteRenderer sprite_lock = tile_script.my_padlock.GetComponent <SpriteRenderer>(); sprite_lock.sprite = lock_gem_hp[board_array_master[x, y, 3] - 1]; } else { tile_script.my_padlock.name = "ice"; SpriteRenderer sprite_lock = tile_script.my_padlock.GetComponent <SpriteRenderer>(); sprite_lock.sprite = ice_hp[board_array_master[x, y, 3] - 11]; } } } else //there is somethin that not is a gem { //auxiliary gem in garbage that will be use when this tile will be free ((GameObject)Instantiate(tile_content, new Vector2(x, -y), Quaternion.identity)).transform.parent = garbage_recycle; if (board_array_master[x, y, 1] == 9) //this is a special content { tile_script.my_gem = (GameObject)Instantiate(tile_content, this_position, Quaternion.identity); //"-y" in order to have 0,0 in the up-left corner tile_script.my_gem.transform.parent = pivot_board; tile_script.my_gem_renderer = tile_script.my_gem.GetComponent <SpriteRenderer>(); if (board_array_master[x, y, 4] == -100)//junk { tile_script.my_gem.name = "junk"; number_of_junk_on_board++; tile_script.my_gem_renderer.sprite = junk; } else if (board_array_master[x, y, 4] == -200)//token { number_of_token_on_board++; tile_script.my_gem.name = "token"; SpriteRenderer sprite_gem = tile_script.my_gem_renderer; sprite_gem.sprite = token; } else if (board_array_master[x, y, 4] > 0)//bonus { number_of_bonus_on_board++; tile_script.my_gem.name = "bonus"; SpriteRenderer sprite_gem = tile_script.my_gem_renderer; sprite_gem.sprite = on_board_bonus_sprites[board_array_master[x, y, 4]]; } } else if (board_array_master[x, y, 1] == 40) //immune block { tile_script.my_gem = (GameObject)Instantiate(tile_content, this_position, Quaternion.identity); //"-y" in order to have 0,0 in the up-left corner tile_script.my_gem.transform.parent = pivot_board; tile_script.my_gem.name = "immune_block"; tile_script.my_gem_renderer = tile_script.my_gem.GetComponent <SpriteRenderer>(); tile_script.my_gem_renderer.sprite = immune_block; } else if ((board_array_master[x, y, 1] > 40) && (board_array_master[x, y, 1] < 50))//block { board_array_master[x, y, 14] = (board_array_master[x, y, 1] - 40); tile_script.my_gem = (GameObject)Instantiate(tile_content, this_position, Quaternion.identity);//"-y" in order to have 0,0 in the up-left corner tile_script.my_gem.transform.parent = pivot_board; tile_script.my_gem.name = "block"; tile_script.my_gem_renderer = tile_script.my_gem.GetComponent <SpriteRenderer>(); block_count++; tile_script.my_gem_renderer.sprite = block_hp[board_array_master[x, y, 1] - 41]; } else if ((board_array_master[x, y, 1] > 50) && (board_array_master[x, y, 1] < 60))// falling block { board_array_master[x, y, 14] = (board_array_master[x, y, 1] - 50); tile_script.my_gem = (GameObject)Instantiate(tile_content, this_position, Quaternion.identity);//"-y" in order to have 0,0 in the up-left corner tile_script.my_gem.transform.parent = pivot_board; tile_script.my_gem.name = "falling_block"; tile_script.my_gem_renderer = tile_script.my_gem.GetComponent <SpriteRenderer>(); block_count++; tile_script.my_gem_renderer.sprite = falling_block_hp[board_array_master[x, y, 1] - 51]; } else if ((board_array_master[x, y, 1] >= 60) && (board_array_master[x, y, 1] < 70)) // need { tile_script.my_gem = (GameObject)Instantiate(tile_content, this_position, Quaternion.identity); //"-y" in order to have 0,0 in the up-left corner tile_script.my_gem.transform.parent = pivot_board; tile_script.my_gem_renderer = tile_script.my_gem.GetComponent <SpriteRenderer>(); tile_script.my_gem.name = "need"; tile_script.my_gem_renderer.sprite = need_color[board_array_master[x, y, 1] - 60]; } else if ((board_array_master[x, y, 1] >= 70) && (board_array_master[x, y, 1] < 80)) // key { tile_script.my_gem = (GameObject)Instantiate(tile_content, this_position, Quaternion.identity); //"-y" in order to have 0,0 in the up-left corner tile_script.my_gem.transform.parent = pivot_board; tile_script.my_gem_renderer = tile_script.my_gem.GetComponent <SpriteRenderer>(); tile_script.my_gem.name = "key"; tile_script.my_gem_renderer.sprite = key_color[board_array_master[x, y, 1] - 70]; } else if ((board_array_master[x, y, 2] >= 20) && (board_array_master[x, y, 2] <= 29)) //item { tile_script.my_gem = (GameObject)Instantiate(tile_content, this_position, Quaternion.identity); //"-y" in order to have 0,0 in the up-left corner tile_script.my_gem.transform.parent = pivot_board; tile_script.my_gem.name = "item" + board_array_master[x, y, 2].ToString(); tile_script.my_gem_renderer = tile_script.my_gem.GetComponent <SpriteRenderer>(); tile_script.my_gem_renderer.sprite = item_color[board_array_master[x, y, 2] - 20]; } } } else //there are no tile here { board_array_master[x, y, 1] = -99;//no color here } } } if (win_requirement_selected == win_requirement.take_all_tokens) { if (number_of_token_on_board > 0) { number_of_token_to_collect = number_of_token_on_board; } else { if (show_token_after_all_tiles_are_destroyed && (HP_board == 0)) { Show_all_token_on_board(); } } if (number_of_token_to_collect > 0) { Update_token_count(); } //else //Debug.LogWarning("win condition is 'Take_all_tolens' but this stage file don't have token!"); } if ((number_of_bonus_on_board > 0) && (trigger_by_select == trigger_by.OFF)) { //Debug.LogWarning("This stage file have on board bonus, but you don't have setup any rule to trigger it. So, by default, these bonus will be trigger on click"); trigger_by_select = trigger_by.click; } //Debug.Log("Board created. HP board = " + HP_board); if (emit_token_only_after_all_tiles_are_destroyed && HP_board == 0) { allow_token_emission = true; } Search_max_bonus_values_for_charge_bonus(); }
// Update is called once per frame void Update() { if (board.game_end) { return; } //if (Input.GetMouseButtonUp(0)) // MouseUp(); if (EventSystem.current.IsPointerOverGameObject())//don't click through UI { return; } bool isTouch = false; bool isMouse = false; Vector2 inputScreenPos = Vector2.zero; Vector3 inputWorldPos = Vector3.zero; //if (_isUsingTouch && Input.touchCount > 0 && Input.GetTouch(0).phase == TouchPhase.Began ) if (Input.touchCount > 0 && Input.GetTouch(0).phase == TouchPhase.Began) { isTouch = true; } //else if (!_isUsingTouch && Input.GetMouseButtonDown(0)) else if (Input.GetMouseButtonDown(0)) { isMouse = true; } if (isTouch || isMouse) { if (isTouch) { inputScreenPos = Input.GetTouch(0).position; inputWorldPos = new Vector3(inputScreenPos.x, inputScreenPos.y, cameraZ); inputWorldPos = Camera.main.ScreenToWorldPoint(inputWorldPos); } else { inputScreenPos = Input.mousePosition; inputWorldPos = new Vector3(inputScreenPos.x, inputScreenPos.y, cameraZ); inputWorldPos = Camera.main.ScreenToWorldPoint(inputWorldPos); } if (IsOnBoard(inputWorldPos)) { tile_C tile = GetTileFromBoardAt(inputWorldPos); tile.MyOnMouseDown(); //tile.my_gem_renderer.color = Color.red; } } //Ray ray3d = Camera.main.ScreenPointToRay(Input.mousePosition); //RaycastHit hitInfo3d; //if (Physics.Raycast(ray3d, out hitInfo3d)) //{ // GameObject thisObj = hitInfo3d.collider.transform.gameObject; // if (thisObj.GetComponent<tile_C>() != null) // MouseOver_Tile(thisObj); //} }