@Test public void testDirectToWallDistanceDiagonalToEastWall() { BattleField battleField = newBattleField(800, 600); double wallDistance = battleField.directToWallDistance( newLocation(622, 300), 280, Math.PI * 0.4, 2.0); assertTrue(wallDistance > 1.0 && wallDistance < 2.0); }
public double directToWallDistance(Point2D.Double targetLocation, double distance, double heading, double bulletPower) { int bulletTicks = DiaUtils.bulletTicksFromPower(distance, bulletPower); double wallDistance = 2.0; double sinHeading = Math.sin(heading); double cosHeading = Math.cos(heading); for (int x = 0; x < 2 * bulletTicks; x++) { if (!rectangle.contains( targetLocation.x + (sinHeading * 8.0 * x), targetLocation.y + (cosHeading * 8.0 * x))) { wallDistance = ((double) x)/bulletTicks; break; } } return wallDistance; }
BattleField { public double directToWallDistance(Point2D.Double targetLocation, double distance, double heading, double bulletPower) { int bulletTicks = DiaUtils.bulletTicksFromPower(distance, bulletPower); double wallDistance = 2.0; double sinHeading = Math.sin(heading); double cosHeading = Math.cos(heading); for (int x = 0; x < 2 * bulletTicks; x++) { if (!rectangle.contains( targetLocation.x + (sinHeading * 8.0 * x), targetLocation.y + (cosHeading * 8.0 * x))) { wallDistance = ((double) x)/bulletTicks; break; } } return wallDistance; } }
BattleField { public double directToWallDistance(Point2D.Double targetLocation, double distance, double heading, double bulletPower) { int bulletTicks = DiaUtils.bulletTicksFromPower(distance, bulletPower); double wallDistance = 2.0; double sinHeading = Math.sin(heading); double cosHeading = Math.cos(heading); for (int x = 0; x < 2 * bulletTicks; x++) { if (!rectangle.contains( targetLocation.x + (sinHeading * 8.0 * x), targetLocation.y + (cosHeading * 8.0 * x))) { wallDistance = ((double) x)/bulletTicks; break; } } return wallDistance; } BattleField(double width, double height); }
BattleField { public double directToWallDistance(Point2D.Double targetLocation, double distance, double heading, double bulletPower) { int bulletTicks = DiaUtils.bulletTicksFromPower(distance, bulletPower); double wallDistance = 2.0; double sinHeading = Math.sin(heading); double cosHeading = Math.cos(heading); for (int x = 0; x < 2 * bulletTicks; x++) { if (!rectangle.contains( targetLocation.x + (sinHeading * 8.0 * x), targetLocation.y + (cosHeading * 8.0 * x))) { wallDistance = ((double) x)/bulletTicks; break; } } return wallDistance; } BattleField(double width, double height); Point2D.Double translateToField(Point2D.Double p); double orbitalWallDistance(Point2D.Double sourceLocation,
      Point2D.Double targetLocation, double bulletPower, int direction); double directToWallDistance(Point2D.Double targetLocation,
      double distance, double heading, double bulletPower); double wallSmoothing(Point2D.Double startLocation, double startAngle,
      int orientation, double wallStick); }
BattleField { public double directToWallDistance(Point2D.Double targetLocation, double distance, double heading, double bulletPower) { int bulletTicks = DiaUtils.bulletTicksFromPower(distance, bulletPower); double wallDistance = 2.0; double sinHeading = Math.sin(heading); double cosHeading = Math.cos(heading); for (int x = 0; x < 2 * bulletTicks; x++) { if (!rectangle.contains( targetLocation.x + (sinHeading * 8.0 * x), targetLocation.y + (cosHeading * 8.0 * x))) { wallDistance = ((double) x)/bulletTicks; break; } } return wallDistance; } BattleField(double width, double height); Point2D.Double translateToField(Point2D.Double p); double orbitalWallDistance(Point2D.Double sourceLocation,
      Point2D.Double targetLocation, double bulletPower, int direction); double directToWallDistance(Point2D.Double targetLocation,
      double distance, double heading, double bulletPower); double wallSmoothing(Point2D.Double startLocation, double startAngle,
      int orientation, double wallStick); final Rectangle2D.Double rectangle; final double width; final double height; }