Difference between revisions of "Module/Radar/MouseRadar"

From Robowiki
< Module‎ | Radar
Jump to navigation Jump to search
(Module radar MouseRadar)
 
m (Using <syntaxhighlight>.)
 
Line 1: Line 1:
<pre>
+
<syntaxhighlight>
 
package jab.radar;
 
package jab.radar;
  
Line 34: Line 34:
 
}
 
}
 
}
 
}
</pre>
+
</syntaxhighlight>

Latest revision as of 09:29, 1 July 2010

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();
		}
	}
}