예제 #1
0
    IEnumerator Spawn()
    {
        while (true)
        {
            for (float timer = secondsBetweenSkulls; timer >= 0; timer -= Time.deltaTime)
            {
                while (gateManager.pause)
                {
                    yield return(null);
                }
                yield return(null);
            }
            if (nextSkull != -1 && Active && !gateManager.pause)
            {
                float angularVelocity   = UnityEngine.Random.Range(angularVelocityRange[0], angularVelocityRange[1]);
                int   rotationDirection = UnityEngine.Random.Range(0, 2);
                if (rotationDirection == 0)
                {
                    rotationDirection = -1;
                }
                angularVelocity *= rotationDirection;

                GameObject skullInstance = Instantiate(skullPrefab, this.transform.position, Quaternion.AngleAxis(UnityEngine.Random.Range(0, 91), new Vector3(0, 0, 1)));
                skullInstance.transform.SetParent(this.transform);
                skullInstance.GetComponent <SpriteRenderer>().sprite       = gateManager.skullSprites[nextSkull];
                skullInstance.GetComponent <Rigidbody2D>().angularVelocity = angularVelocity;
                skullInstance.GetComponent <Skull>().skullNr = nextSkull;
                skullInstance.GetComponent <Skull>().gate    = this;

                SkullType skullType = new SkullType();
                if (nextSkull >= 0 && nextSkull < 6)
                {
                    skullType = SkullType._1X6;
                }
                else if (nextSkull >= 6 && nextSkull < 10)
                {
                    skullType = SkullType._7X10;
                }
                else if (nextSkull >= 10 && nextSkull < 16)
                {
                    skullType = SkullType._11X16;
                }
                else if (nextSkull >= 16 && nextSkull < 18)
                {
                    skullType = SkullType._17X19;
                }
                skullInstance.GetComponent <Skull>().skullType = skullType;

                if (!gateManager.IsWanted(nextSkull))
                {
                    if (UnityEngine.Random.Range(0.0f, 1.0f) <= powerUpChance)
                    {
                        skullInstance.GetComponent <Skull>().PowerUp();
                    }
                }
                skulls.Add(skullInstance.GetComponent <Skull>());
                nextSkull = gateManager.RandomSkull(true);
            }
        }
    }
예제 #2
0
    void Update()
    {
        if (Input.touchCount > 0)
        {
            foreach (Touch touch in Input.touches)
            {
                if (touch.phase == touchPhase)
                {
                    touchPositionW = Camera.main.ScreenToWorldPoint(touch.position);
                    Vector2      touchPositionW2D = new Vector2(touchPositionW.x, touchPositionW.y);
                    RaycastHit2D hitInformation   = Physics2D.Raycast(touchPositionW2D, Camera.main.transform.forward);
                    if (hitInformation.collider != null)
                    {
                        if (hitInformation.collider.tag == "Skull" && !gateManager.pause)
                        {
                            if (gateManager.IsWanted(hitInformation.collider.GetComponent <Skull>().skullNr) && !hitInformation.collider.GetComponent <Skull>().IsPowerUp)
                            {
                                skullSounds.GoodSkull();
                                gateManager.NewWanted();
                                gameMechanics.AddPoints(gameMechanics.pointReward);
                                if (gameMechanics.MorePointActive)
                                {
                                    gameMechanics.AddPoints(Convert.ToInt32(gameMechanics.pointReward * 0.5f));
                                }
                                StartCoroutine(hitInformation.collider.GetComponent <Skull>().Fade(AnimationType.POINT));
                            }
                            else if (hitInformation.collider.GetComponent <Skull>().IsPowerUp)
                            {
                                skullSounds.GoodSkull();
                                switch (hitInformation.collider.GetComponent <Skull>().PowerType)
                                {
                                case PowerUpType.SLOW:
                                    powerUpManager.SlowPowerUp();
                                    break;

                                case PowerUpType.SPEED:
                                    powerUpManager.SpeedPowerUp();
                                    break;

                                case PowerUpType.CLOSE:
                                    powerUpManager.CloseGatePowerUp();
                                    break;
                                }
                                StartCoroutine(hitInformation.collider.GetComponent <Skull>().Fade(AnimationType.POWER));
                            }
                            else
                            {
                                skullSounds.BadSkull();
                                gameMechanics.Damage();
                                StartCoroutine(hitInformation.collider.GetComponent <Skull>().Fade(AnimationType.DEATH));
                            }
                        }
                    }
                }
            }
        }
    }
예제 #3
0
 void OnCollisionEnter2D(Collision2D collision)
 {
     if (collision.collider.tag == "Skull")
     {
         if (gateManager.IsWanted(collision.collider.GetComponent <Skull>().skullNr) && !collision.collider.GetComponent <Skull>().IsPowerUp)
         {
             skullSounds.LostSkull();
             gateManager.NewWanted();
             gameMechanics.Damage();
         }
         collision.collider.GetComponent <Skull>().DeferDestroy();
     }
 }