Picture box movement bug
Picture box movement bug
Picture box movement bug
Picture box movement bug
Picture box movement bug
Picture box movement bug Picture box movement bug Picture box movement bug Picture box movement bug Picture box movement bug Picture box movement bug Picture box movement bug Picture box movement bug
Picture box movement bug Picture box movement bug
Picture box movement bug
Go Back  Xtreme Visual Basic Talk > > > Picture box movement bug


Reply
 
Thread Tools Display Modes
  #1  
Old 12-30-2009, 08:05 PM
AkselJ AkselJ is offline
Newcomer
 
Join Date: Dec 2009
Location: Norway
Posts: 20
Default Picture box movement bug


Ok, so I'm making a simple breakout game, using picture boxes as I didn't want to bother installing picture boxes.

Every movement works perfectly fine; the pad moves correctly, the ball bounces right. Except when I move the pad while the ball is moving.

If I move the pad while the ball is moving, the ball moves at the same speed as the pad, which is 10 times the speed of the ball.

Well here's the movement code.

Code:
    Public Sub Movement(ByVal Movement As String) ' Handles movement

        If Not IsPlaying Then Exit Sub

        Select Case Movement
            Case "Right" ' Moves the pad to the right, distance of movement equals v
                If frmGame.picPad.Left <= EdgeR - PadWidth Then
                    If Not frmGame.picPad.Left + v > EdgeR - PadWidth Then
                        frmGame.picPad.Left = frmGame.picPad.Left + v
                        If Not IsLaunched Then
                            frmGame.picBall.Left = frmGame.picBall.Left + v
                        End If
                    Else
                        If Not IsLaunched Then
                            frmGame.picBall.Left = frmGame.picBall.Left + Int(EdgeR - PadWidth - frmGame.picPad.Left)
                        End If
                        frmGame.picPad.Left = EdgeR - PadWidth
                    End If
                End If
                Exit Sub

            Case "Left" ' Moves the pad to the left, distance of movement equals v
                If frmGame.picPad.Left >= EdgeL Then
                    If Not frmGame.picPad.Left - v < EdgeL Then
                        frmGame.picPad.Left = frmGame.picPad.Left - v
                        If Not IsLaunched Then
                            frmGame.picBall.Left = frmGame.picBall.Left - v
                        End If
                    Else
                        If Not IsLaunched Then
                            frmGame.picBall.Left = frmGame.picBall.Left - Int(frmGame.picPad.Left - EdgeL)
                        End If
                        frmGame.picPad.Left = EdgeL
                    End If
                End If
                Exit Sub

            Case "Launch" ' Launches the ball from the pad
                If Not IsLaunched Then
                    Angle = GetBallAngle(BallLeft, PadStart)
                    frmGame.picBall.Left = frmGame.picBall.Left + Angle
                    frmGame.picBall.Top = frmGame.picBall.Top - v / 10
                    BonusC = BonusT(CurLevel) + 100
                    frmGame.tmrBonus.Enabled = True
                    frmGame.tmrBall.Enabled = True
                    BallDir = 1
                    BallDir2 = 1
                End If
                Exit Sub

            Case "Ball" ' Moves the ball
                Angle = GetBallAngle(BallLeft, PadStart)
                If frmGame.picBall.Left + Angle >= EdgeR - BallWidth And BallDir = 1 Then
                    frmGame.picBall.Left = EdgeR - BallWidth
                    BallDir = 2
                ElseIf frmGame.picBall.Left - Angle <= EdgeL And BallDir = 2 Then
                    frmGame.picBall.Left = EdgeL
                    BallDir = 1
                Else
                    Select Case BallDir
                        Case 1
                            frmGame.picBall.Left = frmGame.picBall.Left + Angle

                        Case 2
                            frmGame.picBall.Left = frmGame.picBall.Left - Angle
                    End Select
                End If

                If frmGame.picBall.Top - v / 10 <= EdgeT And BallDir2 = 1 Then
                    frmGame.picBall.Top = EdgeT
                    BallDir2 = 2
                ElseIf frmGame.picBall.Top + v / 10 >= EdgeB And BallDir2 = 2 Then
                    Call StopGame()
                Else
                    Select Case BallDir2
                        Case 1
                            frmGame.picBall.Top = frmGame.picBall.Top - v / 10

                        Case 2
                            frmGame.picBall.Top = frmGame.picBall.Top + v / 10

                    End Select
                End If
                Exit Sub

        End Select
    End Sub
Well.... Any idea what's wrong?

Thanks for reading,
--AkselJ
Reply With Quote
  #2  
Old 12-30-2009, 09:08 PM
Cerian Knight's Avatar
Cerian KnightPicture box movement bug Cerian Knight is offline
Polymath (in disciplina)

Super Moderator
* Expert *
 
Join Date: May 2004
Location: Michigan
Posts: 4,191
Default

Perhaps you are not setting 'IsLaunched = True' after launch or you have some logic that resets 'IsLaunched = False' when the ball touches the paddle?

A few other comments for your consideration:
It is not generally recommended to have a sub/function variable with the same name as the sub/function.
Also, all of the 'Exit Sub' lines aren't really needed, but perhaps I'm just being picky.
Not that it matters, but I can't tell looking at the code if you are using .NET (this sub-forum) or VB6 (legacy sub-forum).

Good luck.
__________________
I got all the answers wrong on the GLAT, apparently even #9 (where I put a period in the middle of the box and labeled it 'singularity ripe for rapid inflation').
Reply With Quote
  #3  
Old 12-31-2009, 07:12 AM
AkselJ AkselJ is offline
Newcomer
 
Join Date: Dec 2009
Location: Norway
Posts: 20
Default

Quote:
Originally Posted by Cerian Knight View Post
Perhaps you are not setting 'IsLaunched = True' after launch or you have some logic that resets 'IsLaunched = False' when the ball touches the paddle?
Man, I can't believe it, I actually forgot that!
Somehow the speed is ten times higher if the game thinks the ball isn't launched...

Thanks for pointing out my stupid mistake...

Oh, and the exit subs is just an habit I have from VBS, where it may screw up scripts if you don't have it after cases
Reply With Quote
Reply


Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off

Forum Jump

Advertisement:





Free Publications
The ASP.NET 2.0 Anthology
101 Essential Tips, Tricks & Hacks - Free 156 Page Preview. Learn the most practical features and best approaches for ASP.NET.
subscribe
Programmers Heaven C# School Book -Free 338 Page eBook
The Programmers Heaven C# School book covers the .NET framework and the C# language.
subscribe
Build Your Own ASP.NET 3.5 Web Site Using C# & VB, 3rd Edition - Free 219 Page Preview!
This comprehensive step-by-step guide will help get your database-driven ASP.NET web site up and running in no time..
subscribe
Picture box movement bug
Picture box movement bug
Picture box movement bug Picture box movement bug
Picture box movement bug
Picture box movement bug
Picture box movement bug Picture box movement bug Picture box movement bug Picture box movement bug Picture box movement bug Picture box movement bug Picture box movement bug
Picture box movement bug
Picture box movement bug
 
Picture box movement bug
Picture box movement bug
 
-->