本人用VB编写赌场轮盘游戏遇到的难题,请高手指点!
这个难题就是如何编写代码使得Image控件对象或Picture控件对象旋转?
2013-03-02 13:24
2013-03-02 17:03

2013-03-03 12:27
程序代码:Private Type PointApi
x As Long
y As Long
End Type
Private Declare Function PlgBlt Lib "gdi32" (ByVal hdcDest As Long, lpPoint As PointApi, _
ByVal hdcSrc As Long, ByVal nXSrc As Long, ByVal nYSrc As Long, ByVal nWidth As Long, _
ByVal nHeight As Long, ByVal hbmMask As Long, ByVal xMask As Long, ByVal yMask As Long) As Long
Dim TZb(2) As PointApi '目标图形当前坐标,数组中3个元素存储顺序为左上角、右上角、左下角
Dim rS As Single '旋转半径
Private Sub Command1_Click()
Dim xo As Single, yo As Single, xs As Single, ys As Single
If Command1.Caption = "转" Then
Command1.Caption = "停"
xo = Picture2.Width * 0.5: yo = Picture2.Height * 0.5 '目标区域圆心
xs = Picture1.Width * 0.5: ys = Picture1.Height * 0.5 '源图像圆心
TZb(0).x = xo - xs: TZb(0).y = yo - ys
TZb(1).x = xo + xs: TZb(1).y = yo - ys
TZb(2).x = xo - xs: TZb(2).y = yo + ys
rS = Sqr((xo - TZb(0).x) ^ 2 + (yo - TZb(0).y) ^ 2) '求取半径
Picture2.Cls
PlgBlt Picture2.hDC, TZb(0), Picture1.hDC, 0, 0, Picture1.Width, Picture1.Height, 0, 0, 0
Picture2.Refresh
Timer1.Interval = 10
Else
Timer1.Interval = 0
Command1.Caption = "转"
Picture2.Cls
End If
End Sub
Private Sub Form_Load()
Me.Height = 5730: Me.Width = 10755: Me.ScaleMode = 3
Picture1.Height = 25: Picture1.Width = 145: Picture1.ScaleMode = 3: Picture1.Left = 32: Picture1.Top = 24
Picture1.FontName = "宋体": Picture1.FontSize = 18: Picture1.BorderStyle = 0: Picture1.Appearance = 0: Picture1.AutoRedraw = True
Command1.Caption = "转": Command1.Height = 49: Command1.Width = 121: Command1.Top = 216: Command1.Left = 40
Picture2.Left = 224: Picture2.Top = 0: Picture2.ScaleMode = 3: Picture2.Width = 473: Picture2.Height = 337
Picture2.BorderStyle = 0: Picture2.Appearance = 0: Picture2.AutoRedraw = True
Picture1.Print "转死人不偿命"
End Sub
Private Sub Timer1_Timer()
Dim xo As Single, yo As Single, angle As Integer
If Command1.Caption = "转" Then Exit Sub
'根据当前坐标、半径计算转动一个角度后的各点坐标
xo = Picture2.Width * 0.5: yo = Picture2.Height * 0.5 '目标区域圆心
angle = -20 '设定转动角度,负数顺时针转,正数逆时针转
'如果设计轮盘转动可以设计一个加速转动后减速停止的过程,可把angle作为sin函数变量,当angle为0时就停了
TZb(0) = getNewZb(angle, TZb(0), xo, yo, rS) '左上角坐标
TZb(1) = getNewZb(angle, TZb(1), xo, yo, rS) '右上角坐标
TZb(2) = getNewZb(angle, TZb(2), xo, yo, rS) '左下角坐标
Picture2.Cls
PlgBlt Picture2.hDC, TZb(0), Picture1.hDC, 0, 0, Picture1.Width, Picture1.Height, 0, 0, 0
Picture2.Refresh
End Sub
Private Function getNewZb(jiao As Integer, oldZb As PointApi, xo As Single, yo As Single, rHalf As Single) As PointApi
'根据圆点坐标、圆上一点坐标、圆半径求转过一个角度jiao后的坐标
Dim x As Single, y As Single, h As Single
h = jiao * 3.1415926 / 180 '把角度换算为弧度
x = (oldZb.x - xo) * Cos(h) + (oldZb.y - yo) * Sin(h) + xo
y = (oldZb.y - yo) * Cos(h) + yo - (oldZb.x - xo) * Sin(h)
'记住上述两个算法,复习复习下三角函数就知道为什么这样算了。
getNewZb.x = x
getNewZb.y = y
End Function
2013-03-03 15:37
2013-03-04 17:08

2013-03-04 22:37
2013-03-05 00:16