图像处理进阶----动画处理一例
刚做了一个模拟坦克行走,射击的动画(坦克有点粗糙了,呵呵),希望对图像进阶的编程爱好者起到抛砖引玉的效果,这里发出源码Private a,b As Double
Private m, n As Double
Private flag, check As Integer
Private boom As Integer
Private Sub Form_Load() '坦克初始位置向上
SendKeys "W"
End Sub
Private Sub P_Keydown(KeyCode As Integer, Shift As Integer)
P.ScaleMode = 0 '用户自定义
P.ScaleMode = 3
P.Scale (-10, 10)-(10, -10) '设定行走范围
If a >= -9.55 And (KeyCode = vbKeyA Or KeyCode = vbKeyA + 32) Then 'A
P.Cls
a = a - 0.2
P.DrawWidth = 15
P.PSet (a, b), vbBlue
P.DrawWidth = 2
P.Line (a, b)-(a - 0.5, b), vbRed
flag = 1 ’标记坦克方向,为发射方向做基础
End If
If a <= 9.55 And (KeyCode = vbKeyD Or KeyCode = vbKeyD + 32) Then 'D
P.Cls
a = a + 0.2
P.DrawWidth = 15
P.PSet (a, b), vbBlue
P.DrawWidth = 2
P.Line (a, b)-(a + 0.5, b), vbRed
flag = 2
End If
If b <= 9.55 And (KeyCode = vbKeyW Or KeyCode = vbKeyW + 32) Then 'W
P.Cls
b = b + 0.2
P.DrawWidth = 15
P.PSet (a, b), vbBlue
P.DrawWidth = 2
P.Line (a, b)-(a, b + 0.5), vbRed
flag = 3
End If
If b >= -9.55 And (KeyCode = vbKeyS Or KeyCode = vbKeyS + 32) Then 'S
P.Cls
b = b - 0.2
P.DrawWidth = 15
P.PSet (a, b), vbBlue
P.DrawWidth = 2
P.Line (a, b)-(a, b - 0.5), vbRed
flag = 4
End If
If b >= -9.55 And (KeyCode = vbKeyH Or KeyCode = vbKeyH + 32) And boom = 0 Then 'H 子弹射击处理BOOM=0防止重复发射
m = a
n = b
boom = 1
check = flag
Timer1.Enabled = True
End If
End Sub
Private Sub Timer1_Timer() '子弹方向处理
P.DrawWidth = 15
P.Cls
P.PSet (a, b), vbBlue
P.DrawWidth = 2
If check = 1 Then
P.Line (m, n)-(m - 0.2, n), vbRed
m = m - 0.2
End If
If check = 2 Then
P.Line (m, n)-(m + 0.2, n), vbRed
m = m + 0.2
End If
If check = 3 Then
P.Line (m, n)-(m, n + 0.2), vbRed
n = n + 0.2
End If
If check = 4 Then
P.Line (m, n)-(m, n - 0.2), vbRed
n = n - 0.2
End If
If m <= -9.8 Or m >= 9.8 Or n <= -9.8 Or n >= 9.8 Then ‘子弹越界的话,给坦克重装子弹,还原发射位置
m = 0
n = 0
boom = 0
P.Cls
P.DrawWidth = 15
P.PSet (a, b), vbBlue
Timer1.Enabled = False
End If
End Sub
[[it] 本帖最后由 我是菜鸟哦 于 2008-10-8 20:47 编辑 [/it]]
模拟坦克动画处理.rar
(2.17 KB)