Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package nielegalnaplantacja;
- import java.awt.Color;
- import robocode.Droid;
- import robocode.HitByBulletEvent;
- import robocode.HitRobotEvent;
- import robocode.HitWallEvent;
- import robocode.MessageEvent;
- import robocode.StatusEvent;
- import robocode.TeamRobot;
- import robocode.TurnCompleteCondition;
- import sampleteam.Point;
- import static robocode.util.Utils.normalRelativeAngleDegrees;
- public class WladyslawDaliga extends TeamRobot implements Droid {
- boolean movingForward;
- boolean received = true;
- public void run() {
- out.println("Wladyslaw ready.");
- setBodyColor(Color.yellow);
- setGunColor(Color.yellow);
- setScanColor(Color.yellow);
- setBulletColor(Color.white);
- while (true) {
- setAhead(40000);
- movingForward = true;
- setTurnRight(90);
- waitFor(new TurnCompleteCondition(this));
- setTurnLeft(180);
- waitFor(new TurnCompleteCondition(this));
- setTurnRight(180);
- waitFor(new TurnCompleteCondition(this));
- execute();
- }
- }
- @Override
- public void onMessageReceived(MessageEvent e) {
- // Fire at a point
- if (e.getMessage() instanceof Point) {
- Point p = (Point) e.getMessage();
- // Calculate x and y to target
- double dx = p.getX() - this.getX();
- double dy = p.getY() - this.getY();
- // Calculate angle to target
- double theta = Math.toDegrees(Math.atan2(dx, dy));
- // Turn gun to target
- turnGunRight(normalRelativeAngleDegrees(theta - getGunHeading()));
- // Fire hard!
- fire(3);
- }
- }
- // public void onHitByBullet(HitByBulletEvent e) {
- // turnLeft(90 - e.getBearing());
- // }
- //
- public void onHitWall(HitWallEvent e) {
- // Bounce off!
- reverseDirection();
- }
- public void reverseDirection() {
- if (movingForward) {
- setBack(40000);
- movingForward = false;
- } else {
- setAhead(40000);
- movingForward = true;
- }
- }
- public void onHitRobot(HitRobotEvent e) {
- // If we're moving the other robot, reverse!
- if (e.isMyFault()) {
- reverseDirection();
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement