Exemplo n.º 1
0
 public void StartPlay()
 {
     OnStartPlay?.Invoke();
 }
Exemplo n.º 2
0
    private void Update()
    {
        //  AvctivatedBoostView = ActivatedBoost;
        if (Input.GetKeyDown(DebugSettings.Regen) && DebugSettings.enableHotkeys)
        {
            NoMatches();
        }

        if (Input.GetKeyDown(DebugSettings.Win) && DebugSettings.enableHotkeys)
        {
            stars      = Mathf.Clamp(stars, 1, stars);
            gameStatus = GameState.PreWinAnimations;
        }

        if (Input.GetKeyDown(DebugSettings.Lose) && DebugSettings.enableHotkeys)
        {
            levelData.limit = 1;
        }

        if (Input.GetKeyDown(DebugSettings.Restart) && DebugSettings.enableHotkeys)
        {
            GameObject gm = new GameObject();
            gm.AddComponent <RestartLevel>();
            string scene = SceneManager.GetActiveScene().name;
            SceneManager.LoadScene(scene);
        }

#if UNITY_EDITOR
        if (gameStatus == GameState.Playing)
        {
            Time.timeScale = DebugSettings.TimeScaleItems;
        }
        else
        {
            Time.timeScale = DebugSettings.TimeScaleUI;
        }
#endif

        //if (Input.GetKeyDown(KeyCode.D))
        //{
        //	DestroyAnimatedItems();
        //}
        if (Input.GetKeyDown(DebugSettings.SubSwitch) && DebugSettings.enableHotkeys)
        {
            gameStatus = GameState.ChangeSubLevel;
        }

        if (Input.GetKeyUp(DebugSettings.Back) && DebugSettings.enableHotkeys)
        {
            if (THIS.gameStatus == GameState.Playing)
            {
                GameObject.Find("CanvasGlobal").transform.Find("MenuPause").gameObject.SetActive(true);
            }
            else if (THIS.gameStatus == GameState.Map)
            {
                Application.Quit();
            }
        }

        if (gameStatus == GameState.Playing || gameStatus == GameState.Tutorial)
        {
            if (Input.GetMouseButtonDown(0))
            {
                var hit = Physics2D.OverlapPoint(Camera.main.ScreenToWorldPoint(Input.mousePosition),
                                                 1 << LayerMask.NameToLayer("Item"));
                if (hit != null)
                {
                    lastTouchedItem = hit.gameObject.GetComponent <Item>();
                    if (tutorialTime && !lastTouchedItem.tutorialUsableItem)
                    {
                        return;
                    }
                    if (!THIS.DragBlocked &&
                        (gameStatus == GameState.Playing || gameStatus == GameState.Tutorial))
                    {
                        OnStartPlay?.Invoke();
                        tutorialTime = false;
                        if (THIS.ActivatedBoost.type == BoostType.ExplodeArea &&
                            lastTouchedItem.currentType != ItemsTypes.MULTICOLOR && lastTouchedItem.currentType != ItemsTypes.INGREDIENT)
                        {
                            SoundBase.Instance.PlayOneShot(SoundBase.Instance.boostBomb);
                            THIS.DragBlocked = true;
                            var obj = Instantiate(Resources.Load("Boosts/area_explosion"), lastTouchedItem.transform.position,
                                                  lastTouchedItem.transform.rotation) as GameObject;
                            obj.GetComponent <SpriteRenderer>().sortingOrder = 4;
                            obj.GetComponent <BoostAnimation>().square       = lastTouchedItem.square;
                            THIS.ActivatedBoost = null;
                        }
                        else if (THIS.ActivatedBoost.type == BoostType.Bomb &&
                                 lastTouchedItem.currentType != ItemsTypes.MULTICOLOR && lastTouchedItem.currentType != ItemsTypes.INGREDIENT)
                        {
                            SoundBase.Instance
                            .PlayOneShot(SoundBase.Instance.boostColorReplace);
                            THIS.DragBlocked = true;
                            var obj = Instantiate(Resources.Load("Boosts/simple_explosion"), lastTouchedItem.transform.position,
                                                  lastTouchedItem.transform.rotation) as GameObject;
                            obj.GetComponent <BoostAnimation>().square       = lastTouchedItem.square;
                            obj.GetComponent <SpriteRenderer>().sortingOrder = 4;
                            THIS.ActivatedBoost = null;
                        }
                        else if (lastTouchedItem.square.GetSubSquare().CanGoOut() /* && lastTouchedItem.Combinable*/)
                        {
                            lastTouchedItem.dragThis = true;
                            lastTouchedItem.mousePos = lastTouchedItem.GetMousePosition();
                            lastTouchedItem.deltaPos = Vector3.zero;
                        }
                    }
                }
            }
            else if (Input.GetMouseButtonUp(0))
            {
                if (lastTouchedItem != null)
                {
                    lastTouchedItem.dragThis        = false;
                    lastTouchedItem.switchDirection = Vector3.zero;
                }
            }
            else if (Input.GetMouseButton(1))
            {
                var hit = Physics2D.OverlapPoint(Camera.main.ScreenToWorldPoint(Input.mousePosition),
                                                 1 << LayerMask.NameToLayer("Item"));
                if (hit != null)
                {
                    var item = hit.gameObject.GetComponent <Item>();
                    Camera.main.GetComponent <ItemChangerTest>().ShowMenuItems(item);
                }
            }
        }
    }