Difference between revisions of "Talk:Linear Targeting/Buggy Implementations"
Jump to navigation
Jump to search
(snippets need some reformatting) |
|||
Line 1: | Line 1: | ||
These code snippets should be modified to not have super long lines. Also, there's no reason for the last one to be indented across the whole snippet. --[[User:Voidious|Voidious]] 19:43, 14 November 2007 (UTC) | These code snippets should be modified to not have super long lines. Also, there's no reason for the last one to be indented across the whole snippet. --[[User:Voidious|Voidious]] 19:43, 14 November 2007 (UTC) | ||
+ | |||
+ | <pre> | ||
+ | double absBearing=e.getBearingRadians()+getHeadingRadians(); | ||
+ | |||
+ | double eX=getX() + e.getDistance() * Math.sin(absBearing); | ||
+ | |||
+ | double eY=getY() + e.getDistance() * Math.cos(absBearing); | ||
+ | |||
+ | eXChange=(eX-oldX)*(e.getDistance()/11); | ||
+ | |||
+ | eYChange=(eY-oldY)*(e.getDistance()/11); | ||
+ | |||
+ | oldX=getX() + e.getDistance() * Math.sin(absBearing); | ||
+ | |||
+ | oldY=getY() + e.getDistance() * Math.cos(absBearing); | ||
+ | |||
+ | double enemyLocation=robocode.util.Utils.normalAbsoluteAngle(Math.atan2((eX-getX())+eXChange,(eY-getY())+eYChange)); | ||
+ | |||
+ | setTurnGunRightRadians(robocode.util.Utils.normalRelativeAngle(enemyLocation-getGunHeadingRadians())); | ||
+ | |||
+ | setFire(3); | ||
+ | </pre> | ||
+ | |||
+ | |||
+ | I'm trying to make a gun that makes use of code similar to this, but for some reason this doesn't work exactly right... Does anyone know if this is a math problem or a programming problem?--[[User:CrazyBassoonist|CrazyBassoonist]] 22:43, 9 April 2009 (UTC) |
Revision as of 23:43, 9 April 2009
These code snippets should be modified to not have super long lines. Also, there's no reason for the last one to be indented across the whole snippet. --Voidious 19:43, 14 November 2007 (UTC)
double absBearing=e.getBearingRadians()+getHeadingRadians(); double eX=getX() + e.getDistance() * Math.sin(absBearing); double eY=getY() + e.getDistance() * Math.cos(absBearing); eXChange=(eX-oldX)*(e.getDistance()/11); eYChange=(eY-oldY)*(e.getDistance()/11); oldX=getX() + e.getDistance() * Math.sin(absBearing); oldY=getY() + e.getDistance() * Math.cos(absBearing); double enemyLocation=robocode.util.Utils.normalAbsoluteAngle(Math.atan2((eX-getX())+eXChange,(eY-getY())+eYChange)); setTurnGunRightRadians(robocode.util.Utils.normalRelativeAngle(enemyLocation-getGunHeadingRadians())); setFire(3);
I'm trying to make a gun that makes use of code similar to this, but for some reason this doesn't work exactly right... Does anyone know if this is a math problem or a programming problem?--CrazyBassoonist 22:43, 9 April 2009 (UTC)