This example was put together for those making aircraft games. I kind of decided to use the basic AI concept used in StarFox64. I found this kind of fun, and people are asking on how to do AI, so I decided to do an example on it.
This is a pretty simple way of making enemy AI when using a top-down shooter, or an aircraft game. This example is specifically made for using aircraft, but with a bit of changing, can be used for many top-down shooters. So, here's how it works.
The enemy is capable of dodging attacks and asteroids which are placed around. He can get behind you and shoot at you, and leave when he senses danger. He'll slow down when you are too close so he can stay behind you.
Also included, is a very, VERY simple way to do a radar. It can draw the character and enemy on it, and you'll want it. Basically, you base a rectangular radar on the room dimensions. It does not draw directions very well, nor does it draw the asteroids.
So, the controls are as follows:
Left/Right Arrow Keys: move your ship left/right
Up/Down Arrow Keys: speed up/slow down
Spacebar: shoot
Control: barrel roll (used to deflect projectiles)
Z: Loop (used to escape pursuit)
They're pretty simple, and the enemy is capable of most of those. Now, if you are having too much trouble, I threw in some bullet types.
1: normal bullet (you're good if you can win with this)
2: twin bullet (this is if your accuracy is off)
3: big bullet (you have to be a loser to need this, but it can help you finish quickly)
4: homing bullet (you suck to use this)
5: homing big bullet (you are a real loser to need this)
So, it's kind of a minigame within itself. These are the number keys, and may only work when they aren't on the number pad. The ones above the letters. =P
As a final word, do NOT simply put in more enemies. The seperate object for the enemy's health will not draw over all enemies. If you want to make multiple enemies, duplicate both the enemy object and the controller for each extra enemy you make. The reason this is done is because I used image_angle.
One more thing, do NOT rate on whether or not bullet types work, because they were thrown in in case you're having problems.
Remember that this uses GML, but a little D&D. The D&D was mostly used because GM was coming up with dumb ways to do things. Also, using random chances just is easier in D&D. There isn't much, but if you have suggestions for that, they're pretty welcome.
So, all graphics were done by me, I believe, except for the starry background. The programming was mine, and I decided to throw in some music just for fun from SF64.
Enjoy the example! I will not require credit, but it is appreciated. DO NOT simply copy everything and put it in your game. It's usually best to change things up to fit your game.