Monday, February 15, 2010

Moving Aliens around the screen

I have had my aliens being spawned now for a while. In fact I rewrote it recently (2 weeks ago?). I wanted to make it simpler and more appropriate for this normal shooter. I did not need such an incredible spawning algorythm for this game. I need a robust system that has relatively few parameters in it.

So aliens are spawning, and it is time to take control of their movement. For now i was just planting them on the screen then checking their type to  do some elementary velocity movement. Some still retained code from Pellmell and so would follow you around a bit etc. Now it is time to get serious. This is after all a bit of a Homage to classc shooters of old, and they had nice waves of aliens following along after each other along predetermined paths. That is what i wanted.

So i have created Alien Orders (AO). This little system is TIGHT. i love it when ya write a routine and it is not massive, but does so much great stuff. With it being tight like this, it will be so easy to add more functionality to is as it needs it.

Here is my basic data layout with the header listed and the instrcutions i currently have them able to understand.


// Alien Orders (AO)
// Followed by an optional command
// Move - Angle, Speed, Time
// Pause - Time,
// Shoot,
// Repeat,

const float AO_MOVE = 371.0f;
const float AO_PAUSE = 372.0f;
const float AO_SHOOT = 373.0f;
const float AO_REPEAT = 374.0f;

static float[] AO_StepUp = {AO_MOVE,270.0f,2.5f,0.5f, AO_PAUSE,0.25f, AO_SHOOT, AO_MOVE,180.0f,2.0f,0.5f, AO_PAUSE,0.25f, AO_REPEAT};
Above I describe the instuctions i can Order an alien to carry out. Then i have some Defines to make stuff easier to read. Finally you see an example AO data set. This one moves an alien left nad then up and then repeasts, while ordering a shot between each change of direction.
The few variables it takes is also nice of course. And finally the routine itself is an example of simplicity. And is below.  Ok ok, so it isn't. I haven't found a good way to enter code into this blog, BAH! If anyone has any ideas or examples of how to do that, then please let me know :S
I also did a data stream for a few other interesting movements. One is a wave that makes the Aliens snake towards you. Pretty cool. Also if you combine this type of system with other controls, you can end up with a mighty powerful looking alien control.
take for example if you have AO making your alien move in a square (box) move. Then supplement that with a homing routine. You would have a box moving alien coming towards you. Pretty neato.
In conclusion, there is No reason to over think Alien control routines. I have seen some programmers sink because of their overly complex Alien control routines.

No comments:

Post a Comment