Results 1 to 4 of 4

Thread: Game Code Help

  1. #1

    Thread Starter
    Member Giver's Avatar
    Join Date
    Aug 2008
    Posts
    39

    Game Code Help

    This sub moves a rectangle to the center of the form and when it gets there it moves back to its original location. But something weird has happened and the rectangle still moves, but the boolean values dont change. I tested to see if that part of the code was executed by putting a messagebox where the boolean values are supposed to change and the messagebox didnt appear. Help would be greatly appreciated.
    Here is the sub:
    Code:
     Public Sub Start()
            Dim Energy As New PictureBox
            _IsMoving = True 'here is the boolean values along with some other variables
            MessageBox.Show("") 'Here is the messagebox
            _HasEnergy = False 'here is the boolean values along with some other variables
            _EnergyIndex = -1
            Do Until Not Energy.Bounds.IntersectsWith(Form1.ClientRectangle)
                If Not _HasEnergy Then
                    Select Case _Index
                        Case 0
                            Rect.Location = New Point(Rect.Left + 1, Rect.Top + 1)
                        Case 1
                            Rect.Location = New Point(Rect.Left + 0, Rect.Top + 1)
                        Case 2
                            Rect.Location = New Point(Rect.Left - 1, Rect.Top + 1)
                        Case 3
                            Rect.Location = New Point(Rect.Left - 1, Rect.Top + 0)
                        Case 4
                            Rect.Location = New Point(Rect.Left - 1, Rect.Top - 1)
                        Case 5
                            Rect.Location = New Point(Rect.Left + 0, Rect.Top - 1)
                        Case 6
                            Rect.Location = New Point(Rect.Left + 1, Rect.Top - 1)
                        Case 7
                            Rect.Location = New Point(Rect.Left + 1, Rect.Top + 0)
                    End Select
                    For i = 0 To 9
                        If Rect.IntersectsWith(Form1.Controls("Energy" & i).Bounds) Then
                            _HasEnergy = True
                            Energy = Form1.Controls("Energy" & i)
                            _EnergyIndex = i
                            Exit For
                        End If
                    Next i
                Else
                    Select Case _Index
                        Case 0
                            Rect.Location = New Point(Rect.Left - 1, Rect.Top - 1)
                        Case 1
                            Rect.Location = New Point(Rect.Left - 0, Rect.Top - 1)
                        Case 2
                            Rect.Location = New Point(Rect.Left + 1, Rect.Top - 1)
                        Case 3
                            Rect.Location = New Point(Rect.Left + 1, Rect.Top - 0)
                        Case 4
                            Rect.Location = New Point(Rect.Left + 1, Rect.Top + 1)
                        Case 5
                            Rect.Location = New Point(Rect.Left - 0, Rect.Top + 1)
                        Case 6
                            Rect.Location = New Point(Rect.Left - 1, Rect.Top + 1)
                        Case 7
                            Rect.Location = New Point(Rect.Left - 1, Rect.Top - 0)
                    End Select
                    If Not Rect.IntersectsWith(Form1.ClientRectangle) Then
                        Form1.Lives -= 1
                        _HasEnergy = False
                        _IsMoving = False
                        _EnergyIndex = -1
                        Exit Do
                        Exit Sub
                    End If
                End If
                Application.DoEvents()
                Threading.Thread.Sleep(1)
            Loop
        End Sub

  2. #2
    Fanatic Member Vectris's Avatar
    Join Date
    Dec 2008
    Location
    USA
    Posts
    941

    Re: Game Code Help

    Look at where the messagebox is. It's at the top of your code, meaning NONE of it is running. We need the code where you actually call this sub or else we can't help you. Make sure you actually call the sub somewhere else in your code.
    If your problem is solved, click the Thread Tools button at the top and mark your topic as Resolved!

    If someone helped you out, click the button on their post and leave them a comment to let them know they did a good job

    __________________
    My Vb.Net CodeBank Submissions:
    Microsoft Calculator Clone
    Custom TextBox Restrictions
    Get the Text inbetween HTML Tags (or two words)

  3. #3

    Thread Starter
    Member Giver's Avatar
    Join Date
    Aug 2008
    Posts
    39

    Re: Game Code Help

    Ok when I get on my computer I'll post the sub that starts this sub.

  4. #4

    Thread Starter
    Member Giver's Avatar
    Join Date
    Aug 2008
    Posts
    39

    Re: Game Code Help

    The sub Start is in a class called Enemy. This is the loop that starts the sub:

    Code:
     Dim Threads As New Thread(AddressOf MoveEnemies)
                For Me.E = 0 To 7
                    If Not Enemies(E).IsMoving Then
                        Threads = New Thread(AddressOf MoveEnemies)
                        Threads.Start()
                        Me.Text = E
                        Thread.Sleep(2000)
                    End If
                Next E
    This is the MoveEnemies sub:

    Code:
        Public Sub MoveEnemies()
            If Not E < 8 Then Exit Sub
            Enemies(E).Start()
        End Sub
    Enemies is an array of the class enemy. OK, I just figured something out. When i replace Enemies(E).Start() with Enemies(0).Start it works just fine and all the code in the sub Start is executed. But when i do that only Enemies(0) is running and i want them all to run at the same time.

Tags for this Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width