home *** CD-ROM | disk | FTP | other *** search
/ Visual Basic Graphics Programming (2nd Edition) / Visual Basic Graphics Programming 2nd Edition.iso / OldSrc / CH5 / SRC / SPRCIRC.CLS < prev    next >
Encoding:
Text File  |  1996-02-26  |  1.7 KB  |  66 lines

  1. VERSION 1.0 CLASS
  2. BEGIN
  3.   MultiUse = -1  'True
  4. END
  5. Attribute VB_Name = "CircleSprite"
  6. Attribute VB_Creatable = False
  7. Attribute VB_Exposed = False
  8. ' ************************************************
  9. ' Moving circle sprite.
  10. ' ************************************************
  11. Option Explicit
  12.  
  13. Dim R As Integer        ' Radius.
  14. Dim Cx As Integer       ' Position of center.
  15. Dim Cy As Integer
  16. Dim Vx As Integer       ' Velocity.
  17. Dim Vy As Integer
  18. Dim Clr As Long         ' Color.
  19. ' ************************************************
  20. ' Draw the circle on the indicated picture box.
  21. ' ************************************************
  22. Public Sub DrawSprite(pic As PictureBox)
  23.     pic.FillColor = Clr
  24.     pic.Circle (Cx, Cy), R, Clr
  25. End Sub
  26.  
  27. ' ************************************************
  28. ' Initialize the circle.
  29. ' ************************************************
  30. Public Sub InitializeSprite(radius As Integer, x As Integer, y As Integer, dx As Integer, dy As Integer, c As Long)
  31.     R = radius
  32.     Cx = x
  33.     Cy = y
  34.     Vx = dx
  35.     Vy = dy
  36.     Clr = c
  37. End Sub
  38.  
  39.  
  40. ' ************************************************
  41. ' Add the velocity components to the sprite's
  42. ' position components.
  43. ' ************************************************
  44. Public Sub MoveSprite(xmax As Integer, ymax As Integer)
  45.     Cx = Cx + Vx
  46.     Cy = Cy + Vy
  47.     
  48.     ' Keep the circle within the drawing area.
  49.     If Cx < 0 Then
  50.         Cx = -Cx
  51.         Vx = -Vx
  52.     ElseIf Cx > xmax Then
  53.         Cx = 2 * xmax - Cx
  54.         Vx = -Vx
  55.     End If
  56.     If Cy < 0 Then
  57.         Cy = -Cy
  58.         Vy = -Vy
  59.     ElseIf Cy > ymax Then
  60.         Cy = 2 * ymax - Cy
  61.         Vy = -Vy
  62.     End If
  63. End Sub
  64.  
  65.  
  66.