/// <summary> /// Checks the currently pressed keys and changes the acceleration vector accordingly /// </summary> private void ApplyAcceleration() { var shape = Shape.AsDynamicShape(); if (mA[0] == 1 && mA[1] == 0 && mA[2] == 0) { Force.ApplyForce(new Vec2F(-Constants.TAXI_ACCEL_X, 0f), shape); taxiDirection = TaxiDirection.Left; } else if (mA[0] == 1 && mA[1] == 1 && mA[2] == 0) { Force.ApplyForce(new Vec2F(-Constants.TAXI_ACCEL_X, Constants.TAXI_ACCEL_Y), shape); taxiDirection = TaxiDirection.LeftAndUp; } else if (mA[0] == 0 && mA[1] == 1 && mA[2] == 0) { Force.ApplyForce(new Vec2F(0f, Constants.TAXI_ACCEL_Y), shape); taxiDirection = TaxiDirection.Up; } else if (mA[0] == 0 && mA[1] == 1 && mA[2] == 1) { Force.ApplyForce(new Vec2F(Constants.TAXI_ACCEL_X, Constants.TAXI_ACCEL_Y), shape); taxiDirection = TaxiDirection.RightAndUp; } else if (mA[0] == 0 && mA[1] == 0 && mA[2] == 1) { Force.ApplyForce(new Vec2F(Constants.TAXI_ACCEL_X, 0f), shape); taxiDirection = TaxiDirection.Right; } else if (mA[0] == 0 && mA[1] == 0 && mA[2] == 0) { taxiDirection = TaxiDirection.None; } Force.ApplyGravity(shape.AsDynamicShape()); }
public void ApplyForceAppliesCorrectAcceleration(float x, float y) { var forceApplied = new Vec2F(x, y); Force.ApplyForce(forceApplied, testShape); //measure movement caused by ApplyGravity var dX = Math.Abs(testShape.Position.X) - Math.Abs(forceApplied.X); var dY = Math.Abs(testShape.Position.Y) - Math.Abs(forceApplied.Y); Assert.IsTrue(((dX < AcceptableDeviance) && (dY < AcceptableDeviance))); }
public void CustomerCollisionMarksCustomerForDeletion() { var player = new Player(null, null); player.Shape.Position = //set to same y value as customer to ensure collision new Vec2F( testCustomer.Shape.Position.X + 4 * Constants.EXTENT_X, testCustomer.Shape.Position.Y); for (int i = 0; i < 100; i++) { Force.ApplyForce(new Vec2F(0.01f, 0), testCustomer.Shape.AsDynamicShape()); testCustomer.Shape.Move(); testCustomer.Collision(player.Shape.AsDynamicShape()); } Assert.AreEqual(true, testCustomer.IsDeleted()); }
public void TestObstacleCollision() { int i = 0; while (i < 50) { Force.ApplyForce(new Vec2F(0.1f, 0), player.Shape.AsDynamicShape()); player.Shape.Move(); if (obstacle.Collision(player.Shape.AsDynamicShape())) { break; } i++; } Assert.IsTrue(i < 50); }
/// <summary> /// Update function which moves the customer. /// </summary> public void Update(Shape platform) { var shape = Shape.AsDynamicShape(); shape.Move(); Force.ApplyForce( direction == CustomerDirection.Right ? new Vec2F(Constants.CUSTOMER_ACCEL_X, 0) : new Vec2F(-Constants.CUSTOMER_ACCEL_X, 0), Shape.AsDynamicShape()); if (Shape.Position.X + Shape.Extent.X > platform.Position.X + platform.Extent.X) { TurnAround(); } else if (Shape.Position.X < platform.Position.X) { TurnAround(); } }