Mutsop
asked on
reduce movement speed of moving picturebox
So I'm actually stuck at how to reduce movement speed (of my minigolf game)
To recap, I have a small picturebox and a timer set to 20ms.
So on mouseUp I have following code:
Now, in my timerTick I have the code to check for wall collision and this:
Now that I think about it, the xVel and yVel are already multiplied by the speed (usually around 0,07). This might seem like a simple answer to you, but my brains wont function anymore :D
To recap, I have a small picturebox and a timer set to 20ms.
So on mouseUp I have following code:
xVel = (e.X - gameBall.Location.X) * speed
yVel = (e.Y - gameBall.Location.Y) * speed
gameTimer.Enabled = True
Now, in my timerTick I have the code to check for wall collision and this:
If speed > 0 Then
speed -= 0.01
Else
gameTimer.Enabled = False
End If
Now that I think about it, the xVel and yVel are already multiplied by the speed (usually around 0,07). This might seem like a simple answer to you, but my brains wont function anymore :D
ASKER
How to get your total distance if you just have the speed?
Speed is actually calculated like so
The strengthTimer_Tick is activated upon pressing down the left mouse button.
Speed is actually calculated like so
Private Sub strengthTimer_Tick(ByVal sender As Object, ByVal e As System.EventArgs) Handles strengthTimer.Tick
If strengthBar.Value = 100 Then
strengthBar.Value = 0
End If
strengthBar.PerformStep()
End Sub
Private Sub Main_MouseUp(ByVal sender As Object, ByVal e As System.Windows.Forms.MouseEventArgs) Handles Me.MouseUp
strengthTimer.Enabled = False
'Speed value
speed = strengthBar.Value / 500
If e.Button = Windows.Forms.MouseButtons.Left Then
ControlPaint.DrawReversibleLine(ptStart, ptEnd, Color.Black)
Cursor.Clip = Nothing
xVel = (e.X - gameBall.Location.X) * speed
yVel = (e.Y - gameBall.Location.Y) * speed
gameTimer.Enabled = True
End If
End Sub
The strengthTimer_Tick is activated upon pressing down the left mouse button.
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
That means you first need to calculate the distance that your picture box will travel.
I think the speed change should NOT be linear, but a some function speed=f(distance). And perhaps the function should be logarithmic, since it gives the best view of reducing speed, IMO.
Something like ln(D-d), where D is the total distance, and d is the current distance traveled.