VBcoders Guest



Don't have an account yet? Register
 


Forgot Password?



a non-vector ball bounce script that accounts for form size changes

by Lee Carraher (2 Submissions)
Category: Custom Controls/Forms/Menus
Compatability: VB 6.0
Difficulty: Unknown Difficulty
Originally Published: Tue 30th October 2001
Date Added: Mon 8th February 2021
Rating: (1 Votes)

a non-vector ball bounce script that accounts for form size changes

API Declarations


'this is a ball bounce program that simulates the path of a ball bouncing
'inside of a form. instead of using vector changes for direction and speed i
'decided to use nested if statements with a boolean fo the direction. include '
are a few other options that can be initiated throught he code.
'Form set-up: one shape (Shape1) preferably a ball and one timer initiated at 1-'10

Option Explicit
Private BoundX As Integer
Private BoundY As Integer
Private circlePosX As Integer
Private circlePosY As Integer
Private isRight As Boolean
Private isDown As Boolean
'Private ValRnd As Byte

Rate a non-vector ball bounce script that accounts for form size changes



isRight = True
isDown = True
End Sub

Private Sub Timer1_Timer()
BoundY = Form1.ScaleHeight - (Shape1.Height / 2) 'greater equals down
BoundX = Form1.Width - (Shape1.Width / 2)
Shape1.Top = circlePosY
Shape1.Left = circlePosX
'initiate for more balls that follow encapsled paths also make more shapes
'Shape2.Left = circlePosX * 0.1
'Shape2.Top = circlePosY * 0.1
'Shape3.Left = circlePosX * 0.3
'Shape3.Top = circlePosY * 0.3
'Shape4.Left = circlePosX * 0.6
'Shape4.Top = circlePosY * 0.6
'Shape5.Left = circlePosX * 0.9
'Shape5.Top = circlePosY * 0.9

'random number initiate for a wobble effect
'Dim RndMax As Long
'RndMax = 5 'Max value of ValRnd
'ValRnd = (Int(Rnd * RndMax) + 1)



'x boundaries
If circlePosX < BoundX And isRight = True Then
    circlePosX = circlePosX + 100 '* (ValRnd)
    isRight = True
Else
    circlePosX = circlePosX - 100 '* (ValRnd)
    isRight = False
    If circlePosX < 0 Then
        isRight = True
       End If
End If

'y boundaries
If circlePosY < BoundY And isDown = True Then
    circlePosY = circlePosY + 100 '* (5 - ValRnd)
    isDown = True
Else
    circlePosY = circlePosY - 100 '* (5 - ValRnd)
    isDown = False
    If circlePosY < 0 Then
        isDown = True
    End If
End If


End Sub


Download this snippet    Add to My Saved Code

a non-vector ball bounce script that accounts for form size changes Comments

No comments have been posted about a non-vector ball bounce script that accounts for form size changes. Why not be the first to post a comment about a non-vector ball bounce script that accounts for form size changes.

Post your comment

Subject:
Message:
0/1000 characters