碰撞检测原理是检测控件是否在主角位置范围内。
你可以通过检测位置实现啊,比如用这个函数:
'碰撞检测
Public Function IsCollision(x1 As Long, y1 As Long, w1 As Long, h1 As Long, x2 As Long, y2 As Long, w2 As Long, h2 As Long) As Boolean
If y2 + h2 >= y1 And y2 <= y1 + h1 And x2 + w2 >= x1 And x2 <= x1 + w1 Then IsCollision = True
End Function
'使用: 分别设定主角的left, top, width, height 和控件的 left, top, width, height
'碰撞时返回真
'可以放在Timer里循环检测
MsgBox IsCollision(pic1.Left, pic1.Top, pic1.Width, pic1.Height, pic2.Left, pic2.Top, pic2.Width, pic2.Height)
Copyright © 2024 冲浪手游网 滇ICP备2024020316号-78