Bouncing Ball (Tutorial)

Heres your chance to share your own tutorials with the community. Just post them on here. If your lucky they may even be posted on the main site.
1 post Page 1 of 1
Contributors
MANSQN
VIP - Donator
VIP - Donator
Posts: 159
Joined: Sat Sep 17, 2011 11:33 pm

Bouncing Ball (Tutorial)
MANSQN
This tutorial will show you how to make a bouncing ball program

1 use a transparent picture for this tutorial

2 Change also Size Mode to Zoom

4 Add 4 timers to the form. Change their interval property to 1

Change also the first timer Enabled property to True

Let's add the code to each timer tick event:
Code: Select all
Timer1.Tick

Private Sub Timer1_Tick(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Timer1.Tick

        PictureBox1.Location = New Point(PictureBox1.Location.X + 5, PictureBox1.Location.Y + 5)

        If PictureBox1.Location.X + PictureBox1.Width > Me.Width Then

            Timer1.Stop()

            Timer2.Start()

        End If

 

        If PictureBox1.Location.Y + PictureBox1.Height > Me.Height Then

            Timer1.Stop()

            Timer3.Start()

        End If

    End Sub
Code: Select all
Timer2.Tick

 

Private Sub Timer2_Tick(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Timer2.Tick

        PictureBox1.Location = New Point(PictureBox1.Location.X - 5, PictureBox1.Location.Y + 5)

        If PictureBox1.Location.Y + PictureBox1.Height > Me.Height Then

            Timer2.Stop()

            Timer4.Start()

        End If

        If PictureBox1.Location.X < 0 Then

            Timer2.Stop()

            Timer1.Start()

        End If

    End Sub
Code: Select all
Timer3.Tick

Private Sub Timer3_Tick(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Timer3.Tick

        PictureBox1.Location = New Point(PictureBox1.Location.X + 5, PictureBox1.Location.Y - 5)

        If PictureBox1.Location.X + PictureBox1.Width > Me.Width Then

            Timer3.Stop()

            Timer4.Start()

        End If

        If (PictureBox1.Location.Y < 0) Then

            Timer3.Stop()

            Timer1.Start()

        End If

    End Sub
Code: Select all
Timer4.Tick

Private Sub Timer4_Tick(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Timer4.Tick

        PictureBox1.Location = New Point(PictureBox1.Location.X - 5, PictureBox1.Location.Y - 5)

        If PictureBox1.Location.X < 0 Then

            Timer4.Stop()

            Timer3.Start()

        End If

        If (PictureBox1.Location.Y < 0) Then

            Timer4.Stop()

            Timer2.Start()

        End If

    End Sub
1 post Page 1 of 1
Return to “Tutorials”