Sorry your browser is not supported!

You are using an outdated browser that does not support modern web technologies, in order to use this site please update to a new browser.

Browsers supported include Chrome, FireFox, Safari, Opera, Internet Explorer 10+ or Microsoft Edge.

Code Snippets / 2D DBPro Line of Sight Demo

Author
Message
DeepBlue
21
Years of Service
User Offline
Joined: 17th May 2003
Location: A little box in the UK
Posted: 9th Nov 2004 01:11 Edited at: 11th Nov 2004 10:09
Just posted this in response to a thread. Sorry no real time to comment it, but guess someone may find it useful (no media reqd).

Note, the step value in the losTest function is currently set to maximum for speed reducing it will give greater accuracy but will decrease speed.



DeepBlue

The coder formerly known as Twynklet.
Chris K
21
Years of Service
User Offline
Joined: 7th Oct 2003
Location: Lake Hylia
Posted: 9th Nov 2004 02:24
I don't get what it does
DeepBlue
21
Years of Service
User Offline
Joined: 17th May 2003
Location: A little box in the UK
Posted: 9th Nov 2004 11:30 Edited at: 9th Nov 2004 12:04
It tests the Line of Sight between the player and objects on/in the map array (i.e. It checks to see if a wall is in the way) to see if they are visible. These could be any objects i.e. enemy. In the demo code it checks all the floor tiles to see which ones are visible to the player and highlights them.

Tried various other methods including making a 1x1 sprite stretching it along 1 axis (doen't work the collision box/sprite is made into a rectangle around the entire shape).

I only made it because someone else wanted it so I'll probably never use it so thought I'd put it here.

DeepBlue

The coder formerly known as Twynklet.
Cloggy
20
Years of Service
User Offline
Joined: 31st Oct 2004
Location: Rayleigh, Essex
Posted: 11th Nov 2004 07:32
DeepBlue,

It works well. But runs at 9fps on my machine (2600XP).

Would it be quicker to workout the line of site from each square beforehand and store it along with the map data?

Not sure how eay this is to do, but it should pick up the frame rate a bit.

Cheers,

Cloggy
DeepBlue
21
Years of Service
User Offline
Joined: 17th May 2003
Location: A little box in the UK
Posted: 11th Nov 2004 09:53 Edited at: 11th Nov 2004 10:10
Oops left an unwanted set sprite command in that reduced the frame rate around 10 fold. It's not really the LOS calcs that were killing the framerate but the sprites. Have amended above code & here it is again now runs at around 320fps on my PC.



As it was originally used to show someone how to do LOS checks for enemy objects it had to be done real time, but if you just wanted it for static walls as in the demo yes it could be pre calculated.

DeepBlue

The coder formerly known as Twynklet.

Login to post a reply

Server time is: 2025-05-09 23:07:17
Your offset time is: 2025-05-09 23:07:17