I got a lot done today in my work to update Orbital Defense.
My goal was to get player units working today. For the basic functionality I really only need one unit in place so I just updated the basic attack unit.
First up I added in the graphics for it. In the original I wanted the satellites to rotate or at least have some bit of animation. With LibGDX it’s pretty simple to handle animation so I now have them rotating, which is nice.
One thing I had to fix in the conversion was the placement of satellites. The coordinate system is different between the standard android canvas and LibGDX. Basically the Y axis is reversed in Canvas 0 is at the top, in LibGDX 0 is at the bottom. I knew this was something to keep an eye out for so as soon as I tested it and saw the results I knew the change I had to make.
Now that I had satellites placed on the screen I need to get them to move. Moving something smoothly around a circle takes a bit more code then one might imagine but luckily all the code I had written still worked perfectly. I needed to make some adjustments based on changes I’ve made to where variables and methods are coming from, but nothing about the calculations needed to change which is always handy.
Since satellites could orbit I figured they should next be able to attack. Since I have meteors already in place, we have targets for the satellites. This was code that once I took a look at it I was able to reduce it down to far fewer lines. The general logic is still the same, i just get where I need to be a lot quicker and removed some of the redundant branches. Basically it checks to see if it still has a valid target, and if not finds one. Once a target is found it fires on it if the satellite is ready to fire. My original code for this logic took up about 50 lines, my new code for it takes up 20 and performs the same job in a more efficient way.
Part of attacking is that you want to see it on the screen, so I had to work out some better code for that. Previously I only had the attacks on screen for a frame or two, but with faster running frames this doesn’t really work so it’s all time based now. It is still only on the screen for 0.15 seconds but it is enough that you see it happening. I will probably adjust that number further as I work on things more.
Once I had code for satellites attacking in place I could just copy the same code for enemy attacks. Even though I don’t have any enemies that shoot in place yet, the logic stays essentially the same.
I do have meteors though, and the way that those attack is by hitting things, so I needed to put collision detection in place. One thing that is nice for simple collision detection in this game is that everything is more or less bounded by a circle. What makes that simple is that all you need to do to check for a collision is find out the distance between the center of the two objects and see if it is smaller than the radius of the two objects added together. Everything in the game has an impact damage assigned to it so I just subtract from the health of both objects. Of course I couldn’t leave things that simple though and I currently have two special types of satellites that don’t obey the same collision rules. The easy one is the Bulldozer satellite, specifically designed to take out meteors and other objects. It takes no damage from impact. The more difficult one is the Bouncer satellite. Bouncer satellites deflect meteors and neither takes damage. Handling these requires figuring out tangents and reflecting angles and all that jazz, which I had figured out previously and have code for. Right now I’m hoping my old code will work fine, as soon as Bouncers are added back in I specifically need to test them.
After all this added code I can then just simply check the health of all allied and enemy units and destroy the ones below 0, with a little quick explosion that I think I want to expand later on.
Basic game play is more or less in place with all these additions. What I really need to do next is add information to the screen. You currently do not know planet health or current resources, vitally important data to actually know how the game is going and what actions you can take in the game. I think I will work on those tomorrow as well as start working on the main menu screen and other non-game screens, which will all be new with the change to LibGDX.
In completely unrelated news, my Flynt Flossy shirt came in yesterday which is awesome. Here is Turquoise Jeep’s latest video: