Hi guys,
I’ve been itching to build a game for years and have spent a long time planning all the features I want to implement and how it’s going to work. I just hope I can muster the technical expertise to go from paper to computer
I would like to ask you guys about implementing a maximum sight range and line of sight blocking terrain in a tile-based game.
say I have my character at position 10,10. He should be able to see up to 5 squares away, simple. BUT I would like it to be in a circle around him like this:
x x x x - - - x x x x
x x - - - - - - - x x
x - - - - - - - - - x
x - - - - - - - - - x
- - - - - - - - - - -
- - - - - o - - - - -
- - - - - - - - - - -
x - - - - - - - - - x
x - - - - - - - - - x
x x - - - - - - - x x
x x x x - - - x x x x
How would you go about dynamically generating this map? I would like the sight range to be variable (so at night it couldbe reduced, some mobs might have higher or lower range, etc).
I thought about calculating it like a triangle - x squared + y squared = direct distance squared but calculating this 120 times (for a sight radius of 5) per frame per entity doesn’t sound like the best way to do it.
I worked out that I could fudge it a bit by pre calculating the entity’s vision range and valid tile ids when creating the entity but wouldn’t that then hog memory that I wouldn’t need to be keeping?
My next problem is how to calculate the vision range when a sight blocking object is present, like this:
x x x x - - - x x x x
x x x - - - - - - x x
x x x - - - - - - - x
x - - B - - - - - - x
- - - - - - - - - - x
- - - - - o - - B x x
- - - - - - - - - - x
x - - - B - - - - - x
x - - x - - - - - - x
x x x x - - - - - x x
x x x x - - - x x x x
I can’t even fathom where to beging on calculating which blocks behind a blocking piece we should hide!
I’m not looking for code as I would rather understand how the process should work and code it myself to show my understanding so any talk on the subject would be very helpful
Many thanks for reading!
(P.s. I’m new here, please be nice)