for example, i wanted to put all of this in one sub:
Private Sub mymap_KeyDown(ByVal sender As System.Object, ByVal e As System.Windows.Forms.KeyEventArgs) Handles MyBase.KeyDown
Dim Loc As Point
Select Case e.KeyCode
Case Keys.Up
If Not myplayer.Location.Y - 5 < 0 And Not myplayer.Bounds.IntersectsWith(hedge1.Bounds) Then
Loc = New Point(myplayer.Location.X, myplayer.Location.Y - 5)
myplayer.Location = Loc
End If
Case Keys.Down
If Not myplayer.Location.Y + 5 < 0 And Not myplayer.Bounds.IntersectsWith(hedge1.Bounds) Then
Loc = New Point(myplayer.Location.X, myplayer.Location.Y + 5)
myplayer.Location = Loc
End If
Case Keys.Left
If Not myplayer.Location.X - 5 < 0 And Not myplayer.Bounds.IntersectsWith(hedge1.Bounds) Then
Loc = New Point(myplayer.Location.X - 5, myplayer.Location.Y)
myplayer.Location = Loc
End If
Case Keys.Right
If Not myplayer.Location.X + 5 < 0 And Not myplayer.Bounds.IntersectsWith(hedge1.Bounds) Then
Loc = New Point(myplayer.Location.X + 5, myplayer.Location.Y)
myplayer.Location = Loc
End If
End Select
End Sub
Private Sub passable()
Dim canpass As Boolean
Dim pass(3) As String
pass(0) = "bush"
pass(1) = "rock"
pass(2) = "wall"
If pass.Contains(tile) Then
canpass = False
Else
canpass = True
End If
If canpass = True And Me.hedge1.Bounds.IntersectsWith(myplayer.Bounds) Then
'allow player movement
Call mymap_KeyDown(ByVal sender As System.Object, ByVal e As System.Windows.Forms.KeyEventArgs) Handles MyBase.KeyDown
ElseIf canpass = False And Me.hedge1.Bounds.IntersectsWith(myplayer.Bounds) Then
'player is in non-passable tile and must return to position prior
Else
'player is not interacting with object
End If
End Sub
but this part:
Call mymap_KeyDown(ByVal sender As System.Object, ByVal e As System.Windows.Forms.KeyEventArgs) Handles MyBase.KeyDown
doesn't work. i've tried some variations of the call
Call mymap_KeyDown(sender, e)
Call mymap_KeyDown()
and none are working. it says in the above, "expression expected" for ByVal and i don't know what the issue is. i did try to remove byval, tried byref too, and no go.
the full code (current), by the way:
Public Class mymap
Dim tile As String
Dim sender As System.Object
Dim e As System.Windows.Forms.KeyEventArgs
Dim Loc As Point
Private Sub mymap_KeyDown(ByVal sender As System.Object, ByVal e As System.Windows.Forms.KeyEventArgs) Handles MyBase.KeyDown
Select Case e.KeyCode
Case Keys.Up
If Not myplayer.Location.Y - 5 < 0 And Not myplayer.Bounds.IntersectsWith(hedge1.Bounds) Then
Loc = New Point(myplayer.Location.X, myplayer.Location.Y - 5)
myplayer.Location = Loc
End If
Case Keys.Down
If Not myplayer.Location.Y + 5 < 0 And Not myplayer.Bounds.IntersectsWith(hedge1.Bounds) Then
Loc = New Point(myplayer.Location.X, myplayer.Location.Y + 5)
myplayer.Location = Loc
End If
Case Keys.Left
If Not myplayer.Location.X - 5 < 0 And Not myplayer.Bounds.IntersectsWith(hedge1.Bounds) Then
Loc = New Point(myplayer.Location.X - 5, myplayer.Location.Y)
myplayer.Location = Loc
End If
Case Keys.Right
If Not myplayer.Location.X + 5 < 0 And Not myplayer.Bounds.IntersectsWith(hedge1.Bounds) Then
Loc = New Point(myplayer.Location.X + 5, myplayer.Location.Y)
myplayer.Location = Loc
End If
End Select
End Sub
Private Sub passable()
Dim canpass As Boolean
Dim pass(3) As String
pass(0) = "bush"
pass(1) = "rock"
pass(2) = "wall"
If pass.Contains(tile) Then
canpass = False
Else
canpass = True
End If
If canpass = True And Me.hedge1.Bounds.IntersectsWith(myplayer.Bounds) Then
'allow player movement
'call on movement script
ElseIf canpass = False And Me.hedge1.Bounds.IntersectsWith(myplayer.Bounds) Then
'player is in non-passable tile and must return to position prior
'script to do so
Else
'player is not interacting with object
'call on movement sub
End If
End Sub
Private Sub hedge1_Click(ByVal sender As System.Object, ByVal s As System.EventArgs) Handles hedge1.Click
tile = "bush"
Call passable()
End Sub
End Class
This post has been edited by redrin: 09 December 2010 - 12:42 PM

New Topic/Question
Reply




MultiQuote








|