I am creating a simulation of a crowd using Java Swing and Java Graphics2D. I have a certain number of pedestrians that must reach some waypoints and I am having troubles with their motion. The movement of each pedestrian now is very simple, it is something like this:
if (goalPosition.x > pedestrian.position.x) {
pedestrian.position.x++;
}
else
pedestrian.position.x--;
if (goalPosition.y > pedestrian.position.y) {
pedestrian.position.y++;
}
else
pedestrian.position.y--;
I just increase/decrease by 1 the position of each pedestrian according to the position of the goal to reach. The problem is that i need to make them walk towards the goal in a straight line, I tried to compute angles and use trigonometry, but the problem with that approach is that I can't update the position of a pedestrian using a double value, because later each pedestrian is drawn using:
g2D.fillOval(pedestrian.position.x, pedestrian.position.y, ENTITY_SIZE, ENTITY_SIZE);
That accepts only integer positions. Any idea of how I can update my code? Thanks