//=============================================
    //создать новую фигуру на базе фигуры из очереди (взять из нее каркас и типы камней)
    //queueFigura - каркас + типы квадратов (без графики)
    public void Create_Figura(OneQueueFigura queueFigura, Transform parent)
    {
        carcas_type = queueFigura.carcas_type;
        carcas      = queueFigura.carcas;
        //myUtils.console_log(carcas_type, carcas);
        //создание фигуры по центру плашки
        Vector2 min       = new Vector2((float)carcas.getMinD(0), (float)carcas.getMinD(1));
        Vector2 pt_center = new Vector2((float)GameConstants.AREA_WIDTH / 2f, -min.y + (float)GameConstants.AREA_VISUAL_HEIGHT);

        for (int i = 0; i < carcas.numPoints; i++)
        {
            int       type   = queueFigura.squaresList[i].type;
            float     dx     = GameConstants.AREA_START.x + ((float)carcas.coords[i, 0] + pt_center.x + 0.5f) * GameConstants.AREA_SQUARE_SIZE.x;
            float     dy     = GameConstants.AREA_START.y + ((float)carcas.coords[i, 1] + pt_center.y + 0.5f) * GameConstants.AREA_SQUARE_SIZE.y;
            OneSquare square = myUtils.create_OneSquare(new Vector3(dx, dy, 0f), parent, GameConstants.AREA_SQUARE_SCALE, type, GameConstants.sANIM_BASE);
            squaresList.Add(square);
        }
        coords = new Vector2Int(
            Mathf.RoundToInt(pt_center.x),
            Mathf.RoundToInt(pt_center.y)
            );
        delta                        = new Vector2(0f, 0f);
        last_move_time               = 0f;
        rotate_index                 = 0;
        flagFastSpeed                = false;
        figure_area_acept_time       = 0;
        anti_click_space_first_frame = true;
    }
예제 #2
0
    //=============================================
    // конструктор
    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
    }
