/* * This simple method moves the gun to the bearing that we predict the * enemy will be by the time our bullet will get there. * the 'absbearing' method can be found in the helper functions section * the nextX and nextY method can be found in the 'Enemy' class description */ void doGun() { //works out how long it would take a bullet to travel to where the enemy is *now* //this is the best estimation we have, without using a complicated iteration long time = getTime() + (int)(target.distance/(20-(3*firePower))); //offsets the gun by the angle to the next shot based on linear targeting provided by the enemy class double gunOffset = getGunHeadingRadians() - absbearing(getX(),getY(),target.guessX(time),target.guessY(time)); setTurnGunLeftRadians(NormaliseBearing(gunOffset)); }