我正在制作一款太空侵略者风格的射击游戏,其中外星人在运行时生成并放置在随机位置。我试图让玩家的激光灯和外星人之间的碰撞起作用,但问题是我无法确定哪个外星人被击中。
在这样的循环中声明外星人:
spawncount = 20
Do Until spawncount = 0
spawncount = spawncount - 1
spawnID = spawnID + 1 //This is initialized as zero in separate code
alien = New PictureBox
With alien
.Name = "Alien" & Str(spawnID)
//location, image, etc.
Next
End With
Controls.Add(alien)
Loop
在计时器中,我有这段代码可以检查是否有任何玩家激光器(.tag属性为“ L1”)与外星人相撞:
Dim number As Integer = 0
For Each picturebox In Controls
If picturebox.tag = "L1" Then
Do Until spawnID = (19 + level)
spawnID = spawnID + 1
If picturebox.bounds.intersectswith((alien & number).Bounds) Then
//Code to be executed when a collision occurs
Exit For
End If
Loop
End If
Next
If picturebox.bounds.intersectswith((alien & number).Bounds)
部分出现错误。它说:“未为类型'Picturebox'和'Integer'定义运算符'&'”
是否有替代方法或替代方法?还是我只是在If语句中没有正确的格式?