예제 #3
0
    //размещение фигуры в области сборки
    public void put_figura(Vector2Int m, FiguraCarcas fd, List <OneSquare> figuraSquares)
    {
        SoundManager.PlaySound("figura_landed");
        for (int i = 0; i < fd.numPoints; i++)
        {
            int x = m.x + fd.coords[i, 0];
            int y = m.y + fd.coords[i, 1];
            if (y >= GameConstants.AREA_REAL_HEIGHT)
            {
                continue;
            }
            SetSquare(x, y, figuraSquares[i].type);
        }
        int figure_score = (int)UnityEngine.Random.Range(5, 20);

        scoresController.AddScoreLevel(figure_score);
        scoresController.AddGraphicsItem(m, figure_score.ToString(), ScoreType.FigurePut);

        //проверка на заполненные линии
        check_filled_lines();

        //проверка на финиш (заполнение 0 линии),
        if (is_CapacityFull())
        {
            //область переполнена, запуск анимации удаления камней, а затем рестарт уровня
            EventManager.TriggerEvent("Anim_Overfill_area");
        }
        //EventManager.TriggerEvent("CanStartNewFigura");
    }
    private void Awake()
    {
        gameArea       = FindObjectOfType <GameArea>();       // GetComponent
        gameController = FindObjectOfType <GameController>(); // GetComponent

        carcas_type = CarcasType.empty;
        carcas      = null;
        squaresList = new List <OneSquare>();
    }
 //=============================================
 //проверка наличия заполненных квадратов на новом месте фигуры
 bool is_blocked_on_pos(Vector2Int m, FiguraCarcas fd, float dy)
 {
     for (int i = 0; i < fd.numPoints; i++)
     {
         if ((gameArea.is_disabled(m.x + fd.coords[i, 0], m.y + fd.coords[i, 1])) ||
             ((dy > 0f) && gameArea.is_disabled(m.x + fd.coords[i, 0], m.y + fd.coords[i, 1] - 1)))
         {
             return(true);
         }
     }
     return(false);
 }
    //===================================================
    public static FiguraCarcas RotateCarcas(FiguraCarcas carcas, int dir)
    {
        FiguraCarcas tmpCarcas = new FiguraCarcas(carcas);
        int          x, y;

        //поворот клона
        for (int i = 0; i < tmpCarcas.numPoints; i++)
        {
            if (dir == GameConstants.DIR_LEFT)
            {
                x = tmpCarcas.coords[i, 1];
                y = -tmpCarcas.coords[i, 0];
            }
            else
            {
                x = -tmpCarcas.coords[i, 1];
                y = tmpCarcas.coords[i, 0];
            }
            tmpCarcas.coords[i, 0] = x;
            tmpCarcas.coords[i, 1] = y;
        }

        return(tmpCarcas);
    }
    //получить каркас фигуры по ключу с данной ротацией (0..3 = 0,90,180,270)
    public static FiguraCarcas get_Carcas_byType(CarcasType key, int rotate = 0)
    {
        rotate = rotate % 4;
        FiguraCarcas        baseCarcas = null;
        List <FiguraCarcas> carcas     = new List <FiguraCarcas>();

        //myUtils.console_log("figura key =", key);
        switch (key)
        {
        case CarcasType.skoba_l:
            baseCarcas = new FiguraCarcas(4, new int[4, 2] {
                { -1, 1 }, { -1, 0 }, { 0, 0 }, { 1, 0 }
            });
            break;

        case CarcasType.skoba_r:
            baseCarcas = new FiguraCarcas(4, new int[4, 2] {
                { -1, 0 }, { 0, 0 }, { 1, 0 }, { 1, 1 },
            });
            break;

        case CarcasType.zigzag_l:
            baseCarcas = new FiguraCarcas(4, new int[4, 2] {
                { -1, -1 }, { 0, -1 }, { 0, 0 }, { 1, 0 }
            });
            break;

        case CarcasType.zigzag_r:
            baseCarcas = new FiguraCarcas(4, new int[4, 2] {
                { -1, 1 }, { 0, 1 }, { 0, 0 }, { 1, 0 }
            });
            break;

        case CarcasType.halfcros:
            baseCarcas = new FiguraCarcas(4, new int[4, 2] {
                { -1, 0 }, { 0, 0 }, { 1, 0 }, { 0, 1 }
            });
            break;

        case CarcasType.line_h:
            baseCarcas = new FiguraCarcas(4, new int[4, 2] {
                { -1, 0 }, { 0, 0 }, { 1, 0 }, { 2, 0 }
            });
            break;

        case CarcasType.sector:
            baseCarcas = new FiguraCarcas(4, new int[4, 2] {
                { -1, -1 }, { 0, 0 }, { 1, 0 }, { 2, -1 }
            });
            break;

        case CarcasType.duga_l:
            baseCarcas = new FiguraCarcas(4, new int[4, 2] {
                { -1, -1 }, { 0, 0 }, { 1, 0 }, { 2, 0 }
            });
            break;

        case CarcasType.duga_r:
            baseCarcas = new FiguraCarcas(4, new int[4, 2] {
                { -1, 1 }, { 0, 0 }, { 1, 0 }, { 2, 0 }
            });
            break;

        case CarcasType.circle:
            baseCarcas = new FiguraCarcas(4, new int[4, 2] {
                { -1, 0 }, { 0, -1 }, { 1, 0 }, { 0, 1 }
            });
            break;

        case CarcasType.check_l:
            baseCarcas = new FiguraCarcas(4, new int[4, 2] {
                { -1, 0 }, { 0, -1 }, { 1, 0 }, { 2, 1 }
            });
            break;

        case CarcasType.check_r:
            baseCarcas = new FiguraCarcas(4, new int[4, 2] {
                { 1, 0 }, { 0, -1 }, { -1, 0 }, { -2, 1 }
            });
            break;

        case CarcasType.lomanaya:
            baseCarcas = new FiguraCarcas(4, new int[4, 2] {
                { 1, 0 }, { 0, -1 }, { -1, 0 }, { -2, -1 }
            });
            break;

        case CarcasType.square:
        default:
            carcas.Add(new FiguraCarcas(4, new int[4, 2] {
                { 0, 1 }, { 0, 0 }, { -1, 0 }, { -1, 1 }
            }));
            carcas.Add(new FiguraCarcas(4, new int[4, 2] {
                { 0, 0 }, { -1, 0 }, { -1, 1 }, { 0, 1 }
            }));
            carcas.Add(new FiguraCarcas(4, new int[4, 2] {
                { -1, 0 }, { -1, 1 }, { 0, 1 }, { 0, 0 }
            }));
            carcas.Add(new FiguraCarcas(4, new int[4, 2] {
                { -1, 1 }, { 0, 1 }, { 0, 0 }, { -1, 0 }
            }));
            break;
        }

        if (key != CarcasType.square)
        {
            carcas.Add(baseCarcas);
            baseCarcas = RotateCarcas(baseCarcas, GameConstants.DIR_RIGHT);
            carcas.Add(baseCarcas);
            baseCarcas = RotateCarcas(baseCarcas, GameConstants.DIR_RIGHT);
            carcas.Add(baseCarcas);
            baseCarcas = RotateCarcas(baseCarcas, GameConstants.DIR_RIGHT);
            carcas.Add(baseCarcas);
        }

        return(carcas[rotate]);
    }
 public void Reinit(FiguraCarcas fd)
 {
     Reinit(fd.numPoints, fd.coords);
 }
 public FiguraCarcas(FiguraCarcas fd)
 {
     numPoints = fd.numPoints;
     coords    = new int[10, 2];
     Reinit(fd.numPoints, fd.coords);
 }
    //=============================================
    //поворот фигуры по направлению
    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;
    }