Calculating movement on a grid

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

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 on other sites
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.

1. 1
2. 2
3. 3
Rutin
13
4. 4
5. 5

• 26
• 11
• 9
• 9
• 11
• Forum Statistics

• Total Topics
633699
• Total Posts
3013416
×