Discussion:
New to RoboCode & Java
zapetersen
2010-09-03 14:54:37 UTC
Permalink
Hi,
I a new to Java and RoboCode. I Figured RoboCode like it says would be a fun way to learn the language etc.

Just for fun I wanted to create a robot that drove to the center of the map, and then start to shoot at people from there. Just like the Corners Bot but just a alteration to it. Here is the basics of my code.

********************************************************
********************************************************
yValue = getBattleFieldHeight()/2 - getY();
xValue = getBattleFieldWidth()/2 - getX();
hypotValue = Math.sqrt((xValue*xValue)+(yValue*yValue));

changeAngle = Math.asin(yValue/hypotValue)*180/Math.PI;

turnLeft(changeAngle);
ahead(hypotValue);
********************************************************
********************************************************

now the problem that I am having is turning the robot to the correct angle. I cant figure out how to use the getHeading() inconjuction with my changeAngle to get the robot to turn to the center of the map.

I have tried this
changeAngle(getHeading()+changeAngle);

but that didnt seem to help at all. After I figure all that out I am going to put in a control statement something along the lines of this

********************************************************
********************************************************
If getX()>getBattleFieldWidth() -10 && getX() <getBattleFieldWidth()+10 && getY()>getBattleFieldHeight()-10 && getY()<getBattleFieldHeight() +10 {
scan and shoot at people.
}
Else {
Drive to the center
}
********************************************************
********************************************************

None of the above code is complete or anything it is just what was off the top of my head. Thanks for the help and I am looking forward to doing battle with other bots and learning a lot about java at the same time. Thanks.

--Zac



------------------------------------

Yahoo! Groups Links

<*> To visit your group on the web, go to:
http://groups.yahoo.com/group/Robocode/

<*> Your email settings:
Individual Email | Traditional

<*> To change settings online go to:
http://groups.yahoo.com/group/Robocode/join
(Yahoo! ID required)

<*> To change settings via email:
Robocode-***@yahoogroups.com
Robocode-***@yahoogroups.com

<*> To unsubscribe from this group, send an email to:
Robocode-***@yahoogroups.com

<*> Your use of Yahoo! Groups is subject to:
http://docs.yahoo.com/info/terms/

Loading...