Discussion:
How to paint a laser that shows the trajectory of the gun.
z***@gmail.com
2015-03-28 09:05:57 UTC
Permalink
I want to see a laser representation of the gun aiming.. Basically a line
that starts at the robot and ends at the point the gun is aiming at. Here
is my code:

public void onPaint(Graphics2D g){

int laserLength = 200;
double heading =getGunHeading();

g.setColor(Color.RED);
double x = Math.sin(Math.toRadians(heading)) * laserLength;
double y = Math.cos(Math.toRadians(heading)) *
laserLength;
g.drawLine((int)getX(),(int) getY(), (int)x,(int) y);

}

The laser starts at the robot but points to an irrelevant direction.
--
You received this message because you are subscribed to the Google Groups "robocode" group.
To unsubscribe from this group and stop receiving emails from it, send an email to robocode+***@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.
Johannes Slotta
2015-03-28 12:22:24 UTC
Permalink
Hi,

drawLine uses start and end points, perhaps you wanted something like

g.drawLine((int) getX(),(int) getY(), (int) (x+getX()),(int) (y+getY()));

HTH
Johannes
Post by z***@gmail.com
I want to see a laser representation of the gun aiming.. Basically a line
that starts at the robot and ends at the point the gun is aiming at. Here is
public void onPaint(Graphics2D g){
int laserLength = 200;
double heading =getGunHeading();
g.setColor(Color.RED);
double x = Math.sin(Math.toRadians(heading)) * laserLength;
double y = Math.cos(Math.toRadians(heading)) *
laserLength;
g.drawLine((int)getX(),(int) getY(), (int)x,(int) y);
}
The laser starts at the robot but points to an irrelevant direction.
--
You received this message because you are subscribed to the Google Groups "robocode" group.
To unsubscribe from this group and stop receiving emails from it, send an
For more options, visit https://groups.google.com/d/optout.
--
You received this message because you are subscribed to the Google Groups "robocode" group.
To unsubscribe from this group and stop receiving emails from it, send an email to robocode+***@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.
z***@gmail.com
2015-03-29 19:54:46 UTC
Permalink
Thanks that was the problem
Post by Johannes Slotta
Hi,
drawLine uses start and end points, perhaps you wanted something like
g.drawLine((int) getX(),(int) getY(), (int) (x+getX()),(int) (y+getY()));
HTH
Johannes
Post by z***@gmail.com
I want to see a laser representation of the gun aiming.. Basically a
line
Post by z***@gmail.com
that starts at the robot and ends at the point the gun is aiming at.
Here is
Post by z***@gmail.com
public void onPaint(Graphics2D g){
int laserLength = 200;
double heading =getGunHeading();
g.setColor(Color.RED);
double x = Math.sin(Math.toRadians(heading)) *
laserLength;
Post by z***@gmail.com
double y = Math.cos(Math.toRadians(heading)) *
laserLength;
g.drawLine((int)getX(),(int) getY(), (int)x,(int) y);
}
The laser starts at the robot but points to an irrelevant direction.
--
You received this message because you are subscribed to the Google
Groups
Post by z***@gmail.com
"robocode" group.
To unsubscribe from this group and stop receiving emails from it, send
an
Post by z***@gmail.com
For more options, visit https://groups.google.com/d/optout.
--
You received this message because you are subscribed to the Google Groups "robocode" group.
To unsubscribe from this group and stop receiving emails from it, send an email to robocode+***@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.
Loading...