Example #1
0
        public void Tick7Left2Right()
        {
            PlayerPhysics playerPhysics = new PlayerPhysics();
            var           acceleration  = playerPhysics.GetAcceleration();
            var           resistance    = playerPhysics.GetResistance();
            double        expectedVelocity;

            playerPhysics.AccelerateLeft();
            playerPhysics.CalculateVelocityThisTick();
            expectedVelocity = acceleration - resistance;
            playerPhysics.CalculateVelocityThisTick();
            expectedVelocity += acceleration - resistance;
            playerPhysics.CalculateVelocityThisTick();
            expectedVelocity += acceleration - resistance;
            playerPhysics.CalculateVelocityThisTick();
            expectedVelocity += acceleration - resistance;
            playerPhysics.CalculateVelocityThisTick();
            expectedVelocity += acceleration - resistance;
            playerPhysics.CalculateVelocityThisTick();
            expectedVelocity += acceleration - resistance;
            playerPhysics.CalculateVelocityThisTick();
            expectedVelocity += acceleration - resistance;
            playerPhysics.StopAccelerateLeft();

            playerPhysics.AccelerateRight();
            playerPhysics.CalculateVelocityThisTick();
            expectedVelocity += -acceleration - resistance;
            playerPhysics.CalculateVelocityThisTick();
            expectedVelocity += -acceleration - resistance;

            Assert.AreEqual(expectedVelocity, playerPhysics.GetVelocity());
        }
Example #2
0
        public void StopsWhenNoAcceleration()
        {
            PlayerPhysics playerPhysics = new PlayerPhysics();

            playerPhysics.AccelerateLeft();
            playerPhysics.CalculateVelocityThisTick();
            playerPhysics.CalculateVelocityThisTick();

            playerPhysics.StopAccelerateLeft();
            playerPhysics.CalculateVelocityThisTick();
            playerPhysics.CalculateVelocityThisTick();
            playerPhysics.CalculateVelocityThisTick();
            playerPhysics.CalculateVelocityThisTick();
            playerPhysics.CalculateVelocityThisTick();
            playerPhysics.CalculateVelocityThisTick();
            playerPhysics.CalculateVelocityThisTick();

            Assert.AreEqual(0, playerPhysics.GetVelocity());
        }