School Assignment? Project Due Tomorrow? Chat LIVE With A Programming Expert!

Welcome to Dream.In.Code
Become an Expert!

Join 300,360 Programmers for FREE! Get instant access to thousands of experts, tutorials, code snippets, and more! There are 1,729 people online right now. Registration is fast and FREE... Join Now!




vibrating picturebox

 
Reply to this topicStart new topic

> vibrating picturebox, learn how to make things bounce

Dr.No_0B[SwE]
Group Icon



post 10 Feb, 2009 - 05:52 AM
Post #1


Hi this is my first tutorial, becuse non of the other was accepted tongue.gif there where to many of them:P icon_up.gif

ok i hope this tutorial will be approved icon_up.gif

we will make like a vibrating picturebox in a form, worthless but you will learn how to use timers:^:

form size would be like 322; 334

the first you will do is to open a new project (No shit) then add a:

Timer and a picturebox

name the picturebox "vibbox"

Timer
and set the interval to 20 and enabled to true

vibbox size would be like 282; 282

just so you know that the vibbox will be a little bit smaller then the form icon_up.gif

we need to add som variables

CODE
    Dim speed As Single = 25 ' Ball Speed
    Dim rndInst As New Random() ' Random instance
    Dim xVel As Single = Math.Cos(rndInst.Next(5, 10)) * speed
    Dim yVel As Single = Math.Sin(rndInst.Next(5, 10)) * speed


ok, now to the right wall
add this to the timer:

CODE
        If vibbox.Location.X > Me.Width - vibbox.Size.Width - 0 Then
            vibbox.Location = New Point(vibbox.Location.X, Me.Width - vibbox.Size.Width - 0)
            xVel = -xVel
        End If


ok now the vibbox only bounce on the right wall so now we gonna add the left wall

add this under the code above

CODE
        If vibbox.Location.X < 0 Then
            vibbox.Location = New Point(vibbox.Location.X, 0)
            xVel = -xVel
        End If


ok, now to the top wall

CODE
        If gameball.Location.Y < 0 Then
            gameball.Location = New Point(gameball.Location.X, 0)
            yVel = -yVel
        End If


ok, now to the buttom wall

CODE
      If vibbox.Location.Y > Me.Height - vibbox.Size.Height - 45 Then
            vibbox.Location = New Point(vibbox.Location.X, Me.Height - vibbox.Size.Height - 45)
            yVel = -yVel
        End If


that was the bounce code... run it, nothing happens i know icon_up.gif

so we have to add another code just to get the box in movement

add it under the timer

CODE
vibbox.Location = New Point(vibbox.Location.X + xVel, vibbox.Location.Y + yVel)


that was everything for now have fun with your new vibrating thing icon_up.gif





Go to the top of the page
+Quote Post


Register to Make This Ad Go Away!

Asscotte
Group Icon



post 12 Mar, 2009 - 10:03 AM
Post #2
It does not work properly- ie it goes partially of screen where it is of no use to any body


Go to the top of the page
+Quote Post

LvL 187 l33t n00b
*



post 19 Mar, 2009 - 04:15 AM
Post #3
mine wont do anything
Go to the top of the page
+Quote Post

Asscotte
Group Icon



post 25 Mar, 2009 - 11:09 AM
Post #4
i have been thinking about thins and rekon u missed a bit of code namely what is gameball and what do we do with it!!!!!

mad.gif blink.gif mad.gif
Go to the top of the page
+Quote Post


Fast ReplyReply to this topicStart new topic
1 User(s) are reading this topic (1 Guests and 0 Anonymous Users)
0 Members:

 


Lo-Fi Version Time is now: 11/7/09 07:48PM

Live Help!

Be Social

Dream.In.Code RSS Feed Dream.In.Code LinkedIn Group Follow Us On Twitter Fan Us On Facebook

Tutorials

Programming

Web Development

Reference Sheets

Code Snippets

DIC Chatroom

Bye Bye Ads

Monthly Drawing

Thumb Drive

Top Contributors

Top 10 Kudos This Month