I'm currently developing a simple game with Java. It's a top down shooter prototype where your only objective is to kill everyone who appears on the screen. Nothing fancy or over complicated, just a simplistic game to sharpen my skills before I move on to C++.
However, I'm facing a lot of trouble in two areas:
1. Rotating sprites
2. Figuring out the player facing direction in relation to the mouse position
The first problem is somewhat simple. I can actually rotate the image using the code snippet below, but it will get really ugly if I rotate it long enough.
public void rotate(int angle) { BufferedImage biRotate = new BufferedImage(getHeight(), getWidth(), BufferedImage.TYPE_INT_RGB); Graphics2D g = biRotate.createGraphics(); g.rotate(Math.toRadians((double)angle), getWidth()/2, getHeight()/2); g.drawImage(anim.getImage(), 0, 0, null); g.dispose(); anim.setImage(biRotate); }
I did some research to see how the Slick engine would engage this matter, but they use LWJGL and not pure Java as I am using right now. I also tried the similar (equal?) method of using AffineTransform and the results were pretty much the same. So, anyone would recommend another approach?
Also, I thought about creating a spritesheet (tilemap) with some of the rotated sprites in it. This seems unnecessary and would result in LOTS of sprites for every character of the game, spaceship or any other creature I might add later. However, I'm new to Game Development in general and would like to hear your opinions.
Another option would be pre-computing all the images for every rotation angle and storing it somewhere. This, again, could be an over complicated approach as I would have to control many images.
Thanks,
Felipe Kurkowski
PS.: I'm not a native speaker so I apologize in advance for any grotesque mistake. Please, don't forget to point them out so I can keep on learning the language.