本文整理汇总了C#中Ship.Update方法的典型用法代码示例。如果您正苦于以下问题:C# Ship.Update方法的具体用法?C# Ship.Update怎么用?C# Ship.Update使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Ship
的用法示例。
在下文中一共展示了Ship.Update方法的12个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: RotationBigUpdate
public void RotationBigUpdate()
{
var ship = new Ship(1000);
var initialOrientation = ship.Orientation;
var desiredOrientation = initialOrientation + Math.PI / 4;
ship.DesiredOrientation = desiredOrientation;
ship.Update(TimeSpan.MaxValue);
Assert.AreEqual(desiredOrientation, ship.Orientation, "Orientation didn't match");
ship.Update(TimeSpan.FromSeconds(0.25));
Assert.AreEqual(desiredOrientation, ship.Orientation, "Orientation didn't match, after another update");
}
示例2: TestCrazyAllStop
public void TestCrazyAllStop()
{
var ship = new Ship(4000);
Assert.AreEqual(0, ship.Velocity.Magnitude(), "new ship wasn't stopped");
ship.ImpulsePercentage = 100;
ship.Update(TimeSpan.FromSeconds(0.25));
ship.Update(TimeSpan.FromSeconds(0.25));
ship.Update(TimeSpan.FromSeconds(0.25));
ship.Update(TimeSpan.FromSeconds(0.25));
Assert.AreNotEqual(0, ship.Velocity.Magnitude(), "ship wasn't moving, after turning on impulse");
ship.DesiredOrientation = Math.PI / 2;
ship.Update(TimeSpan.FromSeconds(0.25));
ship.Update(TimeSpan.FromSeconds(0.25));
ship.Update(TimeSpan.FromSeconds(0.25));
ship.Update(TimeSpan.FromSeconds(0.25));
Assert.AreNotEqual(0, ship.Velocity.Magnitude(), "ship wasn't moving before telling it to stop");
ship.TargetSpeedMetersPerSecond = 0; // all stop
ship.Update(TimeSpan.FromSeconds(0.25));
Assert.AreNotEqual(0, ship.Velocity.Magnitude(), "ship wasn't moving, just after all stop");
ship.Update(TimeSpan.FromSeconds(0.25));
ship.Update(TimeSpan.FromSeconds(0.25));
ship.Update(TimeSpan.FromSeconds(0.25));
ship.Update(TimeSpan.FromSeconds(0.25));
ship.Update(TimeSpan.FromSeconds(0.25));
ship.Update(TimeSpan.FromSeconds(0.25));
ship.Update(TimeSpan.FromSeconds(0.25));
ship.Update(TimeSpan.FromSeconds(0.25)); // strictly speaking the previous one was really close to zero, so it should work, but one more actually makes it zero.
Assert.AreEqual(0, ship.Velocity.Magnitude(), "ship should be stopped by now?");
}
示例3: RotationBigManySmallUpdates
public void RotationBigManySmallUpdates()
{
var ship = new Ship(1000);
var initialOrientation = ship.Orientation;
var desiredOrientation = initialOrientation + Math.PI / 4;
ship.DesiredOrientation = desiredOrientation;
for (int i = 0; i < 10000; i++)
{
ship.Update(TimeSpan.FromMilliseconds(1));
}
Assert.AreEqual(desiredOrientation, ship.Orientation, "Orientation didn't match");
ship.Update(TimeSpan.FromSeconds(0.25));
Assert.AreEqual(desiredOrientation, ship.Orientation, "Orientation didn't match, after another update");
}
示例4: RunOutOfEnergy
public void RunOutOfEnergy()
{
var game = new Game();
var system = new StarSystem();
system.RandomlySpawnEnemies = false;
game.Add(system);
var ship = new Ship();
system.AddEntity(ship);
ship.ShieldsEngaged = false;
ship.ImpulsePercentage = 100;
Assert.IsTrue(ship.Energy > 0, "Ship didn't have any energy");
var oldVelocity = ship.Velocity;
Assert.AreEqual(0, ship.Velocity.Magnitude(), "Ship should be at rest at first");
for (int i = 0; i < 200; i++)
{
game.Update(TimeSpan.FromSeconds(0.25));
game.Update(TimeSpan.FromSeconds(0.25));
game.Update(TimeSpan.FromSeconds(0.25));
game.Update(TimeSpan.FromSeconds(0.25));
Assert.IsTrue(oldVelocity.Magnitude() < ship.Velocity.Magnitude(), "The ship didn't increase in speed");
oldVelocity = ship.Velocity;
}
Assert.AreEqual(0, ship.Energy, "The ship didn't run out of energy");
ship.Update(TimeSpan.FromSeconds(1));
Assert.AreEqual(oldVelocity, ship.Velocity, "The ship should not have been able to increase it's velocity without energy.");
}
示例5: TestRotate5Radians
public void TestRotate5Radians()
{
var ship = new Ship(1000);
Assert.AreEqual(0, ship.Velocity.Magnitude(), "new ship wasn't stopped");
ship.DesiredOrientation = 5;
ship.Update(TimeSpan.FromSeconds(50));
Assert.AreEqual(5.0, ship.Orientation, "ship wasn't finished turning");
}
示例6: IncreaseVelocity
public void IncreaseVelocity()
{
var ship = new Ship(1000);
ship.ImpulsePercentage = 100;
Assert.AreEqual(ship.Velocity, Vector3.Zero, "Ship wasn't created at rest");
ship.Update(TimeSpan.FromSeconds(0.25));
Assert.AreNotEqual(ship.Velocity, Vector3.Zero, "Ship isn't moving.");
Assert.AreNotEqual(ship.Position, Vector3.Zero, "Ship hasn't moved.");
}
示例7: ShouldNotRotateBackwards
public void ShouldNotRotateBackwards()
{
var ship = new Ship(1000);
ship.DesiredOrientation = 1;
for (int i = 0; i < 1000; i++)
{
ship.Update(TimeSpan.FromSeconds(0.25));
Assert.IsFalse(ship.Orientation < 0);
}
}
示例8: RotateNotWholeAmount
public void RotateNotWholeAmount()
{
var ship = new Ship(1000);
var initialOrientation = ship.Orientation;
var desiredOrientation = initialOrientation + Math.PI / 4;
ship.DesiredOrientation = desiredOrientation;
var oldDiffMag = Math.Abs(ship.Orientation - desiredOrientation);
ship.Update(TimeSpan.FromMilliseconds(1));
var newDiffMag = Math.Abs(ship.Orientation - desiredOrientation);
Assert.AreNotEqual(initialOrientation, ship.Orientation, "The orientation hasn't changed.");
Assert.IsTrue(newDiffMag < oldDiffMag, "We didn't get closer.");
}
示例9: UpdateShip
private void UpdateShip(GameTime gameTime, Ship ship)
{
Ship enemyShip;
if (ship == shipOne)
enemyShip = shipTwo;
else
enemyShip = shipOne;
if (ship.life > 0)
ship.Update(gameTime);
ship.UpdateAmmo(gameTime, ScreenManager, explosionParticles, enemyShip, buildingArray);
ship.UpdateVibration(gameTime);
}
示例10: TestAllStop5Radians
public void TestAllStop5Radians()
{
var ship = new Ship(4000);
Assert.AreEqual(0, ship.Velocity.Magnitude(), "new ship wasn't stopped");
ship.DesiredOrientation = 5;
ship.Update(TimeSpan.FromSeconds(50));
Assert.AreEqual(5.0, ship.Orientation, "ship wasn't finished turning");
ship.Update(TimeSpan.FromSeconds(0.25));
ship.ImpulsePercentage = 100;
ship.Update(TimeSpan.FromSeconds(0.25));
ship.Update(TimeSpan.FromSeconds(0.25));
ship.Update(TimeSpan.FromSeconds(0.25));
ship.Update(TimeSpan.FromSeconds(0.25));
ship.Update(TimeSpan.FromSeconds(0.25));
ship.Update(TimeSpan.FromSeconds(0.25));
ship.Update(TimeSpan.FromSeconds(0.25));
ship.Update(TimeSpan.FromSeconds(0.25));
ship.Update(TimeSpan.FromSeconds(0.25));
Assert.AreEqual(5, ship.Orientation, "ship turned during acceleration");
ship.TargetSpeedMetersPerSecond = 0;
ship.Update(TimeSpan.FromSeconds(0.25));
Assert.IsTrue(Utility.ApproximatelyEqual(5, ship.Orientation), "ship turned during all stop");
}
示例11: TestAllStop0Radians
public void TestAllStop0Radians()
{
var ship = new Ship(4000);
Assert.AreEqual(0, ship.Velocity.Magnitude(), "new ship wasn't stopped");
Assert.AreEqual(0, ship.Orientation, "ship wasn't oriented 0");
ship.Update(TimeSpan.FromSeconds(0.25));
ship.ImpulsePercentage = 100;
ship.Update(TimeSpan.FromSeconds(0.25));
ship.Update(TimeSpan.FromSeconds(0.25));
ship.Update(TimeSpan.FromSeconds(0.25));
ship.Update(TimeSpan.FromSeconds(0.25));
ship.Update(TimeSpan.FromSeconds(0.25));
ship.Update(TimeSpan.FromSeconds(0.25));
ship.Update(TimeSpan.FromSeconds(0.25));
ship.Update(TimeSpan.FromSeconds(0.25));
ship.Update(TimeSpan.FromSeconds(0.25));
Assert.AreEqual(0, ship.Orientation, "ship turned during acceleration");
ship.TargetSpeedMetersPerSecond = 0;
ship.Update(TimeSpan.FromSeconds(0.25));
ship.Update(TimeSpan.FromSeconds(0.25));
ship.Update(TimeSpan.FromSeconds(0.25));
ship.Update(TimeSpan.FromSeconds(0.25));
ship.Update(TimeSpan.FromSeconds(0.25));
ship.Update(TimeSpan.FromSeconds(0.25));
ship.Update(TimeSpan.FromSeconds(0.25));
ship.Update(TimeSpan.FromSeconds(0.25));
Assert.AreNotEqual(Vector3.Zero, ship.Velocity, "Ship couldn't have been stopped by now.");
Assert.IsTrue(Utility.ApproximatelyEqual(0, ship.Orientation), "ship turned during all stop");
ship.Update(TimeSpan.FromSeconds(0.25));
Assert.AreEqual(Vector3.Zero, ship.Velocity, "velocity wasn't stopped long after all stop message sent");
}
示例12: MissileTowardTarget
public void MissileTowardTarget()
{
var game = new Game();
var system = new StarSystem();
game.Add(system);
var ship = new Ship() { Tubes = 3 };
system.AddEntity(ship);
ship.ImpulsePercentage = 100;
ship.Update(TimeSpan.FromSeconds(0.25));
ship.Update(TimeSpan.FromSeconds(0.25));
ship.Update(TimeSpan.FromSeconds(0.25));
ship.Update(TimeSpan.FromSeconds(0.25));
Assert.AreNotEqual(0, ship.Position.X, "The ship should have moved along the x axis");
var missile = new Projectile();
system.AddEntity(missile);
Assert.AreEqual(0, missile.Position.X, "the missile was not at the center");
missile.Target = ship;
var oldDiff = ship.Position.X - missile.Position.X;
missile.Update(TimeSpan.FromSeconds(0.1));
var newDiff = ship.Position.X - missile.Position.X;
Assert.IsTrue(newDiff < oldDiff, "The missile didn't get closer to the ship");
}