Пример #1
0
    public void TouchEgg(BasicEgg egg, Player player)
    {
        if (egg.IsDead)
        {
            return;
        }

        if (egg.IsTheSameColorAs(player.Color))
        {
            egg.TakeDamage(player.Damage);

            if (egg.IsDead)
            {
                destroyedEggs++;
                UpdateEggsCounterText();

                remainingEggs--;
                if (IsEmpty)
                {
                    audioSource.PlayOneShot(audioPanelCleanned, 0.5f);
                    Invoke("SpawnEggs", WAITING_TIME_BEFORE_SPAWN_PANEL);
                }
            }
        }
        else
        {
            player.TakeDamage(1);
        }
    }
Пример #2
0
    void Update()
    {
        // 3 seconds initial countdown
        if (initialThreeCountdownSeconds > 0)
        {
            initialThreeCountdownSeconds -= Time.deltaTime;
            return;
        }
        else
        {
            screenButtonsScript.enabled = true;
        }

        // Do not allow to click if the game is paused.
        if (didGameFinished || screenButtonsScript.getGameIsPaused() || playerScript.IsDead)
        {
            return;
        }

        // Control Time updates
        countdownTimerScript.UpdateTimerBehaviour();

        // Controls player updates
        playerScript.UpdatePlayerBehaviour();

        if (Input.GetMouseButtonDown(0))
        {
            BasicEgg egg = GetEggIfTouched();
            if (egg != null)
            {
                eggsPanelScript.TouchEgg(egg, playerScript);

                // Evaluate if those number of eggs gives a new medal
                medalsScript.DoesItObtainsANewMedalWithThis(eggsPanelScript.DestroyedEggs);

                if (playerScript.IsDead)
                {
                    EndGame();
                }
            }
        }

        if (countdownTimerScript.HasEnded() && !didGameFinished)
        {
            didGameFinished = true;

            if (medalsScript.ObtainedMedals == 0)
            {
                playerScript.Death();
            }
            else
            {
                playerScript.Win();
            }

            EndGame();
        }
    }
Пример #3
0
    BasicEgg GetEggIfTouched()
    {
        Vector3      mousePos   = Camera.main.ScreenToWorldPoint(Input.mousePosition);
        Vector2      mousePos2D = new Vector2(mousePos.x, mousePos.y);
        RaycastHit2D hit        = Physics2D.Raycast(mousePos2D, Vector2.zero);

        if (hit.collider == null)
        {
            return(null);
        }
        else
        {
            BasicEgg touchedEgg = (BasicEgg)hit.collider.gameObject.GetComponent(typeof(BasicEgg));
            return(touchedEgg);
        }
    }
Пример #4
0
    public void SpawnEggs()
    {
        ShuffleEggTypes(ref eggTypes);
        for (int i = 0; i < eggs.Length; i++)
        {
            if (eggs[i] != null)
            {
                eggs[i].DestroyGO();
            }
            Vector3 eggPosition = platforms[i].GetComponent <Transform>().position;
            eggPosition.y += EXTRA_EGG_POSITION_Y;

            switch (eggTypes[i])
            {
            default:
            case EggType.BASIC:
                BasicEgg basicEgg = (BasicEgg)Instantiate(
                    Resources.Load <BasicEgg>("Prefabs/BasicEgg"), eggPosition, Quaternion.identity);
                basicEgg.SetColor(ColorsManager.instance.GetRandomColor());
                basicEgg.name = i + "-" + basicEgg.SpriteName;
                eggs[i]       = basicEgg;
                break;

            case EggType.ARMORED:
                ArmoredEgg armoredEgg = (ArmoredEgg)Instantiate(
                    Resources.Load <ArmoredEgg>("Prefabs/ArmoredEgg"), eggPosition, Quaternion.identity);
                armoredEgg.SetColor(ColorsManager.instance.GetRandomColor());
                armoredEgg.name = i + "-" + armoredEgg.SpriteName;
                eggs[i]         = armoredEgg;
                break;

            case EggType.COLORCHANGER:
                ColorChangerEgg colorChangerEgg = (ColorChangerEgg)Instantiate(
                    Resources.Load <ColorChangerEgg>("Prefabs/ColorChangerEgg"), eggPosition, Quaternion.identity);
                colorChangerEgg.SetEggsPanel(this);
                colorChangerEgg.SetColor(ColorsManager.instance.GetRandomColor());
                colorChangerEgg.name = i + "-" + colorChangerEgg.SpriteName;
                eggs[i] = colorChangerEgg;
                break;
            }

            remainingEggs++;
        }
    }