兄弟集美们这么写picturebox 两两相互碰撞的事件呀
vb吧
全部回复
仅看楼主
level 1
有五个picturebox 该怎么写条件呢
2020年06月22日 07点06分 1
level 7
坐标和宽高。逐一比对
2020年06月22日 13点06分 3
呜呜呜大佬我不会 可不可以加个微信帮我改一下
2020年06月24日 06点06分
就一个很简单的小游戏
2020年06月24日 07点06分
我图已经发在下面啦 麻烦帮我看一下 谢谢了[泪]
2020年06月24日 07点06分
不好意思,好久没来看了
2020年11月03日 19点11分
level 1
就是这个 判断他们四个炸弹跟超人的位置碰撞 四个炸弹分别为picturebox2.....5 超人是picturebox1
2020年06月24日 07点06分 4
[泪]
2020年06月24日 07点06分
@甜进了心头 平时炸弹会不会自己动?超人呢?
2020年06月25日 03点06分
@抠脽酝jq87 炸弹会随机动 超人就通过上下左右案件动
2020年06月25日 05点06分
@甜进了心头 哦简单
2020年06月25日 07点06分
level 15
可以用如下函数判断两个PictureBox是否重合:
Private Function Collision(picA As PictureBox, picB As PictureBox) As Boolean
Dim LeftA As Single, LeftB As Single
Dim RightA As Single, RightB As Single
Dim TopA As Single, TopB As Single
Dim BottomA As Single, BottomB As Single
LeftA = picA.Left: LeftB = picB.Left
RightA = picA.Left + picA.Width: RightB = picB.Left + picB.Width
TopA = picA.Top: TopB = picB.Top
BottomA = picA.Top + picA.Height: BottomB = picB.Top + picB.Height
Collision = (RightA - LeftB) * (RightB - LeftA) > 0 And (BottomA - TopB) * (BottomB - TopA) > 0
End Function
2020年06月24日 07点06分 5
[泪]能不能详细点 我还是看不懂 就按照我那个图上的来
2020年06月24日 08点06分
@甜进了心头 我这是个一般性的代码,适用于任何需要判断图片框是否碰撞的场合,包括你这里的场合;使用方法:在If语句中这样写条件,如Collision(PictureBox1, PictureBox2),就表示判断1和2是否发生碰撞
2020年06月24日 08点06分
@甜进了心头 另外看你的图片,你用的是VB.net么?那么我的代码可能需要做一些修改,或者可能有可以优化的地方,具体修改方法我就不清楚了
2020年06月24日 08点06分
@初音✨七奈 我这个是microsoft visual 2010的[开心]
2020年06月24日 09点06分
level 1
有没有好心人 再救救我
2020年06月24日 09点06分 6
.net是直接封装了gdiplus的,可以设置一个给超人和四个炸弹分别设置一个region,有方法可以直接判断两个region是否有交集,也就是说是否碰撞,明白了吗?
2020年06月24日 13点06分
level 1
[泪]
2020年06月24日 12点06分 7
level 10
'很简单的吧。
'把怪物图片的picturebox 命名为怪兽的数组控件
'把超人图片的picturebox 命名为超人
Private Type 位置
x As Single
y As Single
End Type
Sub 检查碰撞(超人 As Control)
Dim a As Control
Dim 超人位置 As 位置, 怪兽位置 As 位置
With 超人位置
.x = 超人.Left
.y = 超人.Top
End With
For Each a In Me.Controls
If a.Name = "怪兽" Then
With 怪兽位置
.x = a.Left
.y = a.Top
End With
If Abs(超人位置.x - 怪兽位置.x) <= a.Height And Abs(超人位置.y - 怪兽位置.y) <= a.Width Then
Print a.Index & "号怪兽和超人撞了"
End If
End If
Next
End Sub
Private Sub Timer1_Timer()
'增加怪物随机移动的代码
检查碰撞 超人
End Sub
2020年06月24日 17点06分 9
谢谢你! 就是我在下面发图了 你帮我看看错误[泪] 十分感谢十分感谢
2020年06月25日 05点06分
level 11
5、6楼都给了你代码和思路。
如你图片所述,以vb6为基础,假设人图片是p0,地雷图片分别是p1~p4,
先写两个自定义函数,随机移动函数和碰撞函数,调用例如:
1:yd(p1),yd(p2),yd(p3),yd(p4),令四张地雷图片随机移动:
2:pz(p0,p1),pz(p0,p2),pz(p0,p3),pz(p0,p4),分别判断人碰撞到地雷
A:移动函数和生存时间放在时钟控件里。
B:碰撞函数放在键盘(或鼠标)事件中进行真假判断。(if pz(p0,p1) then msgbox"游戏结束":exit sub)
C:开始游戏按钮只是控制时钟事件的启动。(timer1.enabled=true)
鉴于你是其它程序代码,就不强求人家给你敲代码了,以免浪费广大回友的感情。
2020年06月25日 03点06分 10
炸弹的随机移动函数已经弄好了了 就碰撞函数不知道该怎么敲出来
2020年06月25日 04点06分
level 1
2020年06月25日 05点06分 11
这个代码用了控件数组,VB.net没有控件数组,不能用这个代码
2020年06月25日 05点06分
成! 那我就改掉复制粘贴你那个
2020年06月25日 06点06分
level 1
2020年06月25日 05点06分 12
level 8
咳,还是给你代码吧,.net下的碰撞检测没这么复杂,因为它集成了gdiplus
Dim region1 As Region = New Region(New Rectangle(PictureBox1.Left, PictureBox1.Top, PictureBox1.Width, PictureBox1.Height))
Dim region2 As Region = New Region(New Rectangle(PictureBox2.Left, PictureBox2.Top, PictureBox2.Width, PictureBox2.Height))
region1.Intersect(region2)
MsgBox(region1.IsEmpty(Me.CreateGraphics()))
用picturebox1和picturebox2的位置建立两个region,然后得到region的交集,交集为空就是没碰撞,不为空就碰撞了,就这么简单
2020年06月25日 06点06分 13
谢谢! 我直接复制粘贴了[钱] 但是出错了呀 我听不懂因为我没学过这个[泪]
2020年06月25日 06点06分
系统说那个msgbox跟region1.应为声明是啥意思
2020年06月25日 06点06分
level 1
2020年06月25日 06点06分 14
level 1
2020年06月25日 07点06分 15
是这样吗
2020年06月25日 07点06分
调试启动之后两个碰在一起还是没反应耶
2020年06月25日 07点06分
那个picturebox是超人?
2020年06月25日 07点06分
picturebox1 是超人 其他2-5是炸弹
2020年06月25日 07点06分
level 8
Private Function hitTest(ByVal region2 As Region) As Boolean
Dim region As Region = New Region(New Rectangle(超人.left, 超人.top, 超人.width, 超人.height))
Dim r As Boolean
region.Intersect(region2)
r = Not region.IsEmpty(Me.CreateGraphics)
region.Dispose()
region = Nothing
Return r
End Function
Private Function 碰撞() As Boolean
Dim region1 As Region = New Region(New Rectangle(炸弹1.left, 炸弹1.top, 炸弹1.width, 炸弹1.height))
Dim region2 As Region = New Region(New Rectangle(炸弹2.left, 炸弹2.top, 炸弹2.width, 炸弹2.height))
'下面几个炸弹自己写
Dim r As Boolean
r = hitTest(region1) And hitTest(region2) And hitTest(region3) And hitTest(region4)
'region3,region4自己写
region1.Dispose()
region2.Dispose()
region3.Dispose()
region4.Dispose()
Return r
End Function
'然后你在某个timer下写
if 碰撞()=true Then
'这里写碰撞了你要干嘛
end if
2020年06月25日 07点06分 17
谢谢大哥!那我刚才写的是不是要删掉呀 就是上面发的那个
2020年06月25日 07点06分
@甜进了心头 都按你的来了为什么碰撞的时候还是没有触发东西[泪]
2020年06月25日 07点06分
@甜进了心头 timer1.enable=true怎么自己触发自己?放外面去
2020年06月25日 08点06分
@mijing2000 放了!还是没有反应[怒]
2020年06月25日 08点06分
1 2 尾页