[Home]ChaoticDroid

Robo Home | Changes | Preferences | AllPages

My ImplementsDroidCompetition Entry
Runs in a circle, ramming any that dare touch it!
package matt;
import robocode.*;
import matt.Utils;
import java.awt.Color;
import java.awt.geom.Point2D;

public class ChaoticDroid extends AdvancedRobot implements Droid
{
	boolean hit=false;
	public void run() {
		setAdjustGunForRobotTurn(true);
		setColors(Color.black,Color.black,Color.black);
		while (true) {
			if(!hit){
				setAhead(200);
				setTurnRight(200);
			}
			if(getGunHeat()==0 && getTurnRemaining()==0 && getDistanceRemaining()==0){
				hit=false;
			}
			execute();
		}
	}
	
	public void onHitRobot(HitRobotEvent e) {
		turnGunRight(Utils.normalizeBearing(getHeading() - getGunHeading() + e.getBearing()));
		fire(3);
	}
	
	public void onBulletHit(BulletHitEvent e) {
		hit=true;
		Bullet bullet = e.getBullet();
		turnGunRight(Utils.normalizeBearing(Utils.absoluteBearing(getX(), getY(), bullet.getX(), bullet.getY())-getGunHeading()));
		while(getGunHeat()!=0){
			turnRight(1);
		}
		fire(3);
		setTurnGunRight(Utils.normalizeBearing(Utils.absoluteBearing(getX(), getY(), bullet.getX(), bullet.getY())-getGunHeading()));
		setTurnRight(Utils.normalizeBearing(Utils.absoluteBearing(getX(), getY(), bullet.getX(), bullet.getY())-getHeading()));
		setAhead(Point2D.distance(getX(), getY(), bullet.getX(), bullet.getY()));
		execute();
	}
	
	public void onHitByBullet(HitByBulletEvent e){
		hit=true;
		setInterruptible(false);
		setTurnRight(e.getBearing());
		setAhead(5000);
		execute();
	}
}

Robo Home | Changes | Preferences | AllPages
Edit text of this page | View other revisions
Last edited June 14, 2005 23:21 EST by UnderDark (diff)
Search: