Think it out logically. Begin with small steps. When tackling a complex problem, always begin with the simplest thing first, then once that's done build on top of it with the next step. There are no quick answers to things like this.
1. First, create a sprite.
2. Now you want to make it move. There are several ways you could do this. You could give it Bullet movement, or you could manually update it's x, y coordinates. Have it move in a straight line, and then when it hits a wall, make it turn around and go the other way.
3. Now that it moves back and forth, you want to have it stop at the edge of a ledge. The best way to do this is to make an invisible barrier that it can bounce off of. When it overlaps the barrier, it turns around.
4. Maybe you want to have gravity so it falls off a ledge. Make your sprite move down 1 or 2 pixels every cycle.
This can cause your sprite to get stuck in the ground. Make a loop that moves your sprite 1px up when it's overlapping the ground to push it out.
5. Now you want it to follow the player when it "sees" it. You could do this by making the sprite detect when the player is within a certain distance.
6. Now that it is aware that the player is within a certain distance, shoot an invisible object toward the player. If it hits the player, then the sprite "sees" the player. If it hits the background, the sprite does not see the player.
7. Now if the sprite sees the player, make the sprite turn and face towards the player (similar to making the sprite turn around when it hits a wall).
8. Making the sprite shoot the player is up to how you want the sprite to shoot. Do you want it to shoot at regular intervals? Do you want it to shoot a constant stream of bullets? Maybe you only want to shoot when the player is on the same vertical level as the sprite. Who knows? It's up to you.
There... those are the basics. This doesn't cover things like acceleration and such. Your gravity will be linear instead of "y pixels per second squared," but you can ask for help with more natural gravity once you have basic gravity done.
If you ask for help with one of the steps, I want to see a .cap showing that you have completed all the steps leading up to it or you'll get no response from me.