Re: Line of sight bug - anyone help
- From: "John Palmer" <thepalm2@xxxxxxxxx>
- Date: Thu, 15 Jan 2009 07:37:54 GMT
I have a relatively minor bug in my line of sight code, that I believe<snip lots>
Your code looks very complicated - having different code for each quadrant
is not going to be fun when you want to change how LOS works - heres my code
(converted from C# to VB so it might be a little ugly) - but I think it's
reasonably clear whats going on
This code could use much optimisation - but i think its reasonably clear - I
commented just about everything to make it clear what happens
Private Sub checkvis()
'check every cell in the map
For i As Integer = 0 To maparray.GetUpperBound(0)
For j As Integer = 0 To maparray.GetUpperBound(1)
maparray(i, j, curlevel).visible = False
' vecttormap is the cell we are testing
Dim vectormap As New Vector(i, j)
'subtvect is a vector which goes between the player (0 in the array) and the
cell we are testing
Dim subtvect As Vector = Vector.Subtract(vectormap, actorarray(0,
curlevel).vectorpos)
'This sets up the maximum view range for the player - allows for blindness
Dim range As Integer = 0
If actorarray(0, curlevel).effects(CInt(effect.blind)) > 0 Then
range = 0
Else
range = actorarray(0, curlevel).sightrange
End If
'check the tested cell is not to far away - and that we aren't getting a div
by 0 error
If subtvect.Length <= range AndAlso subtvect.Length > 0 Then
'obtain a unit vector in the direction to test
subtvect = subtvect / subtvect.Length
For lengthfromplayer As Integer = 1 To range
'testcell is a cell along the route from the player to vectormap - we check
the player can see through it
Dim testcell As New Vector(actorarray(0, curlevel).xpos +
CInt((lengthfromplayer * subtvect.X)), actorarray(0, curlevel).ypos +
CInt((lengthfromplayer * subtvect.Y)))
If maparray(CInt(testcell.X), CInt(testcell.Y), curlevel).seeable = True
AndAlso (maparray(CInt(testcell.X), CInt(testcell.Y), curlevel).lit = True
OrElse (testcell - actorarray(0, curlevel).vectorpos).lengthforlight <
actorarray(0, curlevel).lightradius) Then
maparray(CInt(testcell.X), CInt(testcell.Y), curlevel).visible = True
maparray(CInt(testcell.X), CInt(testcell.Y), curlevel).seen = True
Else
maparray(CInt(testcell.X), CInt(testcell.Y), curlevel).visible = True
maparray(CInt(testcell.X), CInt(testcell.Y), curlevel).seen = True
'this breaks out of the loop because we got stuck
Exit For
End If
Next
End If
Next
Next
'make sure we can see the player's postion
maparray(CInt(actorarray(0, curlevel).xpos), CInt(actorarray(0,
curlevel).ypos), curlevel).visible = True
maparray(CInt(actorarray(0, curlevel).xpos), CInt(actorarray(0,
curlevel).ypos), curlevel).seen = True
End Sub
.
- Follow-Ups:
- Re: Line of sight bug - anyone help
- From: Brigand
- Re: Line of sight bug - anyone help
- References:
- Line of sight bug - anyone help
- From: Brigand
- Line of sight bug - anyone help
- Prev by Date: Re: IRDC 2008 movies about to go down
- Next by Date: Re: The Rogue Bard unveiling
- Previous by thread: Re: Line of sight bug - anyone help
- Next by thread: Re: Line of sight bug - anyone help
- Index(es):
Relevant Pages
|