home *** CD-ROM | disk | FTP | other *** search
/ Planet Source Code Jumbo …e CD Visual Basic 1 to 7 / 1_2002.ISO / Data / Zips / Bubble-Gra77974512002.psc / clsObject.cls < prev    next >
Encoding:
Visual Basic class definition  |  2002-04-19  |  2.0 KB  |  110 lines

  1. VERSION 1.0 CLASS
  2. BEGIN
  3.   MultiUse = -1  'True
  4.   Persistable = 0  'NotPersistable
  5.   DataBindingBehavior = 0  'vbNone
  6.   DataSourceBehavior  = 0  'vbNone
  7.   MTSTransactionMode  = 0  'NotAnMTSObject
  8. END
  9. Attribute VB_Name = "clsObject"
  10. Attribute VB_GlobalNameSpace = False
  11. Attribute VB_Creatable = True
  12. Attribute VB_PredeclaredId = False
  13. Attribute VB_Exposed = False
  14. Attribute VB_Ext_KEY = "SavedWithClassBuilder6" ,"Yes"
  15. Attribute VB_Ext_KEY = "Member0" ,"clsMassiveObject"
  16. Attribute VB_Ext_KEY = "Top_Level" ,"Yes"
  17. Option Explicit
  18.  
  19. Dim XPos As Single
  20. Dim YPos As Single
  21. Dim XVel As Single
  22. Dim YVel As Single
  23.  
  24. Property Let X(Value As Single)
  25.  
  26. XPos = Value
  27.  
  28. End Property
  29.  
  30. Property Get X() As Single
  31.  
  32. X = XPos
  33.  
  34. End Property
  35.  
  36. Property Let Y(Value As Single)
  37.  
  38. YPos = Value
  39.  
  40. End Property
  41.  
  42. Property Get Y() As Single
  43.  
  44. Y = YPos
  45.  
  46. End Property
  47.  
  48. Property Let XSpeed(Value As Single)
  49.  
  50. XVel = Value
  51.  
  52. End Property
  53.  
  54. Property Get XSpeed() As Single
  55.  
  56. XSpeed = XVel
  57.  
  58. End Property
  59.  
  60. Property Let YSpeed(Value As Single)
  61.  
  62. YVel = Value
  63.  
  64. End Property
  65.  
  66. Property Get YSpeed() As Single
  67.  
  68. YSpeed = YVel
  69.  
  70. End Property
  71.  
  72. Sub Accelerate(ByVal Degrees As Single, ByVal Amount As Single)
  73.  
  74. XVel = XVel + (Amount * Cos(DegToRad(Degrees)))
  75. YVel = YVel + (Amount * Sin(DegToRad(Degrees)))
  76.  
  77. End Sub
  78.  
  79. Sub MoveIt(ByVal FormWidth As Single, ByVal FormHeight As Single)
  80.  
  81. XPos = XPos + XVel
  82. YPos = YPos + YVel
  83.  
  84. 'Collision detection with walls. Reflects bubbles
  85. 'As far as I can see, this should result in a perfect reflection,
  86. 'BUT IT DOESN'T. Why?
  87. 'No, of course it doesn't! Gravity is pulling it in the same direction in the
  88. 'unit of time, when the object actually reflects during that unit of time.
  89. If XPos < 0 Then
  90.     XPos = -XPos
  91.     XVel = -XVel
  92. End If
  93.  
  94. If XPos > FormWidth Then
  95.     XPos = FormWidth - (XPos - FormWidth)
  96.     XVel = -XVel
  97. End If
  98.  
  99. If YPos < 0 Then
  100.     YPos = -YPos
  101.     YVel = -YVel
  102. End If
  103.  
  104. If YPos > FormHeight Then
  105.     YPos = FormHeight - (YPos - FormHeight)
  106.     YVel = -YVel
  107. End If
  108.  
  109. End Sub
  110.