Solved

reduce movement speed of moving picturebox

Posted on 2011-09-20
3
245 Views
Last Modified: 2012-05-12
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:
xVel = (e.X - gameBall.Location.X) * speed
            yVel = (e.Y - gameBall.Location.Y) * speed
            gameTimer.Enabled = True

Open in new window


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

Open in new window


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
0
Comment
Question by:Mutsop
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 2
3 Comments
 
LVL 8

Expert Comment

by:gena17
ID: 36567385
I believe you want to reduce movement speed so that each gets 0 at the end.
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.
0
 
LVL 3

Author Comment

by:Mutsop
ID: 36567452
How to get your total distance if you just have the speed?
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

Open in new window


The strengthTimer_Tick is activated upon pressing down the left mouse button.
0
 
LVL 8

Accepted Solution

by:
gena17 earned 500 total points
ID: 36580301
The total distance should be calculated in advance at the moment when user clicks on Desired Location.
The total distance is the distance between Desired Location and Current Location. It is calculated only once and has nothing to do with speed.

Speed is calculated dynamically on every tick of the timer, based on Total Distance and Current Distance.
0

Featured Post

How our DevOps Teams Maximize Uptime

Our Dev teams are like yours. They’re continually cranking out code for new features/bugs fixes, testing, deploying, responding to production monitoring events and more. It’s complex. So, we thought you’d like to see what’s working for us. Read the use case whitepaper.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Calculating holidays and working days is a function that is often needed yet it is not one found within the Framework. This article presents one approach to building a working-day calculator for use in .NET.
It was really hard time for me to get the understanding of Delegates in C#. I went through many websites and articles but I found them very clumsy. After going through those sites, I noted down the points in a easy way so here I am sharing that unde…
With Secure Portal Encryption, the recipient is sent a link to their email address directing them to the email laundry delivery page. From there, the recipient will be required to enter a user name and password to enter the page. Once the recipient …
I've attached the XLSM Excel spreadsheet I used in the video and also text files containing the macros used below. https://filedb.experts-exchange.com/incoming/2017/03_w12/1151775/Permutations.txt https://filedb.experts-exchange.com/incoming/201…

751 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question