Help with a bouncing ball
Help with a bouncing ball
Help with a bouncing ball
Help with a bouncing ball
Help with a bouncing ball
Help with a bouncing ball Help with a bouncing ball Help with a bouncing ball Help with a bouncing ball Help with a bouncing ball Help with a bouncing ball Help with a bouncing ball Help with a bouncing ball
Help with a bouncing ball Help with a bouncing ball
Help with a bouncing ball
Go Back  Xtreme Visual Basic Talk > > > Help with a bouncing ball


Reply
 
Thread Tools Display Modes
  #1  
Old 09-28-2009, 09:46 AM
AlmightySi AlmightySi is offline
Newcomer
 
Join Date: Sep 2009
Posts: 5
Default Help with a bouncing ball


Hey, my first post here.

Im in need of some help with making a bouncing ball. All this ball has to do is literally jump up and down. I don't wish for the ball to hit the top of the form, I wish for the ball to bounce up and then fall like gravity is pushing it, I need it to do this over and over.

Once I have the ball I wish to add controls to it so I can move it left and right whilst its bouncing, but I believe I can do that part myself, hopefully.

Can anybody help me, or is there any tutorials out there?
Reply With Quote
  #2  
Old 09-29-2009, 02:14 PM
Iceplug's Avatar
IceplugHelp with a bouncing ball Iceplug is offline
MetaCenturion

Retired Moderator
* Guru *
 
Join Date: Aug 2001
Location: Iowa, USA
Posts: 16,583
Default

What have you set up so far?

You'll need to have a vertical velocity variable declared:
Adjust the value of velocity by adding a value to velocity - this is the acceleration - do not make it 9.8 unless you really want to - it doesn't make the jump any more realistic than if you used 5 !
Veloc = Veloc + 5

After you've updated the speed, move the ball in accordance with the Veloc:
Ball.Top = Ball.Top + Veloc
Depending on how you declared veloc, you may have to convert the value.

The next part comes with bouncing:
to make the ball bounce you have to determine if the ball is at the bottom of the area.
If so, make the ball bounce by reversing the sign of velocity.
Veloc = -Veloc

Adding positive values to Velocity will continue to raise velocity back to a positive number and bring the ball back to the bottom of the area.

You may have to experiment with values of acceleration so that your ball is not hyperactive... if you release the ball with Veloc = 0 initially, you should have a good view of what is going on.
__________________

Iceplug, USN
Quadrill 1 Quadrill 2 (full) Quadrill 3 JumpCross .NET Website is ALIVE! - DL Platform Tour for VB.NET! Posting Guidelines Hint: Specify your location in your user cp profile if you want compassion!
Reply With Quote
  #3  
Old 12-04-2009, 07:12 PM
AlmightySi AlmightySi is offline
Newcomer
 
Join Date: Sep 2009
Posts: 5
Default

Sorry I didnt reply back saying thanks. Here is what I came up with in the end,

Code:
Public Class JumpingBall
    Dim BounceSpeed As Double

    Private Sub JumpingBall_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
        pbBall.Location = New Point(pbPaddle.Location.Y + 46, pbPaddle.Location.X + 25)
        BounceSpeed = cbBounceSpeed.Text
    End Sub

    Private Sub BtnBounce_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles BtnBounce.Click

        If cbBounceSpeed.Text = "" Then
            MsgBox("Select bounce speed")
        Else
            BounceSpeed = cbBounceSpeed.Text
            TimerBounce.Enabled = True
        End If

    End Sub

    Private Sub btnStop_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnStop.Click

        pbBall.Location = New Point(pbPaddle.Location.Y + 46, pbPaddle.Location.X + 25)
        TimerBounce.Enabled = False

    End Sub

    Private Sub TimerBounce_Tick(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles TimerBounce.Tick

        pbBall.Top = pbBall.Top + BounceSpeed

        If pbBall.Location.Y >= Me.Height - 200 Then
            BounceSpeed = BounceSpeed - 0.6
        End If

        If pbBall.Bounds.IntersectsWith(pbPaddle.Bounds) Then
            BounceSpeed = cbBounceSpeed.Text
        End If

    End Sub
End Class
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
Help with a bouncing ball
Help with a bouncing ball
Help with a bouncing ball Help with a bouncing ball
Help with a bouncing ball
Help with a bouncing ball
Help with a bouncing ball Help with a bouncing ball Help with a bouncing ball Help with a bouncing ball Help with a bouncing ball Help with a bouncing ball Help with a bouncing ball
Help with a bouncing ball
Help with a bouncing ball
 
Help with a bouncing ball
Help with a bouncing ball
 
-->