📄 sprite.cls
字号:
VERSION 1.0 CLASS
BEGIN
MultiUse = -1 'True
END
Attribute VB_Name = "Sprite"
Attribute VB_Creatable = False
Attribute VB_Exposed = False
Option Explicit
'This is the Sprite Class. It basically handles the creation
'and maintenance of Sprites. A Sprite object, in this case,
'is nothing more than a fancy data structure used to store &
'manipulate information about our animations. Most of the real
'work is in the BitmapBuffer class and the Paint method of this
'Sprite class. You must create a BitmapBuffer object and store the
'bitmap that contains the individual frames (or cels) of your
'sprite before you can use it.
'
'The Sprite class has 14 properties and one method:
'
Public XCoord As Long
' XCoord Indicates the current horizontal position of the sprite.
' <PROPERTY> <READ/WRITE>
'
Public YCoord As Long
' YCoord Indicates the current vertical position of the sprite.
' <PROPERTY> <READ/WRITE>
'
Public CelHeight As Long
' CelHeight The height of each cel of the sprite animation.
' <PROPERTY> <READ/WRITE>
'
Public CelWidth As Long
' CelWidth The width of each cel of the sprite animation.
' <PROPERTY> <READ/WRITE>
'
Public CelCount As Long
' CelCount The number of cels in the sprite animation.
' <PROPERTY> <READ/WRITE>
'
Public CelNum As Long
' CelNum The current cel number in the sprite animation.
' <PROPERTY> <READ/WRITE>
'
Public CelhDC As Long
' CelhDC The handle to the memory device context that stores
' the bitmap of the animation cels.
' <PROPERTY> <READ/WRITE>
'
Public CelStartX As Long
' CelStartX The horizontal coordinate in the bitmap where the cels
' for this sprite begin. <PROPERTY> <READ/WRITE>
'
Public CelStartY As Long
' CelStartY The vertical coordinate in the bitmap where the cels
' for this sprite begin. <PROPERTY> <READ/WRITE>
'
Public Status As Integer
' Status Indicates the Status of the sprite, i.e. animated,
' moving, dead, walking, swimming, etc...
' This property is set up as bit flags. There are
' 16 bits in an integer, so you could have 16 different
' flags for your sprite. Bits 1 and 2 are reserved for
' Animated and Moving, respectively and should not
' be used for other purposes. If you need more than 16
' flags for your sprite, change the Status variable to
' a long integer. <PROPERTY> <READ/WRITE>
'
Public AnimSpeed As Long
' AnimSpeed Determines the speed at which the sprite is animated.
' This property is not implemented yet. When we get into
' timing schemes other than the Timer object, we will use
' this property. <PROPERTY> <READ/WRITE>
'
Public MoveSpeed As Long
' MoveSpeed Determines the speed at which the sprite moves.
' This property is not implemented yet. When we get into
' timing schemes other than the Timer object, we will use
' this property. <PROPERTY> <READ/WRITE>
'
Public CollisionHeight As Long
' CollisionHeight Determines the height of the 'bounding box' around the
' sprite for collision detection. This property is not
' implemented yet. When we get into collision detection,
' we will use this property. <PROPERTY> <READ/WRITE>
'
Public CollisionWidth As Long
' CollisionWidth Determines the width of the 'bounding box' around the
' sprite for collision detection. This property is not
' implemented yet. When we get into collision detection,
' we will use this property. <PROPERTY> <READ/WRITE>
'
'
' Paint Blits the current cel of the sprite to the specified
' device context. <METHOD>
'
' USAGE: object.Paint DesthDC
Sub Paint(ByVal SpriteDest As Long)
'When the Paint method is invoked, this procedure is called.
'Set up a temporary variable to store the results of the BitBlt function
Dim tmpVal As Long
'First Blit the mask to the Destination using the SRCAND ROP code.
BitBlt SpriteDest, XCoord, YCoord, CelWidth, CelHeight, CelhDC, CelNum * CelWidth, CelHeight, SRCAND
'Then Blit the image to the Destination using the SRCINVERT ROP code.
BitBlt SpriteDest, XCoord, YCoord, CelWidth, CelHeight, CelhDC, CelNum * CelWidth, 0, SRCINVERT
'Increment the current cel if the sprite is animated.
If (Status And Animated) Then CelNum = CelNum + 1
'Loop the current cel back to zero if it's past the cel count.
If CelNum > CelCount - 1 Then CelNum = 0
End Sub
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -