First of all, what is AI? AI stands for artificial inteligence. The means by which (in this case) an object in your game would act to a certain cuase. For example your character is 170 pixels away from the enemy. When your character is further than 170 pixels away from the enemy, the enemy will be in a guard animation (walking back and forth.) When your character is 170 pixels or closer, the enemy will change its animation and attack you.

That is a simple example of AI. You see, AI much to often taken for granted. There are many great games out there but a number of them don't have AI. That can often be the one thing that an awsome game is missing. The one secret to GOOD AI is to have your objects act like a real people would in that situation. Now, I'll show you some examples of AI that you could use in you game.
___________________________________________________________
Speed

#1. If your character's speed is higher than say, 50, have the enemy/enemies turn around and attack. If lower than 50, then have them stay there until you ______ close. If you're slower than oh, 20 while you're ______ close, don't have your enemy do anything. If you're faster than 20 when you're ______ close, have your enemy turn around and attack.
___________________________________________________________
Direction

#2. If your character is facing an enemy that is facing away, don't have the enemy attack- and if the enemy is facing your way (looking at you) have it attack (this is one reason to have your enemies turn around in many different directions in your game.)
___________________________________________________________
Distance

#3. We've already covered distance in the first example at the very top, but remember this- you don't want your enemies to attack your character if he's on the total opposite side of the screen (unless the screen is VERY small.) That means you need to wait until they're at least at a somewhat reasonable spot to be seen.
___________________________________________________________
Hiding Spots

#4. Make hiding spots in your games for goodness sake!(Oh, that is if you're going to be shooting or are running away from things.) Hiding spots can range from a silly old plant to a stone pillar- just make sure you have some. To make the hiding spot work, have a condition that says if your character is ______ away from (I'll use a piller for example) piller and the number of 'characters' in a zone (set a zone to the left or right of the pillar) is =to 1, set enemies animation to Stopped (or you could use Walk.)
___________________________________________________________
Attacking

#5. Now, let's face it. If you're attacking an enemy and it's not attacking you back, fighting that enemy just isn't fun- even though it's easy. My point is to not let that happen. It's really simple. When you're attacking an enemy have it attack you. If you have a long range weapon and the enemy has a short range weapon, have the enemy run/chase after you. It's that simple!