Exemplo n.º 1
0
    public override void Awake()
    {
        base.Awake();

        stats.Add(new Dictionary <string, object>()
        {
            ["topSpeedNormal"]  = 6F,
            ["topSpeedSpeedUp"] = 12F,
            ["topSpeed"]        = (Func <string>)(() => HasEffect("speedUp") ? "topSpeedSpeedUp" : "topSpeedNormal"),
            ["terminalSpeed"]   = 16.5F
        });

        LevelManager.current.characters.Add(this);
        playerId = LevelManager.current.GetFreePlayerId();
        input    = new InputCustom(1);

        InitReferences();

        Level levelDefault = FindObjectOfType <Level>();

        if (currentLevel == null)
        {
            currentLevel         = levelDefault;
            respawnData.position = levelDefault.spawnPosition;
            Respawn();
        }

        if (GlobalOptions.GetBool("tinyMode"))
        {
            sizeScale = 0.5F;
        }
    }
Exemplo n.º 2
0
    // Gets rotation for sprite
    // 3D-Ready: No
    public Vector3 GetSpriteRotation(float deltaTime)
    {
        if (!GlobalOptions.GetBool("smoothRotation"))
        {
            return((transform.eulerAngles / 45F).Round(0) * 45F);
        }

        Vector3 currentRotation = sprite.transform.eulerAngles;
        bool    shouldRotate    = Mathf.Abs(Mathf.DeltaAngle(0, forwardAngle)) > 45;

        Vector3 targetAngle;

        if (shouldRotate)
        {
            targetAngle = transform.eulerAngles;
            if (forwardAngle > 180 && currentRotation.z == 0)
            {
                currentRotation.z = 360;
            }
        }
        else
        {
            targetAngle = currentRotation.z > 180 ?
                          new Vector3(0, 0, 360) : Vector3.zero;
        }

        return(Vector3.RotateTowards(
                   currentRotation,       // current
                   targetAngle,           // target // TODO: 3D
                   10F * deltaTime * 60F, // max rotation
                   10F * deltaTime * 60F  // magnitude
                   ));
    }
Exemplo n.º 3
0
    void Update()
    {
        integerScaling = GlobalOptions.GetBool("integerScaling");

        if (LevelManager.current != null)
        {
            integerScaling &= LevelManager.current.characters.Count <= 1;
        }
    }
Exemplo n.º 4
0
    public virtual void Update()
    {
        Utils.SetFramerate();

        float deltaTime = Utils.cappedUnscaledDeltaTime;

        // Limit small fluctuations in deltatime
        deltaTime = Mathf.Round(deltaTime * Application.targetFrameRate) / Application.targetFrameRate;

        if (deltaTime <= 2F / Application.targetFrameRate)
        {
            deltaTime = 1F / Application.targetFrameRate;
        }

        InputCustom.preventRepeatLock = false;

        // We update the frame in a loop over the current delta time to allow
        // the game to catch up if it lags.
        while (deltaTime > 0)
        {
            float modDeltaTime = deltaTime > 1F / 60F ? 1F / 60F : deltaTime;

            // (meme)
            if (GlobalOptions.GetBool("gbaMode"))
            {
                modDeltaTime += (Random.value * 0.032F) - 0.016F;
            }

            foreach (GameBehaviour gameBehaviour in GameBehaviour.allGameBehvaiours)
            {
                float gbDeltaTime = gameBehaviour.useUnscaledDeltaTime ? modDeltaTime : modDeltaTime * Time.timeScale;
                gameBehaviour.UpdateDelta(gbDeltaTime);
            }

            // Run multiple simulations per frame to avoid clipping.
            // Without this, the character sometimes clips into the ground slightly before popping out.
            for (int i = 0; i < physicsStepsPerFrame; i++)
            {
                Physics.Simulate(modDeltaTime * Time.timeScale * (1F / physicsStepsPerFrame));
            }

            foreach (GameBehaviour gameBehaviour in GameBehaviour.allGameBehvaiours)
            {
                float gbDeltaTime = gameBehaviour.useUnscaledDeltaTime ? modDeltaTime : modDeltaTime * Time.timeScale;
                gameBehaviour.LateUpdateDelta(gbDeltaTime);
            }

            // Since we're updating the character multiple times per frame, we
            // need to prevent Input.GetButtonDown from firing multiple times.
            InputCustom.preventRepeatLock = true;
            deltaTime -= modDeltaTime;
        }
    }
    void Start()
    {
        if (!GlobalOptions.GetBool("elementalShields"))
        {
            switch (type)
            {
            case ContentsType.ShieldElectricity:
            case ContentsType.ShieldBubble:
            case ContentsType.ShieldFire:
                type = ContentsType.Shield;
                break;
            }
        }

        animator.Play(ContentsAnimations[(int)type]);
    }
