Implementing movement on a grid

Posted by Dvole on Game Development See other posts from Game Development or by Dvole
Published on 2014-05-27T10:56:48Z Indexed on 2014/05/27 16:03 UTC
Read the original article Hit count: 261

Filed under:
|

I have a simple snake game, where I have other NPC snakes on the field. How do I calculate the movement of those other snakes so that they did not hit walls, and each other?

So far I have it like this:

I check for current coordinates and when there is a wall nearby I change direction to some other one. And so on, this way the snakes never collide the walls.

But not actually colliding other snakes, how do I prevent this?

I figured I could probe for the direction I'm heading and if there is anything there I would change direction too, but there is a set of situation where this won't work, for example if another snake will block off all exits later.

© Game Development or respective owner

Related posts about architecture

Related posts about grid