Exemple #1
0
    // Update is called once per frame
    void Update()
    {
        if (height != targetHeight)
        {
            height = Mathf.MoveTowards(height, targetHeight, speed * Time.deltaTime);
            SetHeight(height);
        }
        if (ClimateEvents.GetInstance().waterLevel)
        {
            targetHeight = 0;
        }
        else
        {
            targetHeight = -3.9f;
        }

        float targetDarkness;

        if (ClimateEvents.GetInstance().darkenScreen)
        {
            targetDarkness = 0.8f;
        }
        else
        {
            targetDarkness = 0f;
        }

        darkness = Mathf.Lerp(darkness, targetDarkness, transitionRate * Time.deltaTime);
        if (Mathf.Abs(darkness - targetDarkness) < 0.01f)
        {
            darkness = targetDarkness;
        }
        sr.color = new Color(1f - darkness, 1f - darkness, 1f - darkness);
    }
 public void UpdateClimateEvents()
 {
     // handle climate events
     if (ClimateEvents.GetInstance().shatterPlatforms)
     {
         gameObject.AddComponent <ShatterPlatform>();
     }
     else if (!ClimateEvents.GetInstance().shatterSky)
     {
         ShatterPlatform shatform = gameObject.GetComponent <ShatterPlatform>();
         if (shatform != null && !shatform.shattering)
         {
             Destroy(shatform);
         }
     }
     if (ClimateEvents.GetInstance().shrinkingPlatforms)
     {
         gameObject.AddComponent <ShrinkPlatform>();
     }
     else
     {
         ShrinkPlatform shrinkform = gameObject.GetComponent <ShrinkPlatform>();
         if (shrinkform != null && !shrinkform.shrinking)
         {
             Destroy(shrinkform);
         }
     }
 }
 // Update is called once per frame
 void Update()
 {
     if (ClimateEvents.GetInstance().wind)
     {
         if (!ps.isEmitting)
         {
             ps.Play(false);
         }
     }
     else if (ps.isEmitting)
     {
         ps.Stop(false, ParticleSystemStopBehavior.StopEmitting);
     }
 }
    // Update is called once per frame
    void Update()
    {
        if (ClimateEvents.GetInstance().darkenScreen)
        {
            targetAlpha = 0.75f;
        }
        else
        {
            targetAlpha = 0;
        }

        alpha = Mathf.Lerp(alpha, targetAlpha, transitionRate * Time.deltaTime);
        if (Mathf.Abs(alpha - targetAlpha) < 0.01f)
        {
            alpha = targetAlpha;
        }
        sr.color = new Color(0f, 0f, 0f, alpha);
    }
    IEnumerator Shatter()
    {
        Platform p = GetComponent <Platform>();

        Instantiate(p.warningPrefab, transform.position + Vector3.up * 1.2f, transform.rotation);
        yield return(new WaitForSeconds(shatterTime));

        Vector3 pos = transform.position;

        p.Explode();
        if (ClimateEvents.GetInstance().shatterSky)
        {
            foreach (GameObject fragment in GameObject.FindGameObjectsWithTag("Fragment"))
            {
                if (Vector2.Distance(fragment.transform.position, pos) < 2f)
                {
                    float sign = Mathf.Sign(fragment.transform.position.x - pos.x);
                    fragment.GetComponent <Rigidbody2D>().velocity += sign * Vector2.right * UnityEngine.Random.Range(0.25f, 3f);
                }
            }
        }
    }
    // Update is called once per frame
    void Update()
    {
        //get camera pose
        Rect cameraView = CameraMovement.CameraRect();

        //create batch of platforms whenever camera is within given distance of the end of the last run
        if (cameraView.xMax + LOOKAHEAD_DISTANCE > distanceGenerated)
        {
            //generate run of new platforms
            float targetDistance = distanceGenerated + RUN_LENGTH;
            while (distanceGenerated < targetDistance)
            {
                RenderedPlatform platform = (Random.value > 0.65) ? GenerateStaticHeightPlatform(cameraView) :
                                            (ClimateEvents.GetInstance().waterLevel ? GenerateStaticHeightPlatform(cameraView) : GenerateVariableHightPlatform(cameraView));
                distanceGenerated = platform.upperRight.x;
                platforms.Add(platform);
            }
        }


        //discard old platforms
        for (int i = 0; i < platforms.Count; i++)
        {
            if (platforms[i].obj == null)
            {
                platforms.RemoveAt(i);
                i--;
                continue;
            }

            if (platforms[i].obj.transform.position.x + (platforms[i].width / 2) < cameraView.xMin)
            {
                Destroy(platforms[i].obj);
                platforms.RemoveAt(i);
                i--;
            }
        }
    }
    // Update is called once per frame
    void Update()
    {
        //TODO: only update if player is alive
        ppm   += Time.deltaTime;
        score += Time.deltaTime * 6;

        scoreText.GetComponent <Text>().text = ((int)score).ToString();

        if (ppm > eventPeriod && currentState == State.FILLING)
        {
            currentState = State.SICKO_MODE;
            eventImage.GetComponent <Image>().sprite = ClimateEvents.GetInstance().StartClimateEvent();
            warningBar.SetActive(true);
        }

        if (currentState == State.SICKO_MODE)
        {
            ppm = eventPeriod;
            SickoMode();
            warningBar.SetActive(true);
        }

        healthBar.UpdateBar(ppm, eventPeriod);
    }
    // Update is called once per frame
    protected virtual void Update()
    {
        if (!inputEnabled)
        {
            UpdateAnimation(true);
            return;
        }

        playerInput.UpdateInput();
        body.gravityScale = gravity;
        body.drag         = 0f;
        bool grounded = Grounded();

        if (squat)
        {
            squatCount++;
            //Debug.Log(squatCount);
        }

        //Tests Grounded()
        //if (grounded)
        //{
        //    sr.color = new Color(sr.color.r, sr.color.g, sr.color.b, 1f);
        //}
        //else
        //{
        //    sr.color = new Color(sr.color.r, sr.color.g, sr.color.b, 0.5f);
        //}

        int hDirection = (playerInput.xmovement < 0 && Movable()) ? -1 :
                         (playerInput.xmovement > 0 && Movable()) ? 1 : 0;


        float windSpeed = 0f;

        if (ClimateEvents.GetInstance().wind&& !grounded)
        {
            windSpeed = -3f;
        }
        Director.GetInstance().xVelocity = Mathf.Abs(horizontalSpeed) + GetCameraSpeed() * 0.6f + windSpeed;
        if (hDirection < 0)
        {
            body.velocity = new Vector2(horizontalSpeed * playerInput.xmovement + GetCameraSpeed() * 0.6f + windSpeed, body.velocity.y);
        }
        else if (hDirection > 0)
        {
            body.velocity = new Vector2(horizontalSpeed * playerInput.xmovement + GetCameraSpeed() * 0.6f + windSpeed, body.velocity.y);
        }
        else
        {
            if (grounded)
            {
                body.velocity = new Vector2(0, body.velocity.y);
            }
            else
            {
                body.velocity = new Vector2(GetCameraSpeed() * 0.6f, body.velocity.y);
            }
        }

        animator.SetBool("Jumpsquat", playerInput.up && Jumpable());
        if (playerInput.up && Jumpable())
        {
            if (!squat)
            {
                squat = true;
            }
        }
        if (playerInput.up)
        {
            body.gravityScale = gravity * 0.5f;
        }


        if (squatCount == SQUATLENGTH)
        {
            squat         = false;
            squatCount    = 0;
            body.velocity = new Vector2(body.velocity.x, jumpSpeed);

            // Change jump height based on if key is held
            //if (Input.GetKeyDown("up"))
            //{
            //    body.velocity = new Vector2(body.velocity.x, jumpSpeed);
            //}
            //else
            //{
            //    body.velocity = new Vector2(body.velocity.x, (int) 0.5 * jumpSpeed);
            //}
        }


        // animate with blend tree
        //animator.SetFloat("VelocityX", hDirection);
        if (hDirection != 0)
        {
            //animator.SetFloat("FacingX", hDirection);
            facingX = hDirection;
        }
        //animator.SetFloat("VelocityY", Mathf.Sign(body.velocity.y));
        //animator.SetBool("Grounded", grounded);

        if (hDirection > 0)
        {
            sr.flipX = false;
        }
        else if (hDirection < 0)
        {
            sr.flipX = true;
        }

        if (body.velocity.y < MAXFALLSPEED)
        {
            body.velocity = new Vector2(body.velocity.x, MAXFALLSPEED);
        }


        if (transform.position.x > CameraMovement.CameraRect().xMax)
        {
            transform.position = new Vector3(CameraMovement.CameraRect().xMax, transform.position.y, transform.position.z);
        }

        UpdateAnimation(grounded);
    }