Exemplo n.º 6
0
    public override void Start()
    {
        capabilities.Add(new CharacterCapabilityGround(this));
        capabilities.Add(new CharacterCapabilityAir(this));
        capabilities.Add(new CharacterCapabilityHurt(this));

        if (GlobalOptions.GetBool("spindash"))
        {
            capabilities.Add(new CharacterCapabilitySpindash(this));
        }

        if (GlobalOptions.GetBool("peelOut"))
        {
            capabilities.Add(new CharacterCapabilityPeelOut(this));
        }

        if (GlobalOptions.GetBool("dropDash"))
        {
            capabilities.Add(new CharacterCapabilityDropdash(this));
        }

        if (GlobalOptions.GetBool("homingAttack"))
        {
            capabilities.Add(new CharacterCapabilityHomingAttack(this));
        }

        if (GlobalOptions.GetBool("lightDash"))
        {
            capabilities.Add(new CharacterCapabilityLightDash(this));
        }

        capabilities.Add(new CharacterCapabilityJump(this));
        capabilities.Add(new CharacterCapabilityRolling(this));
        capabilities.Add(new CharacterCapabilityRollingAir(this));
        capabilities.Add(new CharacterCapabilityVictory(this));
        capabilities.Add(new CharacterCapabilityDeath(this));

        if (GlobalOptions.GetBool("afterImages"))
        {
            capabilities.Add(new CharacterCapabilityAfterImage(this));
        }

        base.Start();
    }
 public override void Update(float deltaTime)
 {
     if (!character.InStateGroup("air") || !character.InStateGroup("rolling"))
     {
         if (!GlobalOptions.GetBool("airCurling"))
         {
             return;
         }
         if (character.InStateGroup("air") && character.input.GetButtonDownPreventRepeat("Primary"))
         {
             character.stateCurrent = "jump";
         }
         else
         {
             return;
         }
     }
     ;
     character.eulerAngles = Vector3.zero;
 }
