Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /**
- * onScannedRobot: Here's the good stuff
- */
- public void onScannedRobot(ScannedRobotEvent e) {
- // If we have a target, and this isn't it, return immediately
- // so we can get more ScannedRobotEvents.
- if (trackName != null && !e.getName().equals(trackName)) {
- return;
- }
- // If we don't have a target, well, now we do!
- if (trackName == null) {
- trackName = e.getName();
- out.println("Tracking " + trackName);
- }
- // This is our target. Reset count (see the run method)
- count = 0;
- // If our target is too far away, turn and move toward it.
- if (e.getDistance() > 150) {
- gunTurnAmt = normalRelativeAngleDegrees(e.getBearing() + (getHeading() - getRadarHeading()));
- turnGunRight(gunTurnAmt); // Try changing these to setTurnGunRight,
- turnRight(e.getBearing()); // and see how much Tracker improves...
- // (you'll have to make Tracker an AdvancedRobot)
- ahead(e.getDistance() - 140);
- return;
- }
- // Our target is close.
- gunTurnAmt = normalRelativeAngleDegrees(e.getBearing() + (getHeading() - getRadarHeading()));
- turnGunRight(gunTurnAmt);
- fire(3);
- // Our target is too close! Back up.
- if (e.getDistance() < 100) {
- if (e.getBearing() > -90 && e.getBearing() <= 90) {
- back(40);
- } else {
- ahead(40);
- }
- }
- scan();
- }
Add Comment
Please, Sign In to add comment