I have a game that i am making, where a ship is in the centre of the screen and planets scroll around it. The ship can rotate about it’s centre, but can not change position.(the planets do that, for a scrolling effect) The problem is that I don’t know how to move the planets in a certain direction based on where the ship is pointing. my first approach was to increment the planet’s x and y coordinates based on where the ship was. example:
if(ships_rotation > 22.5 && ships rotation < 67.5){
planet.x-= ship.y*speed;
planet.y+= ship.y*speed;
}
However this is very time-consuming because I have to write similar code for every direction the planet moves, as well as having very choppy movement. So I decided to attach a AffineTransform to the planet, because as i have found out earlier, AffineTransform can rotate coordinates. This next block of code shows an example of moving the ship diagonally just by incrementing x.
aft.rotate(Math.toRadians(45));
aft.translate(50,0);
However, there is one thing wrong with this code, and it is that the image rotates WITH the coordinates. My new approach is to rotate the image opposite the way I want it to go WITHOUT coordinate change, then rotate it back normally.(So the coordinates change) How can I accomplish this? I am open to other solutions, but NOT installing libraries. Thanks in advance.