Exemplo n.º 1
0
    public void FixedUpdate()
    {
        if (GameCtr != null &&
            (GameCtr.gameEnded || GameCtr.introPlaying || GameCtr.outroPlaying))
        {
            return;
        }

        #region Movement
        float horizontal = staticService.GetInputAxis("Horizontal");
        float vertical   = (-1) * staticService.GetInputAxis("Vertical");

        if (charContr != null)
        {
            Vector3 movement = stats.CalcMovement(horizontal, vertical, staticService.GetDeltaTime());

            charContr.Move(movement);

            if (movement != Vector3.zero)
            {
                transform.rotation = Quaternion.Slerp(transform.rotation, Quaternion.LookRotation(movement.normalized), 0.3f);
            }

            if (!charContr.isGrounded)
            {
                charContr.Move(new Vector3(0, gravityValue, 0));
            }
        }

        #endregion Movement
    }
Exemplo n.º 2
0
// ------------------------------------ helper methods -------------------------------------------------

    IUnityStaticService CreateUnityService(float deltaTimeReturn, float horizontalReturn, float verticalReturn)
    {
        IUnityStaticService s = Substitute.For <IUnityStaticService>();

        s.GetDeltaTime().Returns(deltaTimeReturn);
        s.GetInputAxis("Horizontal").Returns(horizontalReturn);
        s.GetInputAxis("Vertical").Returns(verticalReturn);

        return(s);
    }
Exemplo n.º 3
0
    public void Test_PlayerMovementIsCalculatedCorrectly()
    {
        PlayerStatsClass    stats         = new PlayerStatsClass();
        IUnityStaticService staticService = CreateUnityService(1, 1, 1);

        float expectedX = staticService.GetInputAxis("Horizontal") * stats.playerSpeed * staticService.GetDeltaTime();
        float expectedY = 0;
        float expectedZ = staticService.GetInputAxis("Vertical") * stats.playerSpeed * staticService.GetDeltaTime();

        Vector3 calculatedMovement = stats.CalcMovement(staticService.GetInputAxis("Horizontal"), staticService.GetInputAxis("Vertical"), staticService.GetDeltaTime());

        Assert.NotZero(calculatedMovement.magnitude, "Player movement calculation resulted in no movement!");
        Assert.AreEqual(calculatedMovement.x, expectedX, "Player movement calculation did not return the expected x movement!");
        Assert.AreEqual(calculatedMovement.y, expectedY, "Player movement calculation did not return the expected y movement!");
        Assert.AreEqual(calculatedMovement.z, expectedZ, "Player movement calculation did not return the expected z movement!");
    }
Exemplo n.º 4
0
    public void Test_PlayerDoesntMoveWithoutInput()
    {
        PlayerStatsClass    stats         = new PlayerStatsClass();
        IUnityStaticService staticService = CreateUnityService(1, 0, 0);

        Vector3 calculatedMovement = stats.CalcMovement(staticService.GetInputAxis("Horizontal"), staticService.GetInputAxis("Vertical"), staticService.GetDeltaTime());

        Assert.Zero(calculatedMovement.magnitude, "Player moved without input!");
    }
Exemplo n.º 5
0
    public void Test_PlayerCantMoveWhileInBattle()
    {
        PlayerStatsClass    stats         = new PlayerStatsClass();
        IUnityStaticService staticService = CreateUnityService(1, 1, 1);
        IGameController     ctr           = Substitute.For <IGameController>();

        ctr.IsInBattle().Returns(true);
        IPlayer mockPlayer = Substitute.For <IPlayer>();

        mockPlayer.GetGameController().Returns(ctr);
        stats.SetPlayerAddition(mockPlayer);

        Vector3 calculatedMovement = stats.CalcMovement(staticService.GetInputAxis("Horizontal"), staticService.GetInputAxis("Vertical"), staticService.GetDeltaTime());

        Assert.Zero(calculatedMovement.magnitude, "Player was able to move while in battle!");
    }