Can anyone explain me this code? i don't understand condition in the loop while and "predicted X". why predicted_X < 18
? what does 18 mean?
while((++deltaTime)*BULLET_SPEED <
Point2D.Double.distance(myX, myY, predictedX, predictedY)) {
predictedX += Math.sin(enemyHeading) * e.getVelocity();
predictedY += Math.cos(enemyHeading) * e.getVelocity();
enemyHeading += enemyHeadingChange;
if(predictedX < 18.0
|| predictedY < 18.0
|| predictedX > getBattleFieldWidth() - 18.0
|| predictedY > getBattleFieldHeight() - 18.0) {
predictedX = Math.min(Math.max(18.0, predictedX),
getBattleFieldWidth() - 18.0);
predictedY = Math.min(Math.max(18.0, predictedY),
getBattleFieldHeight() - 18.0);
break;
}
}
The robot´s width is 36px so 18.0 is half of it. The condition just makes sure that your predictedX/Y isn´t outside of the battlefield