示例#1
0
    IEnumerator Jump()
    {
        VarietyPlay(jump_audio_source);

        jumpable   = false;
        gravity_on = false;
        float seconds = 0.4f;
        float iters   = 50 * seconds;
        float short_hop_thresh_start = 0.3f; // can short hop this % of the way through
        float short_hop_thresh_end   = 0.6f; // stuck in full jump after this % of the way through

        bool short_hop = false;
        int  i         = 0;

        while (i < iters)
        {
            // Allow for varying heights based on how long pressing
            if (i > iters * short_hop_thresh_start && i < iters * short_hop_thresh_end &&
                !Input.GetKey(KeyCode.Space) && !Input.GetKey(KeyCode.JoystickButton0))
            {
                short_hop = true;
                break;
            }
            // Completely stop if this player is dead
            if (death.IsDead())
            {
                yield break;
            }
            // Raise player by correct amount
            RaiseLowerPlayer(Mathf.Max(((0.8f * iters) - i), 0.0f) * (jump_amount * 0.008f));
            //RaiseLowerPlayer(jump_amount / iters);
            // Wait + increment so that this all happens overtime
            yield return(new WaitForFixedUpdate());

            i++;
        }
        Debug.Log("Reached height of " + (player.transform.localPosition.z - player_local_z_start));

        if (!short_hop && (Input.GetKey(KeyCode.Space) || Input.GetKey(KeyCode.JoystickButton0)))
        {
            StartCoroutine("Fly");
        }
        else
        {
            gravity_on = true;
        }
    }
示例#2
0
 public void Retry()
 {
     death.IsDead();
 }
示例#3
0
    // Update is called once per frame
    void Update()
    {
        if (deathComp && deathComp.IsDead())
        {
            if (audio && audio.isPlaying)
            {
                audio.Stop();
            }
        }

        if (activated)
        {
            if (startWaterAfterSec > 0.0f)
            {
                startWaterAfterSec -= Time.deltaTime;
            }
            else
            {
                if (playsSound && !audio.isPlaying)
                {
                    audio.Play();
                }
                if (mainWaterObject)
                {
                    secSinceLastWaterTick += Time.deltaTime;

                    if (secSinceLastWaterTick >= secBetweenWaterTicks)
                    {
                        for (int times = 0; times < waterMassTimesPerTick; times++)
                        {
                            Vector2 target = gameObject.transform.position;
                            target.x += waterTargetPoint.x;
                            target.y += waterTargetPoint.y;

                            Collider2D[]      hits      = Physics2D.OverlapCircleAll(target, waterTargetRadius);
                            List <Collider2D> waterHits = new List <Collider2D>();

                            foreach (Collider2D hit in hits)
                            {
                                if (hit.tag.Equals("Water"))
                                {
                                    waterHits.Add(hit);
                                }
                            }

                            for (int i = 0; i < waterHits.Count; i++)
                            {
                                int        randomWaterTile = Random.Range(0, waterHits.Count);
                                Collider2D choosenTile     = waterHits[randomWaterTile];

                                if (choosenTile)
                                {
                                    TWaterTile     waterComponent     = choosenTile.gameObject.GetComponent <TWaterTile>();
                                    TFollowerWater tileWaterComponent = mainWaterObject.GetComponent <TFollowerWater>();

                                    if (tileWaterComponent && waterComponent)
                                    {
                                        if (waterComponent.waterMass <= 1.0f)
                                        {
                                            tileWaterComponent.AddWaterToWaterTile(waterComponent.posX, waterComponent.posY, waterMassPerTick);
                                        }
                                    }
                                }
                            }
                        }

                        secSinceLastWaterTick = 0;
                    }
                }
                else
                {
                    print("TileWaterObject not set!");
                }
            }
        }
    }