This is my first attempt at trying to do OO programming. Ive always been interested in phsyics so I thought I would try to learn by making a class for different types of object such as Circles and Squares and Lines and such and then have them interact correctly. So far this is what Ive got, but I think I am going about this the wrong way. Id appreciate any suggestions on how I can make it easier to work with and make more sense before I get to far into the project. I would also like to know if I am handling the classes corrrectly since I have never done this before,
In the code for Form1
Const NumCircles As Integer = 3
Dim Circles(1 To NumCircles) As New CCircle
Dim Gravity As New Point
Private Sub Form_Load()
Gravity.Y = -2
Dim counter As Integer
While counter < NumCircles
counter = counter + 1
Circles(counter).LoadCircle counter * 600, 1000, 300
Wend
End Sub
Private Sub Timer1_Timer()
Cls
Dim counter As Integer
While counter < NumCircles
counter = counter + 1
If Circles(counter).CLoc.Y - Circles(counter).CRadius < 0 Then
Circles(counter).CLoc.Y = Circles(counter).CRadius
Dim Rebound As New Point
Rebound.Y = Circles(counter).CVel.Y * -1.5
Circles(counter).ApplyForce Rebound, 1
End If
If Circles(counter).CLoc.X - Circles(counter).CRadius < 0 Then
Circles(counter).CLoc.X = Circles(counter).CRadius
Dim LeftRebound As New Point
Rebound.X = Circles(counter).CVel.X * -1.5
Circles(counter).ApplyForce Rebound, 1
End If
If Circles(counter).CLoc.X - Circles(counter).CRadius > 5000 Then
Circles(counter).CLoc.X = Circles(counter).CRadius
Dim RightRebound As New Point
Rebound.Y = Circles(counter).CVel.X * -1.5
Circles(counter).ApplyForce Rebound, 1
End If
Circles(counter).ApplyForce Gravity, 1
Circles(counter).Update
Circles(counter).DrawCircle
Wend
End Sub
In the Class Module for Circle
Public CRadius As Integer
Public CLoc As New Point
Public CVel As New Point
Public CAccel As New Point
Public Sub DrawCircle()
Form1.Circle (CLoc.X, CLoc.Y), CRadius, RGB(0, 0, 0)
End Sub
Public Sub Update()
CVel.Add CAccel
Dim Canceller As New Point
Canceller.X = CAccel.X * -1
Canceller.Y = CAccel.Y * -1
CAccel.Add Canceller
CLoc.Add CVel
End Sub
Public Sub ApplyForce(Normal As Point, Magnitude As Integer)
CAccel.Add Normal
End Sub
Public Sub LoadCircle(X As Integer, Y As Integer, Radius As Integer)
CLoc.X = X
CLoc.Y = Y
CRadius = Radius
End Sub
In the class module for Point
Public X As Integer
Public Y As Integer
Public Sub Add(Point2 As Point)
X = X + Point2.X
Y = Y + Point2.Y
End Sub