Sign in to follow this  
MrChrisnis

C++ AI Coordinate movement

Recommended Posts

I am currently working on programming a basic text based wizard game. I have my movements working for coordinates (north = x+1, east = y+1 etc.) and I am just wondering how you could code it so that the AI moves randomly on coordinates in close proximity to you. The idea is that after moving around for a bit you will land on the same coordinates as your opponent and enter a battle.

Thanks
Chris

Share this post


Link to post
Share on other sites
[quote name='MrChrisnis' timestamp='1318881323' post='4873600']
I am currently working on programming a basic text based wizard game. I have my movements working for coordinates (north = x+1, east = y+1 etc.) and I am just wondering how you could code it so that the AI moves randomly on coordinates in close proximity to you. The idea is that after moving around for a bit you will land on the same coordinates as your opponent and enter a battle.

Thanks
Chris
[/quote]


Do you mean the enemy should be aware of the player's position when its moving so that it keeps being inside a specific proximity of the player?

Share this post


Link to post
Share on other sites
here is some pseudo code that came to my mind right now:

[CODE]

vec2d dist = distVec(player, enemy)

if (dist.x > MAX_DIST)
enemy.x-- // depending on what u want
else if (dist.x < -MAX>DIST)
enem.x++

if (dist.y > MAX_DIST)
enemy.y--
else if (dist.y < - MAX_DIST)
enemy.y++

[/CODE]


that should keep the enemy within a certain range to the player.. if u want the enemy to chase u, u can do the following pseudocode:

[CODE]

if (enemy.x < player.x)
enemy.x++

etc..

[/CODE]

than the enemy goes terminator style after u..

hope to have helped u, it took a while to get your problem ^^ (and i am still not sure if that was what u wanted to know :-)

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this