Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package JCJH;
- import robocode.Robot;
- import robocode.ScannedRobotEvent;
- /**
- * Record the advanced state of an enemy bot.
- *
- * @author Justin Chang
- * @version 5/11/17
- *
- * @author Period - 5
- * @author Assignment - AdvancedEnemyBot
- *
- * @author Sources - none
- */
- public class AdvancedEnemyBot extends EnemyBot
- {
- private double x;
- private double y;
- /**
- *
- * Get's x.
- *
- * @return x value
- */
- public double getX()
- {
- return x;
- }
- /**
- *
- * Get's y.
- *
- * @return y value
- */
- public double getY()
- {
- return y;
- }
- /**
- * Resets values.
- */
- public void reset()
- {
- super.reset();
- x = 0.0;
- y = 0.0;
- }
- /**
- * Resets values.
- */
- public AdvancedEnemyBot()
- {
- reset();
- }
- /**
- *
- * Updates values.
- *
- * @param e
- * Scanned attributes
- * @param robot
- * The robot.
- */
- public void update( ScannedRobotEvent e, Robot robot )
- {
- super.update( e );
- double absBearingDeg = ( robot.getHeading() + e.getBearing() );
- if ( absBearingDeg < 0 )
- {
- absBearingDeg += 360;
- }
- x = robot.getX()
- + Math.sin( Math.toRadians( absBearingDeg ) ) * e.getDistance();
- y = robot.getY()
- + Math.cos( Math.toRadians( absBearingDeg ) ) * e.getDistance();
- }
- /**
- *
- * Predicted x.
- *
- * @param when
- * Time
- * @return Predicted x
- */
- public double getFutureX( long when )
- {
- return x
- + Math.sin( Math.toRadians( getHeading() ) ) * getVelocity() * when;
- }
- /**
- *
- * Predicted y.
- *
- * @param when
- * Time
- * @return Predicted y
- */
- public double getFutureY( long when )
- {
- return y
- + Math.cos( Math.toRadians( getHeading() ) ) * getVelocity() * when;
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement