public void Update(GameTime time) { timeSinceTurn += time.ElapsedGameTime.Milliseconds; var shouldTurn = false; if (timeSinceTurn >= IntervalRangeForTurn[1]) { shouldTurn = true; } else if (timeSinceTurn >= IntervalRangeForTurn[0]) { // 5% chance to turn each update during allowed interval shouldTurn = randomTurn.Next(0, 20) == 0; } if (shouldTurn) { MakeRandomTurn(); } previousPosition = Position; Position += MovementDirection * Speed; Collider.Position = Position; currentSprite.Update(time); }
public override void Update() { if (_playing) { _animation?.Update(Engine.DeltaTime); } }
public override void Update(double dt) { tex.Update(dt); player.Velocity -= Vec2.Clamp(new Vec2(0, player.Velocity.Y + player.Gravity), player.GAcc * dt); bool touch = false; if (GetTime() > DeathTime) { player.Respawn(); } foreach (var a in player.collisions.Values) { foreach (var b in a) { if (b.GetType() == typeof(Spikes)) { return; } else { touch = true; } } } if (touch) { player.Velocity = Vec2.Zero; } }
internal override bool Update(GameTime _GT) { mLifeSpanRemaining = mLifeSpanRemaining.TimerCountDown(_GT); mPosition = mPosition.ApplyVelocity(mVelocity, _GT, mMovementSpeed, 10.00); mMovementSpeed.DecreaseSpeed(mFriction, _GT); mTexture.Update(_GT); return(ShouldBeRemoved); }
public virtual void Update(double dt) { player.Velocity -= Vec2.Clamp(new Vec2(player.Velocity.X - player.Controller.NeedVel().X *player.Speed *player.SpeedUp, 0), player.Acc * player.SpeedUp * dt); AnimatedTexture tex = GetTexture(); if (tex != null) { tex.Update(dt); } }
public override void Update(double dt) { base.Update(dt); if (Game.Result != Result.Undefiend) { return; } if (p1 != null) { p1.Update(dt); } if (p2 != null) { p2.Update(dt); } }
public virtual void Update(GameTime gameTime, Player player, TileMap map, List <MovableItem> movableList) { if ((isAlive) & (deathTime <= 80)) { FrictionCount(); if (!canFly & isAlive & !isOnLadder) { GravitySimulation(); } IsOnObstracles(map); CheckEnviromentColision(map); CheckColisionWithMovables(movableList, map); UpdatePosition(); if (attacking > 0) { attacking--; } if (lifePoints <= 0) { isAlive = false; deathAnimation.UpdateRectangle(rectangle); velocity = Vector2.Zero; } } else { GravitySimulation(); CheckEnviromentColision(map); UpdatePosition(); deathTime++; deathAnimation.Update(gameTime, null); } animatedTexture.Update(gameTime, this); }
public void AnimatedTextureClassErrorBehavior() { // The size of the frame is larger than the image itself. var wrongFrameSize = new AnimatedTexture(Engine.AssetLoader.Get <TextureAsset>("Images/spritesheetAnimation.png"), new Vector2(125, 50), AnimationLoopType.Normal, 500, 0, 3); // Test the auto starting-ending frame constructor working with invalid frame sizes. var wrongFrameSizeAltConstructor = new AnimatedTexture(Engine.AssetLoader.Get <TextureAsset>("Images/spritesheetAnimation.png"), new Vector2(125, 50), AnimationLoopType.Normal, 500); var frameChange = new AnimatedTexture(Engine.AssetLoader.Get <TextureAsset>("Images/spritesheetAnimation.png"), new Vector2(50, 50), AnimationLoopType.Normal, 500, 0, 3); void DrawFrame(Action end) { // ReSharper disable AccessToModifiedClosure Runner.ExecuteAsLoop(_ => { RenderComposer composer = Engine.Renderer.StartFrame(); composer.RenderSprite(new Vector3(10, 10, 0), new Vector2(100, 100), Color.White, wrongFrameSize.Texture, wrongFrameSize.CurrentFrame); composer.RenderSprite(new Vector3(115, 10, 0), new Vector2(100, 100), Color.White, wrongFrameSizeAltConstructor.Texture, wrongFrameSizeAltConstructor.CurrentFrame); composer.RenderSprite(new Vector3(220, 10, 0), new Vector2(100, 100), Color.White, frameChange.Texture, frameChange.CurrentFrame); Engine.Renderer.EndFrame(); end(); }).WaitOne(); // ReSharper enable AccessToModifiedClosure } // The function which advances time for the animation. void AdvanceAnimation(float time) { wrongFrameSize.Update(time); wrongFrameSizeAltConstructor.Update(time); frameChange.Update(time); } // Perform unit tests. var wrongStartingFrame = new AnimatedTexture(Engine.AssetLoader.Get <TextureAsset>("Images/spritesheetAnimation.png"), new Vector2(50, 50), AnimationLoopType.Normal, 500, -10, 3); Assert.Equal(0, wrongStartingFrame.CurrentFrameIndex); wrongStartingFrame.Update(500); Assert.Equal(1, wrongStartingFrame.CurrentFrameIndex); Assert.Equal(3, wrongStartingFrame.AnimationFrames); Assert.Equal(0, wrongStartingFrame.StartingFrame); Assert.Equal(3, wrongStartingFrame.EndingFrame); Assert.Equal(500, wrongStartingFrame.TimeBetweenFrames); wrongStartingFrame = new AnimatedTexture(Engine.AssetLoader.Get <TextureAsset>("Images/spritesheetAnimation.png"), new Vector2(50, 50), AnimationLoopType.Normal, 500, 4, 3); Assert.Equal(0, wrongStartingFrame.CurrentFrameIndex); wrongStartingFrame.Update(500); Assert.Equal(1, wrongStartingFrame.CurrentFrameIndex); Assert.Equal(3, wrongStartingFrame.AnimationFrames); Assert.Equal(0, wrongStartingFrame.StartingFrame); Assert.Equal(3, wrongStartingFrame.EndingFrame); Assert.Equal(500, wrongStartingFrame.TimeBetweenFrames); wrongStartingFrame = new AnimatedTexture(Engine.AssetLoader.Get <TextureAsset>("Images/spritesheetAnimation.png"), new Vector2(50, 50), AnimationLoopType.Normal, 500, 3, 2); Assert.Equal(0, wrongStartingFrame.CurrentFrameIndex); wrongStartingFrame.Update(500); Assert.Equal(1, wrongStartingFrame.CurrentFrameIndex); Assert.Equal(2, wrongStartingFrame.AnimationFrames); Assert.Equal(0, wrongStartingFrame.StartingFrame); Assert.Equal(2, wrongStartingFrame.EndingFrame); Assert.Equal(500, wrongStartingFrame.TimeBetweenFrames); // Assert the objects are as expected. Assert.Equal(0, wrongFrameSize.AnimationFrames); Assert.Equal(0, wrongFrameSize.StartingFrame); Assert.Equal(0, wrongFrameSize.EndingFrame); Assert.Equal(500, wrongFrameSize.TimeBetweenFrames); Assert.Equal(0, wrongFrameSizeAltConstructor.AnimationFrames); Assert.Equal(0, wrongFrameSizeAltConstructor.StartingFrame); Assert.Equal(0, wrongFrameSizeAltConstructor.EndingFrame); Assert.Equal(500, wrongFrameSizeAltConstructor.TimeBetweenFrames); Assert.Equal(3, frameChange.AnimationFrames); Assert.Equal(0, frameChange.StartingFrame); Assert.Equal(3, frameChange.EndingFrame); Assert.Equal(500, frameChange.TimeBetweenFrames); // Capture starting frames. DrawFrame(() => { Runner.VerifyScreenshot(ResultDb.AnimatedTextureTest7); }); Assert.Equal(0, wrongFrameSize.CurrentFrameIndex); Assert.Equal(0, wrongFrameSizeAltConstructor.CurrentFrameIndex); Assert.Equal(0, frameChange.CurrentFrameIndex); // Move 500 ms into the future, as the frames are specified to change every 500ms. AdvanceAnimation(500); DrawFrame(() => { Runner.VerifyScreenshot(ResultDb.AnimatedTextureTest8); }); Assert.Equal(0, wrongFrameSize.CurrentFrameIndex); Assert.Equal(0, wrongFrameSizeAltConstructor.CurrentFrameIndex); Assert.Equal(1, frameChange.CurrentFrameIndex); // Change starting frame. frameChange.StartingFrame = 2; Assert.Equal(1, frameChange.CurrentFrameIndex); AdvanceAnimation(0); Assert.Equal(2, frameChange.CurrentFrameIndex); frameChange.StartingFrame = 1; AdvanceAnimation(0); Assert.Equal(2, frameChange.CurrentFrameIndex); // Move 500 ms into the future, as the frames are specified to change every 500ms. AdvanceAnimation(500); DrawFrame(() => { Runner.VerifyScreenshot(ResultDb.AnimatedTextureTest9); }); Assert.Equal(0, wrongFrameSize.CurrentFrameIndex); Assert.Equal(0, wrongFrameSizeAltConstructor.CurrentFrameIndex); Assert.Equal(3, frameChange.CurrentFrameIndex); // Change ending frame. frameChange.EndingFrame = 2; Assert.Equal(3, frameChange.CurrentFrameIndex); AdvanceAnimation(0); Assert.Equal(2, frameChange.CurrentFrameIndex); frameChange.EndingFrame = 3; AdvanceAnimation(0); Assert.Equal(2, frameChange.CurrentFrameIndex); // Move 500 ms into the future, as the frames are specified to change every 500ms. AdvanceAnimation(500); DrawFrame(() => { Runner.VerifyScreenshot(ResultDb.AnimatedTextureTest9); }); Assert.Equal(0, wrongFrameSize.CurrentFrameIndex); Assert.Equal(0, wrongFrameSizeAltConstructor.CurrentFrameIndex); Assert.Equal(3, frameChange.CurrentFrameIndex); // Move 500 ms into the future, as the frames are specified to change every 500ms. AdvanceAnimation(500); DrawFrame(() => { Runner.VerifyScreenshot(ResultDb.AnimatedTextureTest8); }); Assert.Equal(0, wrongFrameSize.CurrentFrameIndex); Assert.Equal(0, wrongFrameSizeAltConstructor.CurrentFrameIndex); Assert.Equal(1, frameChange.CurrentFrameIndex); // Move 500 ms into the future, as the frames are specified to change every 500ms. AdvanceAnimation(500); DrawFrame(() => { Runner.VerifyScreenshot(ResultDb.AnimatedTextureTest10); }); Assert.Equal(0, wrongFrameSize.CurrentFrameIndex); Assert.Equal(0, wrongFrameSizeAltConstructor.CurrentFrameIndex); Assert.Equal(2, frameChange.CurrentFrameIndex); // Ensure objects are as expected. Assert.Equal(0, wrongFrameSize.AnimationFrames); Assert.Equal(0, wrongFrameSize.StartingFrame); Assert.Equal(0, wrongFrameSize.EndingFrame); Assert.Equal(500, wrongFrameSize.TimeBetweenFrames); Assert.Equal(5, wrongFrameSize.LoopCount); Assert.Equal(0, wrongFrameSizeAltConstructor.AnimationFrames); Assert.Equal(0, wrongFrameSize.StartingFrame); Assert.Equal(0, wrongFrameSizeAltConstructor.EndingFrame); Assert.Equal(500, wrongFrameSizeAltConstructor.TimeBetweenFrames); Assert.Equal(5, wrongFrameSizeAltConstructor.LoopCount); Assert.Equal(2, frameChange.AnimationFrames); Assert.Equal(1, frameChange.StartingFrame); Assert.Equal(3, frameChange.EndingFrame); Assert.Equal(500, frameChange.TimeBetweenFrames); Assert.Equal(1, frameChange.LoopCount); wrongFrameSize = null; wrongFrameSizeAltConstructor = null; frameChange = null; Engine.AssetLoader.Destroy("Images/spritesheetAnimation.png"); }
public void AnimatedTextureClassDrawing() { var normalLoop = new AnimatedTexture(Engine.AssetLoader.Get <TextureAsset>("Images/spritesheetAnimation.png"), new Vector2(50, 50), AnimationLoopType.Normal, 500, 0, 3); // Test constructor without starting-ending frame as well. It should set the starting and ending frames to 0-3 as well. var noLoop = new AnimatedTexture(Engine.AssetLoader.Get <TextureAsset>("Images/spritesheetAnimation.png"), 2, 2, AnimationLoopType.None, 500); var normalThenReverse = new AnimatedTexture(Engine.AssetLoader.Get <TextureAsset>("Images/spritesheetAnimation.png"), new Vector2(50, 50), AnimationLoopType.NormalThenReverse, 500, 0, 3); var noLoopReverse = new AnimatedTexture(Engine.AssetLoader.Get <TextureAsset>("Images/spritesheetAnimation.png"), new Vector2(50, 50), AnimationLoopType.NoneReverse, 500, 0, 3); var reverseLoop = new AnimatedTexture(Engine.AssetLoader.Get <TextureAsset>("Images/spritesheetAnimation.png"), new Vector2(50, 50), AnimationLoopType.Reverse, 500); void DrawFrame(Action end) { // ReSharper disable AccessToModifiedClosure Runner.ExecuteAsLoop(_ => { RenderComposer composer = Engine.Renderer.StartFrame(); composer.RenderSprite(new Vector3(10, 10, 0), new Vector2(100, 100), Color.White, normalLoop.Texture, normalLoop.CurrentFrame); composer.RenderSprite(new Vector3(115, 10, 0), new Vector2(100, 100), Color.White, noLoop.Texture, noLoop.CurrentFrame); composer.RenderSprite(new Vector3(220, 10, 0), new Vector2(100, 100), Color.White, normalThenReverse.Texture, normalThenReverse.CurrentFrame); composer.RenderSprite(new Vector3(325, 10, 0), new Vector2(100, 100), Color.White, noLoopReverse.Texture, noLoopReverse.CurrentFrame); composer.RenderSprite(new Vector3(430, 10, 0), new Vector2(100, 100), Color.White, reverseLoop.Texture, reverseLoop.CurrentFrame); Engine.Renderer.EndFrame(); end(); }).WaitOne(); // ReSharper enable AccessToModifiedClosure } // The function which advances time for the animation. void AdvanceAnimation(float time) { noLoop.Update(time); normalLoop.Update(time); normalThenReverse.Update(time); noLoopReverse.Update(time); reverseLoop.Update(time); } // Assert the objects are as expected. Assert.Equal(3, normalLoop.AnimationFrames); Assert.Equal(0, normalLoop.StartingFrame); Assert.Equal(3, normalLoop.EndingFrame); Assert.Equal(500, normalLoop.TimeBetweenFrames); Assert.Equal(3, noLoop.AnimationFrames); Assert.Equal(0, noLoop.StartingFrame); Assert.Equal(3, noLoop.EndingFrame); Assert.Equal(500, noLoop.TimeBetweenFrames); Assert.Equal(3, normalThenReverse.AnimationFrames); Assert.Equal(0, normalThenReverse.StartingFrame); Assert.Equal(3, normalThenReverse.EndingFrame); Assert.Equal(500, normalThenReverse.TimeBetweenFrames); Assert.Equal(3, noLoopReverse.AnimationFrames); Assert.Equal(0, noLoopReverse.StartingFrame); Assert.Equal(3, noLoopReverse.EndingFrame); Assert.Equal(500, noLoopReverse.TimeBetweenFrames); Assert.Equal(3, reverseLoop.AnimationFrames); Assert.Equal(0, reverseLoop.StartingFrame); Assert.Equal(3, reverseLoop.EndingFrame); Assert.Equal(500, reverseLoop.TimeBetweenFrames); // Capture starting frames. DrawFrame(() => { Runner.VerifyScreenshot(ResultDb.AnimatedTextureTest1); }); Assert.Equal(0, normalLoop.CurrentFrameIndex); Assert.Equal(0, noLoop.CurrentFrameIndex); Assert.Equal(0, normalThenReverse.CurrentFrameIndex); Assert.Equal(3, noLoopReverse.CurrentFrameIndex); Assert.Equal(3, reverseLoop.CurrentFrameIndex); // Move 500 ms into the future, as the frames are specified to change every 500ms. AdvanceAnimation(500); DrawFrame(() => { Runner.VerifyScreenshot(ResultDb.AnimatedTextureTest2); }); Assert.Equal(1, normalLoop.CurrentFrameIndex); Assert.Equal(1, noLoop.CurrentFrameIndex); Assert.Equal(1, normalThenReverse.CurrentFrameIndex); Assert.Equal(2, noLoopReverse.CurrentFrameIndex); Assert.Equal(2, reverseLoop.CurrentFrameIndex); // Move 500 ms into the future, as the frames are specified to change every 500ms. AdvanceAnimation(500); DrawFrame(() => { Runner.VerifyScreenshot(ResultDb.AnimatedTextureTest3); }); Assert.Equal(2, normalLoop.CurrentFrameIndex); Assert.Equal(2, noLoop.CurrentFrameIndex); Assert.Equal(2, normalThenReverse.CurrentFrameIndex); Assert.Equal(1, noLoopReverse.CurrentFrameIndex); Assert.Equal(1, reverseLoop.CurrentFrameIndex); // Move 500 ms into the future, as the frames are specified to change every 500ms. AdvanceAnimation(500); DrawFrame(() => { Runner.VerifyScreenshot(ResultDb.AnimatedTextureTest4); }); Assert.Equal(3, normalLoop.CurrentFrameIndex); Assert.Equal(3, noLoop.CurrentFrameIndex); Assert.Equal(3, normalThenReverse.CurrentFrameIndex); Assert.Equal(0, noLoopReverse.CurrentFrameIndex); Assert.Equal(0, reverseLoop.CurrentFrameIndex); // Move 500 ms into the future, as the frames are specified to change every 500ms. AdvanceAnimation(500); DrawFrame(() => { Runner.VerifyScreenshot(ResultDb.AnimatedTextureTest5); }); Assert.Equal(0, normalLoop.CurrentFrameIndex); Assert.Equal(3, noLoop.CurrentFrameIndex); Assert.Equal(2, normalThenReverse.CurrentFrameIndex); Assert.Equal(0, noLoopReverse.CurrentFrameIndex); Assert.Equal(3, reverseLoop.CurrentFrameIndex); // Move 500 ms into the future, as the frames are specified to change every 500ms. AdvanceAnimation(500); DrawFrame(() => { Runner.VerifyScreenshot(ResultDb.AnimatedTextureTest6); }); Assert.Equal(1, normalLoop.CurrentFrameIndex); Assert.Equal(3, noLoop.CurrentFrameIndex); Assert.Equal(1, normalThenReverse.CurrentFrameIndex); Assert.Equal(0, noLoopReverse.CurrentFrameIndex); Assert.Equal(2, reverseLoop.CurrentFrameIndex); AdvanceAnimation(500); Assert.Equal(0, normalThenReverse.CurrentFrameIndex); // Ensure objects are as expected. Assert.Equal(3, normalLoop.AnimationFrames); Assert.Equal(0, normalLoop.StartingFrame); Assert.Equal(3, normalLoop.EndingFrame); Assert.Equal(500, normalLoop.TimeBetweenFrames); Assert.Equal(1, normalLoop.LoopCount); Assert.Equal(3, noLoop.AnimationFrames); Assert.Equal(0, noLoop.StartingFrame); Assert.Equal(3, noLoop.EndingFrame); Assert.Equal(500, noLoop.TimeBetweenFrames); Assert.Equal(1, noLoop.LoopCount); Assert.Equal(3, normalThenReverse.AnimationFrames); Assert.Equal(0, normalThenReverse.StartingFrame); Assert.Equal(3, normalThenReverse.EndingFrame); Assert.Equal(500, normalThenReverse.TimeBetweenFrames); Assert.Equal(1, normalThenReverse.LoopCount); Assert.Equal(3, noLoopReverse.AnimationFrames); Assert.Equal(0, noLoopReverse.StartingFrame); Assert.Equal(3, noLoopReverse.EndingFrame); Assert.Equal(500, noLoopReverse.TimeBetweenFrames); Assert.Equal(1, noLoopReverse.LoopCount); Assert.Equal(3, reverseLoop.AnimationFrames); Assert.Equal(0, reverseLoop.StartingFrame); Assert.Equal(3, reverseLoop.EndingFrame); Assert.Equal(500, reverseLoop.TimeBetweenFrames); Assert.Equal(1, reverseLoop.LoopCount); // Reset normalLoop.Reset(); noLoop.Reset(); normalThenReverse.Reset(); noLoopReverse.Reset(); reverseLoop.Reset(); // Ensure starting frame is reset. Assert.Equal(0, normalLoop.CurrentFrameIndex); Assert.Equal(0, noLoop.CurrentFrameIndex); Assert.Equal(0, normalThenReverse.CurrentFrameIndex); Assert.Equal(3, noLoopReverse.CurrentFrameIndex); Assert.Equal(3, reverseLoop.CurrentFrameIndex); // Ensure objects are as expected. Assert.Equal(3, normalLoop.AnimationFrames); Assert.Equal(0, normalLoop.StartingFrame); Assert.Equal(3, normalLoop.EndingFrame); Assert.Equal(500, normalLoop.TimeBetweenFrames); Assert.Equal(0, normalLoop.LoopCount); Assert.Equal(3, noLoop.AnimationFrames); Assert.Equal(0, noLoop.StartingFrame); Assert.Equal(3, noLoop.EndingFrame); Assert.Equal(500, noLoop.TimeBetweenFrames); Assert.Equal(0, noLoop.LoopCount); Assert.Equal(3, normalThenReverse.AnimationFrames); Assert.Equal(0, normalThenReverse.StartingFrame); Assert.Equal(3, normalThenReverse.EndingFrame); Assert.Equal(500, normalThenReverse.TimeBetweenFrames); Assert.Equal(0, normalThenReverse.LoopCount); Assert.Equal(3, noLoopReverse.AnimationFrames); Assert.Equal(0, noLoopReverse.StartingFrame); Assert.Equal(3, noLoopReverse.EndingFrame); Assert.Equal(500, noLoopReverse.TimeBetweenFrames); Assert.Equal(0, noLoopReverse.LoopCount); Assert.Equal(3, reverseLoop.AnimationFrames); Assert.Equal(0, reverseLoop.StartingFrame); Assert.Equal(3, reverseLoop.EndingFrame); Assert.Equal(500, reverseLoop.TimeBetweenFrames); Assert.Equal(0, reverseLoop.LoopCount); // Check if matching starting capture. DrawFrame(() => { Runner.VerifyScreenshot(ResultDb.AnimatedTextureTest1); }); Assert.Equal(0, normalLoop.CurrentFrameIndex); Assert.Equal(0, noLoop.CurrentFrameIndex); Assert.Equal(0, normalThenReverse.CurrentFrameIndex); Assert.Equal(3, noLoopReverse.CurrentFrameIndex); Assert.Equal(3, reverseLoop.CurrentFrameIndex); normalLoop = null; noLoop = null; normalThenReverse = null; noLoopReverse = null; reverseLoop = null; Engine.AssetLoader.Destroy("Images/spritesheetAnimation.png"); }
public override void Update(float fr) { _animatedTexture.Update(fr); }
public override void Update(KeyboardDevice keyboard) { atexture.Update(); }
public void AnimatedTextureClassErrorBehavior() { // References to the animated texture classes. AnimatedTexture wrongFrameSize = null; AnimatedTexture wrongFrameSizeAltConstructor = null; AnimatedTexture frameChange = null; // Create the test scene. TestScene extScene = new TestScene { // Load the animated texture classes. This also tests loading in another thread. ExtLoad = () => { // The size of the frame is larger than the image itself. wrongFrameSize = new AnimatedTexture(Engine.AssetLoader.Get <Texture>("Textures/spritesheetAnimation.png"), new Vector2(125, 50), AnimationLoopType.Normal, 500, 0, 3); // Test the auto starting-ending frame constructor working with invalid frame sizes. wrongFrameSizeAltConstructor = new AnimatedTexture(Engine.AssetLoader.Get <Texture>("Textures/spritesheetAnimation.png"), new Vector2(125, 50), AnimationLoopType.Normal, 500); frameChange = new AnimatedTexture(Engine.AssetLoader.Get <Texture>("Textures/spritesheetAnimation.png"), new Vector2(50, 50), AnimationLoopType.Normal, 500, 0, 3); }, // Unload the texture and the animated texture classes. ExtUnload = () => { wrongFrameSize = null; wrongFrameSizeAltConstructor = null; frameChange = null; Engine.AssetLoader.Destroy("Textures/spritesheetAnimation.png"); }, // Draw the current frames. ExtDraw = () => { Engine.Renderer.Render(new Vector3(10, 10, 0), new Vector2(100, 100), Color.White, wrongFrameSize.Texture, wrongFrameSize.CurrentFrame); Engine.Renderer.Render(new Vector3(115, 10, 0), new Vector2(100, 100), Color.White, wrongFrameSizeAltConstructor.Texture, wrongFrameSizeAltConstructor.CurrentFrame); Engine.Renderer.Render(new Vector3(220, 10, 0), new Vector2(100, 100), Color.White, frameChange.Texture, frameChange.CurrentFrame); } }; // The function which advances time for the animation. void AdvanceAnimation(float time) { wrongFrameSize.Update(time); wrongFrameSizeAltConstructor.Update(time); frameChange.Update(time); } // Add scene. Helpers.LoadScene(extScene); // Perform unit tests. AnimatedTexture wrongStartingFrame = new AnimatedTexture(Engine.AssetLoader.Get <Texture>("Textures/spritesheetAnimation.png"), new Vector2(50, 50), AnimationLoopType.Normal, 500, -10, 3); Assert.Equal(0, wrongStartingFrame.CurrentFrameIndex); wrongStartingFrame.Update(500); Assert.Equal(1, wrongStartingFrame.CurrentFrameIndex); Assert.Equal(3, wrongStartingFrame.AnimationFrames); Assert.Equal(0, wrongStartingFrame.StartingFrame); Assert.Equal(3, wrongStartingFrame.EndingFrame); Assert.Equal(500, wrongStartingFrame.TimeBetweenFrames); wrongStartingFrame = new AnimatedTexture(Engine.AssetLoader.Get <Texture>("Textures/spritesheetAnimation.png"), new Vector2(50, 50), AnimationLoopType.Normal, 500, 4, 3); Assert.Equal(0, wrongStartingFrame.CurrentFrameIndex); wrongStartingFrame.Update(500); Assert.Equal(1, wrongStartingFrame.CurrentFrameIndex); Assert.Equal(3, wrongStartingFrame.AnimationFrames); Assert.Equal(0, wrongStartingFrame.StartingFrame); Assert.Equal(3, wrongStartingFrame.EndingFrame); Assert.Equal(500, wrongStartingFrame.TimeBetweenFrames); wrongStartingFrame = new AnimatedTexture(Engine.AssetLoader.Get <Texture>("Textures/spritesheetAnimation.png"), new Vector2(50, 50), AnimationLoopType.Normal, 500, 3, 2); Assert.Equal(0, wrongStartingFrame.CurrentFrameIndex); wrongStartingFrame.Update(500); Assert.Equal(1, wrongStartingFrame.CurrentFrameIndex); Assert.Equal(2, wrongStartingFrame.AnimationFrames); Assert.Equal(0, wrongStartingFrame.StartingFrame); Assert.Equal(2, wrongStartingFrame.EndingFrame); Assert.Equal(500, wrongStartingFrame.TimeBetweenFrames); // Assert the objects are as expected. Assert.Equal(0, wrongFrameSize.AnimationFrames); Assert.Equal(0, wrongFrameSize.StartingFrame); Assert.Equal(0, wrongFrameSize.EndingFrame); Assert.Equal(500, wrongFrameSize.TimeBetweenFrames); Assert.Equal(0, wrongFrameSizeAltConstructor.AnimationFrames); Assert.Equal(0, wrongFrameSizeAltConstructor.StartingFrame); Assert.Equal(0, wrongFrameSizeAltConstructor.EndingFrame); Assert.Equal(500, wrongFrameSizeAltConstructor.TimeBetweenFrames); Assert.Equal(3, frameChange.AnimationFrames); Assert.Equal(0, frameChange.StartingFrame); Assert.Equal(3, frameChange.EndingFrame); Assert.Equal(500, frameChange.TimeBetweenFrames); // Capture starting frames. Assert.Equal("BE+gi0MdZrqWI2S3owCkiS1evwbyTlPxZtdwwJDwQn4=", Helpers.TakeScreenshot()); Assert.Equal(0, wrongFrameSize.CurrentFrameIndex); Assert.Equal(0, wrongFrameSizeAltConstructor.CurrentFrameIndex); Assert.Equal(0, frameChange.CurrentFrameIndex); // Move 500 ms into the future, as the frames are specified to change every 500ms. AdvanceAnimation(500); extScene.WaitFrames(2).Wait(); Assert.Equal("Fwq9SouHAzrTtWoa24vZCaogWoKlh2Z38h2L17lNNw4=", Helpers.TakeScreenshot()); Assert.Equal(0, wrongFrameSize.CurrentFrameIndex); Assert.Equal(0, wrongFrameSizeAltConstructor.CurrentFrameIndex); Assert.Equal(1, frameChange.CurrentFrameIndex); // Change starting frame. frameChange.StartingFrame = 2; Assert.Equal(1, frameChange.CurrentFrameIndex); AdvanceAnimation(0); Assert.Equal(2, frameChange.CurrentFrameIndex); frameChange.StartingFrame = 1; AdvanceAnimation(0); Assert.Equal(2, frameChange.CurrentFrameIndex); // Move 500 ms into the future, as the frames are specified to change every 500ms. AdvanceAnimation(500); extScene.WaitFrames(2).Wait(); Assert.Equal("sqFDVON43bN6e0fbCkKIKLRQVNq1KxknUjUs4mY04Xw=", Helpers.TakeScreenshot()); Assert.Equal(0, wrongFrameSize.CurrentFrameIndex); Assert.Equal(0, wrongFrameSizeAltConstructor.CurrentFrameIndex); Assert.Equal(3, frameChange.CurrentFrameIndex); // Change ending frame. frameChange.EndingFrame = 2; Assert.Equal(3, frameChange.CurrentFrameIndex); AdvanceAnimation(0); Assert.Equal(2, frameChange.CurrentFrameIndex); frameChange.EndingFrame = 3; AdvanceAnimation(0); Assert.Equal(2, frameChange.CurrentFrameIndex); // Move 500 ms into the future, as the frames are specified to change every 500ms. AdvanceAnimation(500); extScene.WaitFrames(2).Wait(); Assert.Equal("sqFDVON43bN6e0fbCkKIKLRQVNq1KxknUjUs4mY04Xw=", Helpers.TakeScreenshot()); Assert.Equal(0, wrongFrameSize.CurrentFrameIndex); Assert.Equal(0, wrongFrameSizeAltConstructor.CurrentFrameIndex); Assert.Equal(3, frameChange.CurrentFrameIndex); // Move 500 ms into the future, as the frames are specified to change every 500ms. AdvanceAnimation(500); extScene.WaitFrames(2).Wait(); Assert.Equal("Fwq9SouHAzrTtWoa24vZCaogWoKlh2Z38h2L17lNNw4=", Helpers.TakeScreenshot()); Assert.Equal(0, wrongFrameSize.CurrentFrameIndex); Assert.Equal(0, wrongFrameSizeAltConstructor.CurrentFrameIndex); Assert.Equal(1, frameChange.CurrentFrameIndex); // Move 500 ms into the future, as the frames are specified to change every 500ms. AdvanceAnimation(500); extScene.WaitFrames(2).Wait(); Assert.Equal("9RHVfW82y/uvEHsI7GMqzg1m2N7tuOyoZHtmkymSlLE=", Helpers.TakeScreenshot()); Assert.Equal(0, wrongFrameSize.CurrentFrameIndex); Assert.Equal(0, wrongFrameSizeAltConstructor.CurrentFrameIndex); Assert.Equal(2, frameChange.CurrentFrameIndex); // Ensure objects are as expected. Assert.Equal(0, wrongFrameSize.AnimationFrames); Assert.Equal(0, wrongFrameSize.StartingFrame); Assert.Equal(0, wrongFrameSize.EndingFrame); Assert.Equal(500, wrongFrameSize.TimeBetweenFrames); Assert.Equal(5, wrongFrameSize.LoopCount); Assert.Equal(0, wrongFrameSizeAltConstructor.AnimationFrames); Assert.Equal(0, wrongFrameSize.StartingFrame); Assert.Equal(0, wrongFrameSizeAltConstructor.EndingFrame); Assert.Equal(500, wrongFrameSizeAltConstructor.TimeBetweenFrames); Assert.Equal(5, wrongFrameSizeAltConstructor.LoopCount); Assert.Equal(2, frameChange.AnimationFrames); Assert.Equal(1, frameChange.StartingFrame); Assert.Equal(3, frameChange.EndingFrame); Assert.Equal(500, frameChange.TimeBetweenFrames); Assert.Equal(1, frameChange.LoopCount); // Cleanup. Helpers.UnloadScene(); }