Module/Radar/MouseRadar

From Robowiki
< Module‎ | Radar
Revision as of 00:01, 24 March 2008 by Jab (talk | contribs) (Module radar MouseRadar)
(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)
Jump to navigation Jump to search
package jab.radar;

import java.awt.event.InputEvent;
import java.awt.event.MouseEvent;

import robocode.util.Utils;

import jab.Module;
import jab.Radar;

/**
 * Credits
 * Interactive - a sample robot by Flemming N. Larsen.
 */
public class MouseRadar extends Radar {
	
	public MouseRadar(Module bot) {
		super(bot);
	}

	int aimX, aimY;
	
	public void scan(){
		double angle = Utils.normalAbsoluteAngle(Math.atan2(aimX - bot.getX(), aimY - bot.getY()));
		bot.setTurnRadarRightRadians(Utils.normalRelativeAngle(angle - bot.getRadarHeadingRadians()));
	}

	public void listenInput(InputEvent e){
		if (e instanceof MouseEvent){
			aimX = ((MouseEvent)e).getX();
			aimY = ((MouseEvent)e).getY();
		}
	}
}