//============================================= // конструктор public void Create_Queue_Figura(CarcasType type, Transform parent) { carcas_type = type; carcas = FiguraCarcasesList.get_Carcas_byType(carcas_type); // создание плашки DestroyGraphicsObjects(); plashka = (GameObject)Instantiate(Resources.Load(GameConstants.PREFAB_PLASHKA), parent); //, parent plashka.transform.SetParent(parent); plashka.transform.localPosition = new Vector3(0f, 0f, 0f); //localPosition GameConstants.QUEUE_ITEM_HEIGHT / 2f plashka.GetComponent <SpriteRenderer>().maskInteraction = SpriteMaskInteraction.VisibleInsideMask; //plashka.transform.localScale = GameConstants.PLASHKA_SCALE; //Animator anim = prefab.GetComponent<Animator>(); //anim.runtimeAnimatorController = (RuntimeAnimatorController)Instantiate(Resources.Load(animation)) as RuntimeAnimatorController; //anim.Play("Idle"); //создание фигуры по центру плашки Vector2 min = new Vector2((float)carcas.getMinD(0), (float)carcas.getMinD(1)); Vector2 size = new Vector2((float)carcas.getMaxD(0) - min.x + 1f, (float)carcas.getMaxD(1) - min.y + 1f); //Ширина плашки = 5 x Ширина квадрата , поэтому crd = Xn-Xmin - FIGURA_WIDTH/2 + 1/2 //Высота плашки = 3.9 x Высоты квадрата for (int i = 0; i < carcas.numPoints; i++) { float dx = (0.5f - min.x - size.x / 2f + (float)carcas.coords[i, 0]) * GameConstants.QUEUE_SQUARE_SIZE.x; //f - maxwidth float dy = (0.45f - min.y - size.y / 2f + (float)carcas.coords[i, 1]) * GameConstants.QUEUE_SQUARE_SIZE.y; //myUtils.console_log(dx, dy); OneSquare square = myUtils.create_OneSquare(new Vector3(dx, dy, 0f), plashka.transform, GameConstants.QUEUE_SQUARE_SCALE, -1, GameConstants.sANIM_BASE); squaresList.Add(square); } //plashka.transform.localPosition = plashka.transform.localPosition + new Vector3(0f, GameConstants.QUEUE_ITEM_HEIGHT/2f, 0f); //localPosition }
//========================================= //добавить случайную фигуру в конец очереди public void Add_Random_Figura() { CarcasType carcase_type = FiguraCarcasesList.get_RandomCarcasType(); //myUtils.console_log("random carcase_type =", carcase_type); Vector3 crd = new Vector3(0f, -top_point_y - GameConstants.QUEUE_START.y - (float)figures_Queue.Count * GameConstants.QUEUE_ITEM_HEIGHT, 0f); OneQueueFigura qfigura = new OneQueueFigura(); Transform parent = GameObject.FindGameObjectWithTag("queue_figures").GetComponent <Transform>(); qfigura.Create_Queue_Figura(carcase_type, parent); qfigura.MoveTo(crd); figures_Queue.Add(qfigura); }
//============================================= //поворот фигуры по направлению void RotateFigura(int dir) { //if ( carcas_type == "square") return; //myUtils.console_log("rotate_figure"); //создание клона фигуры и проверка int new_rotate = rotate_index; if (dir == GameConstants.DIR_LEFT) { new_rotate--; } else { new_rotate++; } if (new_rotate < 0) { new_rotate += 4; } new_rotate = new_rotate % 4; //попытка поворота и сдвига //получить каркас с поворотом FiguraCarcas tmpCarcas = FiguraCarcasesList.get_Carcas_byType(carcas_type, new_rotate); //myUtils.console_log("new_carcas = ", tmpCarcas); //при проверке нужно учесть, что возможно фигуру нужно подвинуть влево-вправо от бордюра на несколько квадратов //определение сдвига фигуры от края (если надо) Vector2Int new_min = tmpCarcas.getMinV2Int(); Vector2Int new_max = tmpCarcas.getMaxV2Int(); int shift_x = 0; int new_x = coords.x; if (coords.x + new_min.x < 0) { shift_x = -coords.x + Mathf.Abs(new_min.x); } if (coords.x + new_max.x >= GameConstants.AREA_WIDTH) { shift_x = -coords.x + GameConstants.AREA_WIDTH - (1 + new_max.x); } new_x += shift_x; //если фигура изначально (до поворота) была прислонена к краю, то тоже ее придвинуть туда Vector2Int old_min = carcas.getMinV2Int(); Vector2Int old_max = carcas.getMaxV2Int(); if ((coords.x + old_min.x) <= 0) { //фигура должна быть прижата к левому борту if (new_x + new_min.x > 0) { shift_x = -coords.x + Mathf.Abs(new_min.x); new_x = coords.x + shift_x; } } if ((coords.x + old_max.x + 1) >= GameConstants.AREA_WIDTH) { //фигура должна быть прижата к правому борту if (new_x + new_max.x + 1 < GameConstants.AREA_WIDTH) { shift_x = -coords.x + GameConstants.AREA_WIDTH - (1 + new_max.x); new_x = coords.x + shift_x; } } if (is_blocked_on_pos(new Vector2Int(new_x, coords.y), tmpCarcas, delta.y)) { //myUtils.console_log("blocked", new_x, new_min.x, shift_x, coords.x); return; } //сохранение повернутого каркаса carcas.Reinit(tmpCarcas); //перемещение графических объектов for (int c = 0; c < carcas.numPoints; c++) { squaresList[c].brick.transform.localPosition = new Vector3( GameConstants.AREA_START.x + ((float)carcas.coords[c, 0] + (float)coords.x + 0.5f) * GameConstants.AREA_SQUARE_SIZE.x, GameConstants.AREA_START.y + ((float)carcas.coords[c, 1] + (float)coords.y + 0.5f) * GameConstants.AREA_SQUARE_SIZE.y - delta.y, 0 ); //myUtils.console_log(old_crd, "->", new_crd); } MoveBy(new Vector3((float)shift_x * GameConstants.AREA_SQUARE_SIZE.x, 0f, 0f)); //учет сдвига coords.x = new_x; rotate_index = new_rotate; return; // true; }