All Downloads are FREE. Search and download functionalities are using the official Maven repository.

sampleteam.MyFirstDroid Maven / Gradle / Ivy

/*
 * Copyright (c) 2001-2023 Mathew A. Nelson and Robocode contributors
 * All rights reserved. This program and the accompanying materials
 * are made available under the terms of the Eclipse Public License v1.0
 * which accompanies this distribution, and is available at
 * https://robocode.sourceforge.io/license/epl-v10.html
 */
package sampleteam;


import robocode.Droid;
import robocode.MessageEvent;
import robocode.TeamRobot;
import static robocode.util.Utils.normalRelativeAngleDegrees;


/**
 * SimpleDroid - a sample robot by Mathew Nelson.
 * 

* Follows orders of team leader. * * @author Mathew A. Nelson (original) * @author Flemming N. Larsen (contributor) */ public class MyFirstDroid extends TeamRobot implements Droid { /** * run: Droid's default behavior */ public void run() { out.println("MyFirstDroid ready."); } /** * onMessageReceived: What to do when our leader sends a message */ public void onMessageReceived(MessageEvent e) { // Fire at a point if (e.getMessage() instanceof Point) { Point p = (Point) e.getMessage(); // Calculate x and y to target double dx = p.getX() - this.getX(); double dy = p.getY() - this.getY(); // Calculate angle to target double theta = Math.toDegrees(Math.atan2(dx, dy)); // Turn gun to target turnGunRight(normalRelativeAngleDegrees(theta - getGunHeading())); // Fire hard! fire(3); } // Set our colors else if (e.getMessage() instanceof RobotColors) { RobotColors c = (RobotColors) e.getMessage(); setBodyColor(c.bodyColor); setGunColor(c.gunColor); setRadarColor(c.radarColor); setScanColor(c.scanColor); setBulletColor(c.bulletColor); } } }





© 2015 - 2024 Weber Informatics LLC | Privacy Policy