Link to home
Start Free TrialLog in
Avatar of BitHunt
BitHuntFlag for Belgium

asked on

AI for a 2D character

I am new to game programming and would like to implement a 2d java applet game in which a person will compete with an hero  (with AI)  to collect all the golds in a platform without being detected to creatures.  The basic game scenario  is shown in the image (without the human character included). In the game:

-There are creatures moving on their path (red line) with different speeds and moving to opposite directions
- Both the creatures and the hero (AI) will have line of sight but hero's line of sight is larger than the creatures'.
-If any of the character (human or hero(ai) ) gets into creatures' line of sight it loses.

My question is  how can I make the hero collect all the golds in the map by reacting to creatures (hiding,direction changing etc.) without being detected by creatures.is it hard to implement this kind of ai? Do I also need to implement a path finding algorithm, can't I give the route to him, if so how?Can you recommend me algorithms, examples etc.?

Thank you User generated image
Avatar of Member_2_5069294
Member_2_5069294

Are all of the levels going to be circular?
Does the hero AI know when they player takes some gold, so that it ignores the areas where could has been taken by the player.

Do the creatures move consistently?  I understand they aren't the same speed, but do they stop, or change directions?

From the diagram it looks as though the hero should follow the same path as the creatures.  The main path would have connected paths that lead to the gold.  The AI moves along the main path until it reached one of the connected paths.  It's decision about what to do is based on the positions of the creature on the path and the distance/time to the available gold.
Avatar of BitHunt

ASKER

-An answer for rectangular structured  levels is perfectly fine. I think i should start with that since it seems easier.

-Hero AI and the player will have their own golds with different colors. They can't take each others golds.

-Creatures move consistently, they can randomly stop, wait for a couple of seconds and continue in the same direction  (it doesn't change its direction)

Thank you
ASKER CERTIFIED SOLUTION
Avatar of TommySzalapski
TommySzalapski
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
SOLUTION
Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
SOLUTION
Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Sorry, DHaest, I missed your first comment when you made it. http:#a35181690 gives a good solution to the original problem and http:#a35201018 answers the askers most recent question quite fully.
I wish to support TommySzalapski's solution.  If I had more time I would posted a more complete description of a very similar idea.  BitHunt's answer (using A*) will work, but it's neither necessary or especially effective in this case.  A case of sledgehammer to crack a nut, final result is a smashed nut.