To FinnSo, your algorithm is:
For avoiding objects just do something like:
Save the direction the sprite is moving,
Check if the enemy is colliding with any object.
(for example the sprite is colliding with an object and moved right-->)
Check if the player is higher or lower then the enemy. If the player is above move up, then right. If colliding move up again and then right. As long as you're not colliding anymore. Then you can go on normal movement
and it'll work in this case(E - Enemy, P - Player, O - Obstacle):
P
O
EO
O
O
but what to choose if E.Y == P.Y, how to choose what's better(faster) - to move up or down?
O
EO P
O
O
or what to do if Enemy is surrounded? He can't move right, so he tries up or down, but if the are blocked?
OO
EO P
OO
I can suggest something like this for Enemy movement:
R) If right is not blocked
move right
A) If right is blocked
move up(down) (choose randomly or depending on Player's position)
then make check and select R or B
B) If chosen up(down) blocked
try down(up)
then make check and select R or C
C) If both up and down are blocked
move left and move up(down)
then make check and select R or B
Repeat it until we can use R
So it is only for "move right" check, there should be made 3 more check for the other 3 directions, i'm not so sure, but i think this code is ok for such kind of "trap"(and its variations):
OOO
O
OOO
EO P
OO
O
OO
But still it doesn't look so natural( that's why i'm going to read about A*), the Enemy would look not so smart, he should avoid this "trap", without this "research".
Should be it is hard to understand what i'm trying to say about my algorithm,but if you try to track Enemy's path yourself in your mind it could help.
To XorliumYou said A* is good... I checked Boost.Graph link, there is enough code...so, i think first i'll read about A* in my book and try to understand if it is really good for kind of game i'm developing.
So, you tested my program(special thanks), could you tell me:
1)will A* work if different object have different sizes?
2)will the be be able to avoid each other and obstacles?
3)how many objects' pathfinding is optimal for A*?
Sorry for that many questions again =)
Thanks for the help and good luck, everyone =D