locked
Minor "Jump" issue RRS feed

  • Question

  • Having a little trouble with my jump method I created. Basicly if you "keyup" durnign the jump processs the keyup mybase will not grab it and you keep running. So I just need a simple solution or adjustment. Here is my code:

    Warning Codes still a little messy

    Private Sub Screen_1_KeyDown(sender As System.Object, e As System.Windows.Forms.KeyEventArgs) Handles MyBase.KeyDown
            If e.KeyValue = Keys.A Then
                Storage.MLeft = True
                Mario_Timer.Start()
            End If
    
            If e.KeyValue = Keys.D Then
                Storage.MRight = True
                Mario_Timer.Start()
            End If
    
            If e.KeyValue = Keys.Space Then
                Storage.MJump = True
                Jump_Timer.Start()
            End If
        End Sub
    
        Private Sub Screen_1_KeyUp(sender As System.Object, e As System.Windows.Forms.KeyEventArgs) Handles MyBase.KeyUp
            If e.KeyValue = Keys.A And Storage.MJump = False Then
                Storage.MLeft = False
                Mario_Timer.Stop()
                MTick = 1
                pbMario.BackgroundImage = My.Resources.Mario_Run_1L
            End If
    
            If e.KeyValue = Keys.D And Storage.MJump = False Then
                Storage.MRight = False
                Mario_Timer.Stop()
                MTick = 1
                pbMario.BackgroundImage = My.Resources.Mario_1R
            End If
        End Sub
    
        Private Sub Mario_Timer_Tick(sender As System.Object, e As System.EventArgs) Handles Mario_Timer.Tick
            If Storage.MLeft = True And Storage.MJump = False Then
                Select Case MTick
                    Case 1
                        pbMario.BackgroundImage = My.Resources.Mario_Run_1L
                        pbMario.Left -= 5
                        MTick += 1
                    Case 2
                        pbMario.BackgroundImage = My.Resources.Mario_Run_2L
                        pbMario.Left -= 5
                        MTick += 1
                    Case 3
                        pbMario.BackgroundImage = My.Resources.Mario_Run_3L
                        pbMario.Left -= 5
                        MTick += 1
                    Case 4
                        pbMario.BackgroundImage = My.Resources.Mario_Run_4L
                        pbMario.Left -= 5
                        MTick = 1
                End Select
            ElseIf Storage.MRight = True And Storage.MJump = False Then
                Select Case MTick
                    Case 1
                        pbMario.BackgroundImage = My.Resources.Mario_1R
                        pbMario.Left += 5
                        MTick += 1
                    Case 2
                        pbMario.BackgroundImage = My.Resources.Mario_Run_2R
                        pbMario.Left += 5
                        MTick += 1
                    Case 3
                        pbMario.BackgroundImage = My.Resources.Mario_Run_3R
                        pbMario.Left += 5
                        MTick += 1
                    Case 4
                        pbMario.BackgroundImage = My.Resources.Mario_Run_4R
                        pbMario.Left += 5
                        MTick = 1
                End Select
            End If
        End Sub
    
        Private Sub Jump_Timer_Tick(sender As System.Object, e As System.EventArgs) Handles Jump_Timer.Tick
            If Storage.MJump = True And Storage.MLeft = False And Storage.MRight = False Then
                Select Case JTick
                    Case 1
                        pbMario.BackgroundImage = My.Resources.Mario_Run_1L
                        pbMario.Top -= 10
                        JTick += 1
                    Case 2
                        pbMario.BackgroundImage = My.Resources.Mario_Run_1L
                        pbMario.Top -= 10
                        JTick += 1
                    Case 3
                        pbMario.BackgroundImage = My.Resources.Mario_Run_1L
                        pbMario.Top += 10
                        JTick += 1
                    Case 4
                        pbMario.BackgroundImage = My.Resources.Mario_Run_1L
                        Jump_Timer.Stop()
                        pbMario.Top += 10
                        Storage.MJump = False
                        JTick = 1
                End Select
            ElseIf Storage.MJump = True And Storage.MLeft = True Then
                Select Case JTick
                    Case 1
                        pbMario.BackgroundImage = My.Resources.Mario_Run_1L
                        pbMario.Top -= 10
    
                        pbMario.Left -= 5
                        JTick += 1
                    Case 2
                        pbMario.BackgroundImage = My.Resources.Mario_Run_1L
                        pbMario.Top -= 10
                        pbMario.Left -= 5
                        JTick += 1
                    Case 3
                        pbMario.BackgroundImage = My.Resources.Mario_Run_1L
                        pbMario.Left -= 5
                        JTick += 1
                    Case 4
                        pbMario.BackgroundImage = My.Resources.Mario_Run_1L
                        pbMario.Top += 10
                        pbMario.Left -= 5
                        JTick += 1
                    Case 5
                        pbMario.BackgroundImage = My.Resources.Mario_Run_1L
                        Jump_Timer.Stop()
                        pbMario.Top += 10
                        pbMario.Left -= 5
                        Storage.MJump = False
                        JTick = 1
                End Select
            ElseIf Storage.MJump = True And Storage.MRight = True Then
                Select Case JTick
                    Case 1
                        pbMario.BackgroundImage = My.Resources.Mario_1R
                        pbMario.Top -= 10
                        pbMario.Left += 5
                        JTick += 1
                    Case 2
                        pbMario.BackgroundImage = My.Resources.Mario_1R
                        pbMario.Top -= 10
                        pbMario.Left += 5
                        JTick += 1
                    Case 3
                        pbMario.BackgroundImage = My.Resources.Mario_Run_1L
                        pbMario.Left += 5
                        JTick += 1
                    Case 4
                        pbMario.BackgroundImage = My.Resources.Mario_1R
                        pbMario.Top += 10
                        pbMario.Left += 5
                        JTick += 1
                    Case 5
                        pbMario.BackgroundImage = My.Resources.Mario_1R
                        Jump_Timer.Stop()
                        pbMario.Top += 10
                        pbMario.Left += 5
                        Storage.MJump = False
                        JTick = 1
                End Select
            End If
        End Sub

    Thursday, June 14, 2012 6:41 PM

Answers

All replies

  • solved
    • Marked as answer by mholmes_3038 Saturday, June 16, 2012 12:03 AM
    Saturday, June 16, 2012 12:03 AM
  • Hi mholmes,

    Glad to hear that you solved your issue. Would you like to share the solution here? It will benefit the members who have similar issue with yours.

    Have a nice day. 


    Mark Liu-lxf [MSFT]
    MSDN Community Support | Feedback to us

    Monday, June 18, 2012 2:17 AM