So now the fighters are all done. Yesterday they had the problem of shooting which I call, not altogether affectionately, the Bullet Hose. Basically the little dudes want to shoot every single cycle the game goes through, which means that their little guns shoot 60 times…per second. It looks like a laser almost. A stupid, broken laser. The problem that I had is similar to the one I had with the players, since they too needed a way to keep track of timing. The issue was that all of the things in the whole game really only have 1 spare variable that I built into them. Each type of thing uses it differently. So the dive bombers use it to keep track of how they fly, and the crashing enemies use it as a timer until they explode. The fighter planes use it to track which player they are chasing after.
Which meant that they couldn’t also use that variable for their timer.
Or so I thought. C languages like C, C++ and C# have an adorable little bit of math built into them. It looks like this : “%”. In this case it’s not a percent sign, but a funny way to divide. Like we remember from 2nd grade, most numbers don’t divide well, and usually they will have either fractions left over, or remainders. The “%” sign divides and tells you what the remainder is. So 104 % 10 = 4.
So for fighters, and probably the flying fortress enemies and ground turrets, they have a timer that’s built into the 10’s place for the misc field. It works really quite well. While I was there I use that same internal clock to make them a little less vicious by making them have a slight delay before they do much of anything. So now they aren’t the super hunters that they were before and are challenging without being unfair. I’ll call that a positive.
Since I was finishing off the fighters I also went ahead and added their dead crashing version. So I went in and made a Class for them and made a placeholder fireball for them. Then I realized that they don’t need their own class. Going back a little bit, I explained how I can summon up a constructor to make a class. Since making an instance (a new robot that follows the class code) has a whole lot of crap in it I found it was easier to just make a function that I fed the stuff I care about. So I could do this : MakeChicken(red)
It would then be a red Chicken that followed all of the code in the Chicken part of the code. Well, Crashing enemies aren’t really that complicated. They don’t move much and it’s not as if every type does something different. I mean, the design says that they burn differently, but that’s really just a simple number. So instead of having an entire class devoted to each possible type of crashing enemy, I could update my SpawnCrasher() function to make any kind I want. So now when I make one I tell it what kind of thing the enemy was, and it loads the correct animation and gives it the right number for how flammable it is. It’s pretty awesome really.
Finally, things now bump into the ground. I discovered that certain enemies (namely the dive bombers) are really stupid and will crash into anything, killing them instantly. So either a) I can add code to make them less stupid or b) I can just design levels around them. I think I’ll end up doing that. It is kind of cute to make fighters try to track me into things though. I know that I could make them smarter, but really, if I want to create tunnels in the levels, the ground based enemies are a smarter choice anyway. It’s what Gradius III did, so I’m okay with it.