Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package zicabots;
- import robocode.HitByBulletEvent;
- import robocode.HitRobotEvent;
- import robocode.HitWallEvent;
- import robocode.ScannedRobotEvent;
- import robocode.TeamRobot;
- import robocode.TurnCompleteCondition;
- import robocode.MessageEvent;
- import static robocode.util.Utils.normalRelativeAngleDegrees;
- public class droideira extends TeamRobot{
- boolean movingForward;
- boolean noLeader = false; //Inicialmente existe um líder
- static int MIN_ROBOT_DISTANCE = 100;
- static int MAX_ROBOT_DISTANCE = 150;
- public void run(){
- while (true){
- if(!noLeader){ //Se ainda tem líder
- }else{ //Se não, atue como um doido
- setAhead(40000);
- movingForward = true;
- setTurnRight(90);
- waitFor(new TurnCompleteCondition(this));
- setTurnLeft(180);
- waitFor(new TurnCompleteCondition(this));
- setTurnRight(180);
- waitFor(new TurnCompleteCondition(this));
- }
- }
- }
- 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));
- double distance = Math.sqrt(
- (this.getX() - p.getX()) * (this.getX() - p.getX()) +
- (this.getY() - p.getY()) * (this.getY() - p.getY())
- );
- System.out.println(distance);
- /*
- if(distance>MAX_ROBOT_DISTANCE){
- movingAside = false;
- aproximar(theta - getHeading());
- }else if(distance<=MAX_ROBOT_DISTANCE && distance>MIN_ROBOT_DISTANCE){
- movingAside = true;
- posicionar(theta - getHeading());
- }else{
- movingAside = false;
- recuar(theta - getHeading(), distance);
- }*/
- // Turn gun to target
- setTurnGunRight(normalRelativeAngleDegrees(theta - getGunHeading()));
- // Fire hard!
- fire(3);
- }
- }
- public void onHitRobot (HitRobotEvent e){
- if (!noLeader){
- }else{
- }
- if(e.isMyFault()){
- reverseDirection();
- }
- }
- public void onHitByBullet(HitByBulletEvent e){
- if (!noLeader){
- //Só pra debugar
- System.out.println("Obedecer líder");
- }else{
- }
- }
- public void onHitWall (HitWallEvent e){
- if (!noLeader){
- //Só pra debugar
- System.out.println("Obedecer líder");
- }else{
- reverseDirection();
- }
- }
- public void reverseDirection(){
- if (movingForward){
- setBack (40000);
- movingForward = false;
- }else{
- setAhead(40000);
- movingForward = true;
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement