SimplePhysicsTests ClassDelta Engine Documentation
Inheritance Hierarchy

System Object
  DeltaEngine.Platforms TestWithMocksOrVisually
    DeltaEngine.Rendering2D.Tests SimplePhysicsTests

Namespace: DeltaEngine.Rendering2D.Tests
Assembly: DeltaEngine.Rendering2D.Tests (in DeltaEngine.Rendering2D.Tests.dll) Version: 1.1.1.0 (1.1.1)
Syntax

public class SimplePhysicsTests : TestWithMocksOrVisually

The SimplePhysicsTests type exposes the following members.

Constructors

  NameDescription
Public methodSimplePhysicsTests
Initializes a new instance of the SimplePhysicsTests class
Top
Methods

  NameDescription
Protected methodAdvanceTimeAndUpdateEntities (Inherited from TestWithMocksOrVisually.)
Public methodBounceOffScreenEdge
Public methodCreateWindowForScreenSpace
Public methodFallingEffectIsRemovedAfterOneSecond
Public methodInitializeResolver (Inherited from TestWithMocksOrVisually.)
Public methodKillSpriteAfterTimeout
Protected methodRegisterMock T  (Inherited from TestWithMocksOrVisually.)
Public methodRenderBouncingOffScreenEdgesSprite
Public methodRenderFallingCircle
Public methodRenderFallingCircleUsingExtension
Public methodRenderMovingCircleUsingExtension
Public methodRenderMovingUVSprite
Public methodRenderRotatingRect
Public methodRenderRotatingRectViaExtensionMethod
Public methodRenderSlowlyFallingLogo
Protected methodResolve T  (Inherited from TestWithMocksOrVisually.)
Public methodRotateAdvancesAngleCorrectly
Protected methodRunAfterFirstFrame (Inherited from TestWithMocksOrVisually.)
Public methodRunTestAndDisposeResolverWhenDone (Inherited from TestWithMocksOrVisually.)
Top
Properties

  NameDescription
Protected propertyIsMockResolver (Inherited from TestWithMocksOrVisually.)
Top
Examples

[Test, CloseAfterFirstFrame]
public void FallingEffectIsRemovedAfterOneSecond()
{
    var sprite = CreateFallingSpriteWhichExpires();
    CheckFallingEffectStateAfterOneSecond(sprite);
}
[Test]
public void RenderSlowlyFallingLogo()
{
    var sprite = new Sprite(new Material(ShaderFlags.Position2DTextured, "DeltaEngineLogo"),
        screenCenter);
    sprite.Add(new SimplePhysics.Data
    {
        Velocity = new Vector2D(0.0f, -0.3f),
        RotationSpeed = 100.0f,
        Gravity = new Vector2D(0.0f, 0.1f),
    });
    sprite.Color = Color.Red;
    sprite.Start<SimplePhysics.Move>();
}
[Test]
public void RenderFallingCircle()
{
    var ellipse = new Ellipse(Vector2D.Half, 0.1f, 0.1f, Color.Blue);
    ellipse.Add(new SimplePhysics.Data
    {
        Velocity = new Vector2D(0.1f, -0.1f),
        Gravity = new Vector2D(0.0f, 0.1f)
    });
    ellipse.Start<SimplePhysics.Move>();
}
[Test]
public void RenderMovingCircleUsingExtension()
{
    var ellipse = new Ellipse(Vector2D.Half, 0.1f, 0.1f, Color.Blue);
    ellipse.StartMoving(new Vector2D(0.1f, -0.1f));
}
[Test]
public void RenderFallingCircleUsingExtension()
{
    var ellipse = new Ellipse(Vector2D.Half, 0.1f, 0.1f, Color.Blue);
    ellipse.StartFalling(new Vector2D(0.1f, -0.1f), new Vector2D(0.0f, 0.1f));
}
[Test]
public void RenderRotatingRect()
{
    var rect = new FilledRect(Rectangle.FromCenter(Vector2D.Half, new Size(0.2f)), Color.Orange)
    {
        Rotation = 0
    };
    rect.Add(new SimplePhysics.Data { Gravity = Vector2D.Zero, RotationSpeed = 5 });
[Test]
public void RenderRotatingRectViaExtensionMethod()
{
    new FilledRect(Rectangle.FromCenter(Vector2D.Half, new Size(0.2f)), Color.Red).StartRotating(5);
}
[Test]
public void BounceOffScreenEdge()
{
    var rect =
        new FilledRect(new Rectangle(ScreenSpace.Current.Viewport.TopLeft, new Size(0.2f)),
            Color.Red);
    rect.Add(new SimplePhysics.Data
    {
        Gravity = Vector2D.Zero,
        Velocity = new Vector2D(-0.1f, 0.0f)
    });
    rect.Start<SimplePhysics.Move>();
    rect.Start<SimplePhysics.BounceIfAtScreenEdge>();
    var collided = false;
    rect.Get<SimplePhysics.Data>().Bounced += () => collided = true;
    AdvanceTimeAndUpdateEntities();
    Assert.IsTrue(collided);
    Assert.AreEqual(0.1f, rect.Get<SimplePhysics.Data>().Velocity.X);
}
[Test, CloseAfterFirstFrame]
public void RotateAdvancesAngleCorrectly()
{
    var rect = new FilledRect(new Rectangle(ScreenSpace.Current.Viewport.TopLeft, new Size(0.2f)),
        Color.Red);
    rect.Rotation = 0;
    rect.Add(new SimplePhysics.Data { Gravity = Vector2D.Zero, RotationSpeed = 0.1f });
[Test]
public void RenderMovingUVSprite()
{
    var sprite = new Sprite(new Material(ShaderFlags.Position2DTextured, "DeltaEngineLogo"),
        Rectangle.One);
    sprite.SetWithoutInterpolation(new Rectangle(0, 0, 0.1f, 0.1f));
    sprite.FlipMode = FlipMode.Vertical;
    sprite.StartMovingUV(Vector2D.One/10);
}
[Test]
public void RenderBouncingOffScreenEdgesSprite()
{
    var sprite = new Sprite(new Material(ShaderFlags.Position2DTextured, "DeltaEngineLogo"), 
        new Rectangle(Vector2D.Zero, new Size(0.1f)));
    sprite.StartBouncingOffScreenEdges(Vector2D.Half, () => { });
[Test]
public void KillSpriteAfterTimeout()
{
    var enemyMovingOutOfScreen =
        new Sprite(new Material(ShaderFlags.Position2DTextured, "DeltaEngineLogo"),
            new Rectangle(Vector2D.Half, new Size(0.1f)));
    var data = new SimplePhysics.Data { Velocity = new Vector2D(0.5f, 0), Duration = 1 };
    enemyMovingOutOfScreen.Add(data);
    enemyMovingOutOfScreen.Start<SimplePhysics.Move>();
    enemyMovingOutOfScreen.Start<SimplePhysics.KillAfterDurationReached>();
    if (IsMockResolver)
        AdvanceTimeAndUpdateEntities(1.1f);
}
See Also