Jump to content
  • Advertisement
Sign in to follow this  
Anonyymi

Calculating movement on a grid

This topic is 3980 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

Hi, Let's say i have a 2d array of structs. Every cell has information about game area, like if there is player in it or is there a wall or free area and other stuff too. Wall means player can't go there, free area means it's walkable :) So basically that is grid that has information about game map in it. What would be the efficient way to calculate cells with free area where player can move, when player has x-amount of movement points? Also i need to calculate if player can see other player somewhere. I've heard something about Bresenham algorithm, is it something i should use ?

Share this post


Link to post
Share on other sites
Advertisement
To find cells where the player can move, just do a depth first search to a limited depth.

To find if something is visible to the player, you draw a line from the player to the object. The line is made of grid cells instead of pixels. Bresenham's algorithm is an efficient way to do this, although in modern machines floating point can be used instead of the trick to avoid floating point.

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!