Results 1 to 3 of 3

Thread: NewBie Question

  1. #1

    Thread Starter
    Member
    Join Date
    Mar 2001
    Posts
    60

    NewBie Question

    how can i make a picture bounce aroound but keep it with in a certain area
    What is Life? One big dream or one Big nightmere.

  2. #2
    Addicted Member Cbomb's Avatar
    Join Date
    Jul 1999
    Posts
    153

    More info

    Try reposting...provide a bit more info...like what you mean by bouncing. Real physics? just up and down? degrading up and down? side to side?...etc...Best of luck
    Cbomb
    Techie

  3. #3
    New Member
    Join Date
    May 2001
    Location
    UK
    Posts
    4
    Add a timer and a picture box to a form the paste this in and run:

    '***
    Dim AccelX As Single, AccelY As Single
    Dim
    PosX As Single, PosY As Single

    Const
    Gravity = 6   'How strong the gravity is
    Const Damping = 0.9 'How much bouncing damps the acceleration

    Private Sub Form_Load()
      Randomize Timer

      'Set the defaults for the 'ball'
      PosX = (MaxX - Picture1.Width) \ 2
      PosY = 0
      AccelX = (Rnd * 20) - 10

      'Start the animation timer
      With Timer1
        .Interval = 50
        .Enabled = True
      End With
    End Sub


    Private Sub Timer1_Timer()
      Dim MaxX As Long, MaxY As Long

      'Get the size of the bouncing area
      MaxX = Form1.Width - 120 - Picture1.Width
      MaxY = Form1.Height - 400 - Picture1.Height

      'Increce vertical acceleration due to gravity
      AccelY = AccelY + Gravity

      'Move the image based on it's acceleration
      PosX = PosX + AccelX
      PosY = PosY + AccelY

      'Check for collisions
    &nbsp;&nbsp;If PosX < 0 Then
    &nbsp;&nbsp;&nbsp;&nbsp;PosX = -PosX
    &nbsp;&nbsp;&nbsp;&nbsp;AccelX = -AccelX * Damping
    &nbsp;&nbsp;ElseIf PosX > MaxX Then
    &nbsp;&nbsp;&nbsp;&nbsp;PosX = MaxX
    &nbsp;&nbsp;&nbsp;&nbsp;AccelX = -AccelX * Damping
    &nbsp;&nbsp;End If

    &nbsp;&nbsp;If
    PosY < 0 Then
    &nbsp;&nbsp;&nbsp;&nbsp;PosY = -PosY
    &nbsp;&nbsp;&nbsp;&nbsp;AccelY = -AccelY * Damping
    &nbsp;&nbsp;ElseIf PosY > MaxY Then
    &nbsp;&nbsp;&nbsp;&nbsp;PosY = MaxY
    &nbsp;&nbsp;&nbsp;&nbsp;AccelY = -AccelY * Damping
    &nbsp;&nbsp;End If

    &nbsp;&nbsp;'Finally move picture to new location
    &nbsp;&nbsp;Picture1.Move PosX, PosY
    End Sub
    '***

    Hope this helps,

    Mike
    -- EDais --

    WWW: Http://Members.xoom.com/EDais/
    Work E-Mail: [email protected]
    Other E-Mail: [email protected]

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width