Beispiel #1
0
    public bool CanPlace(KinematicBlock block)
    {
        Block oriented = block.GetOrientedBlock(out Vector2Int position);

        position.y = Height - position.y;
        return(simulator.CanPlaceBlock(oriented, block.CurrentRotationToOrientation(), position.x, position.y));
    }
Beispiel #2
0
    public bool InsideBox(KinematicBlock block)
    {
        Block oriented = block.GetOrientedBlock(out Vector2Int position);

        return(position.x >= 0 && position.y >= oriented.Height && position.x + oriented.Width <= Width &&
               position.y <= Height);
    }
Beispiel #3
0
    void CheckTraps()
    {
        Collider2D[] nearestTraps = Physics2D.OverlapCircleAll(player.position, 4f, LayerMask.GetMask("Traps"));
        if (nearestTraps != null && nearestTraps.Length > 0)
        {
            foreach (Collider2D trap in nearestTraps)
            {
                foundTrap = trap.GetComponent <KinematicBlock>();

                if (foundTrap.isTriggered()) // Если ловушка активирована и ее никто не собирается останавливать
                {
                    // определяем вектор движения ловушки
                    direction = foundTrap.getVectorAngle();

                    // Ищем блок фронта движения
                    Transform nearestTrapBlock = trap.transform.GetChild(0);

                    /*
                     * foreach (Transform trapBlock in trap.transform)
                     * {
                     *  if (trapBlock.position.x * direction.x >= nearestTrapBlock.position.x * direction.x)
                     *      if(trapBlock.position.y * direction.y >= nearestTrapBlock.position.y * direction.y)
                     *          nearestTrapBlock = trapBlock;
                     * }*/
                    // запрещаем другим блокировать эту ловушку
                    foundTrap.Block();

                    // вычисляем скорость движения
                    float trapSpeed = foundTrap.expansion / (foundTrap.expansionTime);
                    speed = trapSpeed * 20;

                    // сбрасываем время анимации
                    t = 0;

                    // переходим в режим ускорения
                    triggered = true;

                    // меняем свой спрайт
                    GetComponent <SpriteRenderer>().sprite = chaseSprite;
                    trfm.localScale = Vector3.one;

                    // включаем хвост
                    tr.time = 1f;

                    // летим на точку и отключаемся
                    pointToMove = nearestTrapBlock;

                    //сохраняем старое положение для интерполяции
                    oldPos = trfm.position;

                    // удаляем себя из менеджера, чтобы больше нас не трогал
                    MatesManager.matesManager.RemoveMate(trfm);
                    break;
                }
            }
        }
    }
Beispiel #4
0
 private bool CheckAlphaKey(KinematicBlock kb, KeyCode keyCode, int index)
 {
     if (Input.GetKey(keyCode) && MaterialRegistry.Materials.Length > index)
     {
         kb.SetBlockMaterial(MaterialRegistry.Materials[index]);
         Reserialize();
         return(true);
     }
     return(false);
 }
Beispiel #5
0
    public void PlaceBlock(KinematicBlock kinematicBlock, bool initial = false)
    {
        var block = kinematicBlock.GetOrientedBlock(out Vector2Int pos);

        sfxPlaceBlock.Play();

        BlockOrientation orientation = kinematicBlock.CurrentRotationToOrientation();

        if (LevelPatternSaveAsset && IsEditor)
        {
            LevelPatternSaveAsset.Add(block, orientation, kinematicBlock.BlockMaterial, pos);
        }
        pos.y = Height - pos.y;
        Debug.Log("Place @ " + pos.x + ", " + pos.y);
        var color = kinematicBlock.GetComponent <MeshRenderer>().sharedMaterial.color;

        kinematicBlock.BlockID = simulator.PlaceBlock(block, orientation, color, pos.x, pos.y, initial);
        kinematicBlocks.Add(kinematicBlock);
    }
Beispiel #6
0
    private KinematicBlock InstantiateBlock(Block block, BlockOrientation orientation, int x, int y, BlockMaterial m, bool place = true)
    {
        Vector3 position      = new Vector3(x, y, 0);
        Vector3 worldSpacePos = transform.TransformPoint(position);
        var     go            = Instantiate(block.Prefab, worldSpacePos, KinematicBlock.OrientationToRotation(orientation), transform);
        var     kblock        = go.AddComponent <KinematicBlock>();

        kblock.Initialize(this, block, m, BlockMaterial);

        Vector2Int simPos   = kblock.GetTopLeftPoint();
        var        localpos = go.transform.localPosition;

        localpos.x += x - simPos.x;
        localpos.y += y - simPos.y;
        go.transform.localPosition = localpos;
        Debug.DrawLine(Vector3.zero, worldSpacePos);
        Debug.Log($"InstantiateBlock [{x}, {y}] => {worldSpacePos} => {simPos}");
        if (!place)
        {
            return(kblock);
        }

        if (!CanPlace(kblock))
        {
            Destroy(go);
            return(null);
        }

        PlaceBlock(kblock, true);

        var goBackground =
            Instantiate(block.Prefab, go.transform.position - new Vector3(0, 0, -0.25f),
                        go.transform.rotation, transform);

        goBackground.GetComponent <MeshRenderer>().sharedMaterial = m.MaterialPrefab;

        return(kblock);
    }