Answered Array Question

12padams

Well-known member
Joined
Feb 19, 2010
Messages
48
Programming Experience
Beginner
Ok I am making an RPG that is checking for collisions whenever the user is walking...

Basically i made an array of points in which the user is not allowed to access and if they do try to access them it will not walk...

VB.NET:
Public Class cityshop2010
    Dim abletomove As Boolean = True
    Dim moveto As Point
    Dim badpoints(1) As Point
    Dim playerx As Integer = 256
    Dim playery As Integer = 0
    Private Sub Form1_KeyDown(ByVal sender As Object, ByVal e As System.Windows.Forms.KeyEventArgs) Handles Me.KeyDown
        If abletomove = True Then
            If e.KeyCode = Keys.Left Then
                player.Image = My.Resources.mainplayerleft
                moveto = New Point(playerx - 32, playery)
                If moveto = badpoints(0) Then
                Else
                    playerx = playerx - 32
                    player.Location = New Point(playerx, playery)
                End If
            End If


            If e.KeyCode = Keys.Right Then
                player.Image = My.Resources.mainplayerright
                moveto = New Point(playerx + 32, playery)
                If moveto = badpoints(0) Then
                Else
                    playerx = playerx + 32
                    player.Location = New Point(playerx, playery)
                End If
                End If


                If e.KeyCode = Keys.Up Then
                    player.Image = My.Resources.mainplayerup
                    moveto = New Point(playerx, playery - 32)
                If moveto = badpoints(0) Then
                Else
                    playery = playery - 32
                    player.Location = New Point(playerx, playery)
                End If
                End If

                If e.KeyCode = Keys.Down Then
                    player.Image = My.Resources.mainplayerdown
                    moveto = New Point(playerx, playery + 32)
                If moveto = badpoints(0) Then
                Else
                    playery = playery + 32
                    player.Location = New Point(playerx, playery)
                End If
                End If
            End If
            abletomove = False
            moveable.Start()
    End Sub

    Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load

        badpoints(0) = New Point(0, 0)
        badpoints(1) = New Point(224, 0)


    End Sub

    Private Sub moveable_Tick(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles moveable.Tick
        abletomove = True
        moveable.Stop()
        
    End Sub
End Class

Also Here is a screen shot so you get the picture of what it looks like...
1a9634cd80.png

Here is what i want:
VB.NET:
If moveto = badpoints(0) Then
with that code there I want to be able to say badpoints(0-50) or badpoints (0 to 50) whatever... or even badpoints(*) for any badpoint....

How do i make it check all the badpoints?
 
Last edited:
Back
Top