Re: Not Painting When Firing

Vegeta <[email protected]> Thu, 22 Oct 2020 14:12:34 -0400
Newsgroups gmane.comp.java.robocode
Message-ID <CAOkf+2ZA5xrNQP5Y80Zcv01MruQS+OA9x4GZ+yy4+oqd_SWhNw@mail.gmail.com>
I have painting enabled as per the Wiki, but it doesn't paint anything the
turn the robot fires.

On Thu., Oct. 22, 2020, 13:58 fnl <[email protected]> wrote:

> This is my design.
> If every robot paint itself, it will be hard to see what is going on on
> the battlefield. Hence, the developer needs to enable painting for the
> individual robot in the robot console.
>
> This is described on this RoboWiki page:
> https://robowiki.net/wiki/Robocode/Graphical_Debugging
>
> torsdag den 22. oktober 2020 kl. 19.55.55 UTC+2 skrev [email protected]:
>
>> For some reason, the turn my robot fires, it doesn't seem to paint. Any
>> fixes for this? Code is below.
>>
>> import java.awt.BasicStroke;
>> import java.awt.Color;
>> import java.awt.Graphics2D;
>>
>> import robocode.AdvancedRobot;
>> import robocode.Bullet;
>> import robocode.HitByBulletEvent;
>> import robocode.HitWallEvent;
>> import robocode.ScannedRobotEvent;
>>
>> public class BasicRobot extends AdvancedRobot {
>> //Attributes
>> private int scanX, scanY;
>> private boolean found = false;
>> private ScannedRobotEvent latestScan = null;
>> /**
>> * run: BasicRobot's default behavior
>> */
>> public void run() {
>> // Initialization of the robot should be put here
>>
>> // After trying out your robot, try uncommenting the import at the top,
>> // and the next line:
>>
>> setColors(Color.BLACK, Color.GRAY, Color.RED); // body,gun,radar
>> setScanColor(Color.WHITE);
>>
>> // Robot main loop
>> while(true) {
>> // Replace the next 4 lines with any behavior you would like
>> if (!found) {
>> turnGunRight(5);
>> } else {
>> scan();
>> }
>> }
>> }
>> /**
>> * onScannedRobot: What to do when you see another robot
>> */
>> public void onScannedRobot(ScannedRobotEvent e) {
>> found = true;
>> latestScan = e;
>> // Replace the next line with any behavior you would like
>> if (getGunHeat() == 0)
>> fireBullet(3);
>> }
>> private void drawScannedRobot(ScannedRobotEvent e) {
>> double angle = Math.toRadians((getHeading() + e.getBearing()) % 360);
>> scanX = (int) (getX() + Math.sin(angle) * e.getDistance());
>> scanY = (int) (getY() + Math.cos(angle) * e.getDistance());
>> Graphics2D g = this.getGraphics();
>> g.setColor(new Color(0xff, 0x00, 0x00, 0x80));
>> g.drawLine((int) getX(), (int) getY(), scanX, scanY);
>> int w = (int) getWidth();
>> g.fillRect(scanX - w/2, scanY - w/2, 40, 40);
>> }
>> public void onPaint(Graphics2D g) {
>> g.setStroke(new BasicStroke(2));
>> g.setColor(Color.GRAY);
>> int r = (int) (getWidth() * 1.5);
>> if (latestScan != null)
>> drawScannedRobot(latestScan);
>> }
>> private void draw(Graphics2D g) {
>> g.setStroke(new BasicStroke(2));
>> g.setColor(Color.GRAY);
>> int r = (int) (getWidth() * 1.5);
>> if (latestScan != null)
>> drawScannedRobot(latestScan);
>> }
>> }
>>
> --
> You received this message because you are subscribed to a topic in the
> Google Groups "robocode" group.
> To unsubscribe from this topic, visit
> https://groups.google.com/d/topic/robocode/tJdttapWeqM/unsubscribe.
> To unsubscribe from this group and all its topics, send an email to
> [email protected].
> To view this discussion on the web visit
> https://groups.google.com/d/msgid/robocode/921c3b8c-8ba5-4f5c-acd0-517795911f9fn%40googlegroups.com
> <https://groups.google.com/d/msgid/robocode/921c3b8c-8ba5-4f5c-acd0-517795911f9fn%40googlegroups.com?utm_medium=email&utm_source=footer>
> .
>

-- 
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 [email protected].
To view this discussion on the web visit https://groups.google.com/d/msgid/robocode/CAOkf%2B2ZA5xrNQP5Y80Zcv01MruQS%2BOA9x4GZ%2Byy4%2Boqd_SWhNw%40mail.gmail.com.