Please Help. Arrays I think

Discussion in 'Software' started by Anon-15281db623, Jan 4, 2005.

  1. Anon-15281db623

    Anon-15281db623 Anonymized

    Ok here is my problem.

    I have two objects on a form. Pic1, and Pic2. Both Pic1, and Pic2 will be moved by a keypress. Pic1 will use the arrow keys, and Pic2 will use WASD. My goal here is to be able to move both objects at the same time. Using the keypress event does not let me do that. :(

    I received some advice from another person on this. Here is what he said:

    Ok i dont know how to do that lol. Here is my take on what i need.

    Using the Array I will have a switch board with boolean values.

    When i press D, Pic1 Moves to the right using the code i provided below. I substatued Pic1 for all the "Cage....." names for time reasons.

    Code:
    Private Sub MoveRight()
            Me.CageDucking.Left = Me.CageWalkingRight.Left
            Me.CageJumping.Left = Me.CageWalkingRight.Left
            Me.CageWalkingRight.Left = Me.CageStanding.Left
            Me.CageWalkingLeft.Left = Me.CageWalkingRight.Left
            Me.CageStanding.Left = Me.CageStanding.Left + 5
            Me.CageWalkingRight.Visible = True
            Me.CageDucking.Hide()
            Me.CageJumping.Hide()
            Me.CageStanding.Hide()
            Me.CageWalkingLeft.Hide()
        End Sub
    
    Is what im asking even possible? This is going to be a two player fighting game. Simular to mortal kombat. I need to be able to move both pics at the same time. :)

    Thanks so much for the help!

    :cool:

    cooked
     
  2. Anon-15281db623

    Anon-15281db623 Anonymized

    BTW Im using VB .NET

    Here is the code i was able to come up with. I thought using booleans would allow me to move both the fighters at once, but no luck. :(

    Code:
    Indicates if the left / right buttons are pressed.
        Dim CageGoLeft, CageGoRight, ReptileGoLeft, ReptileGoRight As Boolean
    
        Private Sub MoveFighter(ByVal sender As Object, ByVal e As System.Windows.Forms.KeyEventArgs) Handles MyBase.KeyDown
            'Move Cage by pressing the arrow keys
            Select Case e.KeyCode
                Case Keys.Left
                    CageGoLeft = True
                Case Keys.Right
                    CageGoRight = True
            End Select
            'Move Reptile by pressing the WASD Keys
            Select Case e.KeyCode
                Case Keys.A
                    ReptileGoLeft = True
                Case Keys.D
                    ReptileGoRight = True
            End Select
        End Sub
    
        Private Sub MainTimer_Tick(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MainTimer.Tick
            Select Case
                'Move Cage using provided code if the boolean is true
                Case CageGoLeft
                    Me.CageDucking.Left = Me.CageWalkingRight.Left
                    Me.CageJumping.Left = Me.CageWalkingRight.Left
                    Me.CageWalkingRight.Left = Me.CageStanding.Left
                    Me.CageWalkingLeft.Left = Me.CageWalkingRight.Left
                    Me.CageStanding.Left = Me.CageStanding.Left - 5
                    Me.CageWalkingLeft.Visible = True
                    Me.CageDucking.Hide()
                    Me.CageJumping.Hide()
                    Me.CageStanding.Hide()
                    Me.CageWalkingRight.Hide()
                Case CageGoRight
                    Me.CageDucking.Left = Me.CageWalkingRight.Left
                    Me.CageJumping.Left = Me.CageWalkingRight.Left
                    Me.CageWalkingRight.Left = Me.CageStanding.Left
                    Me.CageWalkingLeft.Left = Me.CageWalkingRight.Left
                    Me.CageStanding.Left = Me.CageStanding.Left + 5
                    Me.CageWalkingRight.Visible = True
                    Me.CageDucking.Hide()
                    Me.CageJumping.Hide()
                    Me.CageStanding.Hide()
                    Me.CageWalkingLeft.Hide()
            End Select
    
            'Move Reptile usind proved code if the boolean is true
            Select Case
                Case ReptileGoLeft
                    Me.ReptileDucking.Left = Me.ReptileWalkingRight.Left
                    Me.ReptileJumping.Left = Me.ReptileWalkingRight.Left
                    Me.ReptileWalkingRight.Left = Me.ReptileStanding.Left
                    Me.ReptileWalkingLeft.Left = Me.ReptileWalkingRight.Left
                    Me.ReptileStanding.Left = Me.ReptileStanding.Left - 5
                    Me.ReptileWalkingLeft.Visible = True
                    Me.ReptileDucking.Hide()
                    Me.ReptileJumping.Hide()
                    Me.ReptileStanding.Hide()
                    Me.ReptileWalkingRight.Hide()
                Case ReptileGoRight
                    Me.ReptileDucking.Left = Me.ReptileWalkingRight.Left
                    Me.ReptileJumping.Left = Me.ReptileWalkingRight.Left
                    Me.ReptileWalkingRight.Left = Me.ReptileStanding.Left
                    Me.ReptileWalkingLeft.Left = Me.ReptileWalkingRight.Left
                    Me.ReptileStanding.Left = Me.ReptileStanding.Left + 5
                    Me.ReptileWalkingRight.Visible = True
                    Me.ReptileDucking.Hide()
                    Me.ReptileJumping.Hide()
                    Me.ReptileStanding.Hide()
                    Me.ReptileWalkingLeft.Hide()
            End Select
    
        End Sub
    
        Private Sub ArmoryBckGnd_KeyUp(ByVal sender As Object, ByVal e As System.Windows.Forms.KeyEventArgs) Handles MyBase.KeyUp
            'When the key lets up then stop moving
            If e.KeyCode = Keys.Left Then
                CageGoLeft = False
            ElseIf e.KeyCode = Keys.Right Then
                CageGoRight = False
            End If
            'Ditto
            If e.KeyCode = Keys.A Then
                ReptileGoLeft = False
            ElseIf e.KeyCode = Keys.D Then
                ReptileGoRight = False
            End If
    End Class
    
    :cool:

    cooked
     
  3. Anon-15281db623

    Anon-15281db623 Anonymized

    Anyone?

    Could i forget an Array and still make this work? Maybe a collection? I tried looking on MSDN, but their info was a little over the top for me.

    Any help, comments, and suggestions are appreciated. :)

    :cool:

    cooked
     

MajorGeeks.Com Menu

Downloads All In One Tweaks \ Android \ Anti-Malware \ Anti-Virus \ Appearance \ Backup \ Browsers \ CD\DVD\Blu-Ray \ Covert Ops \ Drive Utilities \ Drivers \ Graphics \ Internet Tools \ Multimedia \ Networking \ Office Tools \ PC Games \ System Tools \ Mac/Apple/Ipad Downloads

Other News: Top Downloads \ News (Tech) \ Off Base (Other Websites News) \ Way Off Base (Offbeat Stories and Pics)

Social: Facebook \ YouTube \ Twitter \ Tumblr \ Pintrest \ RSS Feeds