The first think you will need is RobocodeGLV014.
Then do as follows:
1. Import the following libraries. import java.awt.geom.Point2D; import java.awt.geom.Line2D; import robocode.robocodeGL.system.GLRenderer; import robocode.robocodeGL.PointGL; import robocode.robocodeGL.LineGL; import java.awt.Color; 2. Declare the following variables. static int n,m; static Line2D[] ps = new Line2D[100000]; ---- What is the advantage of this over using awt shapes (such as Ellipse2D.Double, Rectangle2D.Double)? 3. On your scan event add the following code (targetBearing is the absolute bearing to the target). ps[n] = new Line2D.Double(getX(),getY(),getX()+eGetDistance*Math.sin(targetBearing),getY()+eGetDistance*Math.cos(targetBearing)); 4. Before firing, call the method calculateGunBearings(); (see below) 5. When firing (probably in your scan event) add (note that predBearing is the relative bearing to target for firing): PointGL pt4 = new PointGL(); pt4.setPosition(getTime(),50+50*predBearing); pt4.setSize(2); pt4.setColor(Color.green); GLRenderer.getInstance().addRenderElement(pt4); 6. At the end of your scan event, add: n++; 7. The method is as follows: public void calculateGunBearings() { for (int i=m+1; i<((int)n-1); i++) { Line2D gun = new Line2D.Double(ps[i].getP1(),ps[i].getP2()); int j = 0; while (j*11.0 < gun.getP1().distance(gun.getP2())-20.0 && i+j<n ) { j++; gun.setLine(gun.getP1(),ps[i+j].getP2()); } if (i+j < n) { double angle = bearings[m] = normalRelativeAngle(Math.atan2(gun.getX2()-gun.getX1(),gun.getY2()-gun.getY1()) - Math.atan2(ps[i].getX2()-gun.getX1(),ps[i].getY2()-gun.getY1())); double tolerance = Math.asin(50/ps[i].getP1().distance(ps[i].getP2())); PointGL pme = new PointGL(); pme.setPosition(getTime()-n+m,50+angle*50+tolerance*50); pme.setColor(Color.white); GLRenderer.getInstance().addRenderElement(pme); PointGL pme2 = new PointGL(); pme2.setPosition(getTime()-n+m,50+angle*50-tolerance*50); pme2.setColor(Color.white); GLRenderer.getInstance().addRenderElement(pme2); m++; } } }
-- Albert