I didn’t do too much development, but this time, I’m aiming to add something noticeable with every update to keep myself motivated and keep at it, instead of abandoning the project like I did with every one of my previous ones.
I used Gimp to create a new set of sprites for the basic tank. This one looks slightly better than the last one, but isn’t anything amazing. In the end, I’m not artist. While I was at it, I also added a basic cannon/turret graphic and a weapon class. Each tank will have a weapon which is drawn right on top of the base. The weapon can rotate independently from the tank and for now, rotates based on where you click.
The idea is for the weapon class to become a base or even an abstract class from which all other weapons will inherit.
It took me a while to figure out the rotation math, mostly because I was confused with the camera. For some reason, I decided to position the (0,0) coordinate of the LibGDX orthographic camera in the center of the screen, but this just ended up giving me trouble. Because of that, I put it in the bottom left, which makes much more sense to me. I did it the following way:
camera = new OrthographicCamera(Gdx.graphics.getWidth(), Gdx.graphics.getHeight()); camera.setToOrtho(false, Gdx.graphics.getWidth(), Gdx.graphics.getHeight());
The false parameter indicates that the y-axis starts at the bottom. Setting this to true makes it start at the top, which might be more familiar to some people.
A slight issue here is that the y touch coordinate in Gdx.input.getY() starts from the top, but the fix here is simple. You simply subtract it from the camera height to make it go from the bottom.
Vector2 touchPos = new Vector2(Gdx.input.getX(), camera.viewportHeight - Gdx.input.getY());
I decided to calculate rotation not from the exact touch coordinate, but from the center of the tile nearest to the touch coordinate. This way, it’s more of a discreet feel and in the future, when I’m actually targeting enemies centered on that tile, it will look better.
I’ve noticed everything seems a bit too small, though, so I’ll see about increasing the size of everything. Maybe an 8×8 or a 6×6 grid would work a bit better. Ideally, I would have zoom functionality, but that’s a bit beyond me at this point.
Here’s the latest video:
In any case, the game is progressing and I’m still at it. I think my next goal will be to add a basic bullet factory/manager class and add shooting functionality. Either that, or I’ll work on increasing graphics size and maybe try to make the code a bit better. That’s putting me in danger of getting ahead of myself, though.