Exemplo n.º 8
0
    //balence state reappears here
    // Updates the character's animation while they're on the ground
    // 3D-Ready: NO
    void UpdateGroundAnim(float deltaTime)
    {
        bool ignoreFlipX = false;

        character.spriteAnimatorSpeed = 1;

        // Check if we are transitioning to a rolling air state. If so, set the speed of it
        if (character.InStateGroup("rolling") && character.InStateGroup("air"))
        {
            character.spriteAnimatorSpeed = 1 + (
                (
                    Mathf.Abs(character.groundSpeed) /
                    character.stats.Get("topSpeedNormal")
                ) * 2F
                );
        }
        else
        {
            // Turning
            // ======================
            if (character.pressingLeft && (character.groundSpeed < 0))
            {
                character.facingRight = false;
            }
            else if (character.pressingRight && (character.groundSpeed > 0))
            {
                character.facingRight = true;
            }

            // Skidding
            // ======================
            var skidding = (
                (character.pressingRight && character.groundSpeed < 0) ||
                (character.pressingLeft && character.groundSpeed > 0)
                );

            // You can only trigger a skid state if:
            // - Your angle (a) is <= 45d or >= 270d and your absolute speed is above the threshhold
            // - OR you're already skidding
            var canSkid = (
                (
                    (
                        (character.forwardAngle <= 45F) ||
                        (character.forwardAngle >= 270F)
                    ) && (
                        Mathf.Abs(character.groundSpeed) >= character.stats.Get("skidThreshold")
                        )
                ) || character.spriteAnimator.GetCurrentAnimatorStateInfo(0).IsName("Skid")
                );

            // Standing still, looking up/down, idle animation
            // ======================
            if (character.groundSpeed == 0)
            {
                if (character.input.GetAxisNegative("Vertical"))
                {
                    character.AnimatorPlay("Look Down");
                }
                else if (character.input.GetAxisPositive("Vertical"))
                {
                    character.AnimatorPlay("Look Up");
                }
                //seen specificly here (weirdly enough it looks somewhat like our own code just with less transations)
                else if (character.balanceState != Character.BalanceState.None)
                {
                    ignoreFlipX     = true;
                    character.flipX = character.balanceState == Character.BalanceState.Right;
                    character.AnimatorPlay("Balancing");
                }
                else
                {
                    if (
                        !character.spriteAnimator.GetCurrentAnimatorStateInfo(0).IsName("Tap") &&
                        !character.spriteAnimator.GetCurrentAnimatorStateInfo(0).IsName("Idle")
                        )
                    {
                        character.AnimatorPlay("Idle");
                    }
                }
                // Pushing anim
                // ======================
            }
            else if (pushing)
            {
                character.AnimatorPlay("Push");
                character.spriteAnimatorSpeed = 1 + (Mathf.Abs(character.groundSpeed) / character.stats.Get("topSpeedNormal"));
                // Skidding, again
                // ======================
            }
            else if (skidding && canSkid)
            {
                if (!character.spriteAnimator.GetCurrentAnimatorStateInfo(0).IsName("Skid"))
                {
                    SFX.Play(character.audioSource, "sfxSkid");
                }

                character.AnimatorPlay("Skid");
                // Walking
                // ======================
            }
            else if (Mathf.Abs(character.groundSpeed) < character.stats.Get("topSpeedNormal"))
            {
                character.AnimatorPlay("Walk");
                character.spriteAnimatorSpeed = 1 + (Mathf.Abs(character.groundSpeed) / character.stats.Get("topSpeedNormal"));
                // Running Fast
                // ======================
            }
            else if (
                (Mathf.Abs(character.groundSpeed) >= 10F * character.physicsScale) &&
                GlobalOptions.GetBool("peelOut")
                )
            {
                character.AnimatorPlay("Fast");
                character.spriteAnimatorSpeed = Mathf.Abs(character.groundSpeed) / character.stats.Get("topSpeedNormal");
            }
            else
            {
                // Running
                // ======================
                character.AnimatorPlay("Run");
                character.spriteAnimatorSpeed = Mathf.Abs(character.groundSpeed) / character.stats.Get("topSpeedNormal");
            }
        }

        // Final value application
        // ======================
        character.spriteContainer.transform.eulerAngles = character.GetSpriteRotation(deltaTime);
        if (!ignoreFlipX)
        {
            character.flipX = !character.facingRight;
        }

        pushing = false;
    }
Exemplo n.º 9
0
    public void Update()
    {
        canvas.worldCamera = character.characterCamera.camera;
        // Debug.Log(character.characterCamera.camera);

        scoreText.text = Utils.IntToStrCached(character.score);
        ringsText.text = Utils.IntToStrCached(character.rings);
        livesText.text = Utils.IntToStrCached(character.lives);

        int minutes = (int)(character.timer / 60);
        int seconds = (int)(character.timer % 60);

        sb.Clear();
        sb.Append(Utils.IntToStrCached(minutes));
        sb.Append(":");
        if (seconds < 10)
        {
            sb.Append("0");
        }
        sb.Append(Utils.IntToStrCached(seconds));

        if (GlobalOptions.Get("timerType") != "NORMAL")
        {
            sb.Append(":");
            int preciseTime = 0;

            if (GlobalOptions.Get("timerType") == "CENTISECOND")
            {
                preciseTime = (int)((character.timer % 1) * 100F);
            }

            if (GlobalOptions.Get("timerType") == "FRAMES")
            {
                preciseTime = (int)((character.timer * 60) % 60);
            }

            if (preciseTime < 10)
            {
                sb.Append("0");
            }
            sb.Append(Utils.IntToStrCached(preciseTime));
        }

        timeText.text = sb.ToString();

        bool shouldFlash = (((int)(Time.unscaledTime * 60)) % 16) > 8;

        if (shouldFlash)
        {
            if (character.rings <= 0)
            {
                ringsTitleText.color = Color.red;
            }

            if (GlobalOptions.GetBool("timeLimit"))
            {
                if (character.timer >= 9 * 60)
                {
                    timeTitleText.color = Color.red;
                }
            }
        }
        else
        {
            timeTitleText.color  = Color.white;
            ringsTitleText.color = Color.white;
        }
    }