Re: Line of sight bug - anyone help




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


.



Relevant Pages

  • Re: Can this be done?
    ... Dim sh1 As Worksheet ... Dim cell As Range ... about each player on that coach's team. ...
    (microsoft.public.excel.programming)
  • Re: Output form to excel with range ????
    ... here is a long post with lots of useful code for exporting to excel. ... Dim varGetFileName As Variant 'File Name with Full Path ... Set objXLws = objXLWkb.ActiveSheet ... For Each cell In objXLws.Range ...
    (microsoft.public.access.formscoding)
  • RE: Offset(0, 1) and then Offset(1, 0)?
    ... Dim rngMyRange As Range ... Dim rngBlanks As Range ... Dim rng As Range ... How can I modify the code to get the cell ...
    (microsoft.public.excel.programming)
  • Re: Formulas containing hard coded values
    ... Dim R As Range, sdoit As String ... MsgBox "Cell contains hard codes" ... Dim Fml As String, LCtext As String ... For Each Rng In R.Precedents.Areas ...
    (microsoft.public.excel.programming)
  • Re: Nested table question (W2003)
    ... Dim oCell As Word.Cell ... 'Extract cell text ... only the parent cell string by the end of the loop. ... Set oRng = ActiveDocument.Range ...
    (microsoft.public.word.vba.general)