0

我正在尝试制作一个类似于 iCopter 的游戏,在那里你可以控制一个物体并引导它穿过移动的障碍物。

所以我在 Fireworks 中制作了一个简单的 png,它只是山脉,我想将它添加到 VB,这样如果对象接触到 PNG 的一部分(不是 Picturebox,因为那会破坏目的),它将结束游戏。

因此,主要问题是如何让 VB 识别没有图片框的 PNG(如果可能的话)......

谢谢

截屏

我不断地离开背景的运动,我可以移动汽车,但是我想产生碰撞,这将很难看到,因为它会与更大的图片框,而不是里面的实际图像......


新代码/工作

Public Class Form1
Dim upc, leftc, rightc, downc As Boolean
Dim speedofblocks As Integer = 5
Dim speedofguy As Integer = 6
Dim standing As Boolean
Dim blocks(1) As PictureBox
Dim floor(1) As PictureBox


    If e.KeyCode = Keys.Left Then

        leftc = True
        PictureBox1.BackgroundImage = My.Resources.guy1
    End If

    If e.KeyCode = Keys.Right Then
        rightc = True
        PictureBox1.BackgroundImage = My.Resources.guy1
    End If

    If e.KeyCode = Keys.Up Then
        upc = True
        PictureBox1.BackgroundImage = My.Resources.guy1
    End If
    If e.KeyCode = Keys.Down Then
        downc = True
        PictureBox1.BackgroundImage = My.Resources.guy1
    End If






    If e.KeyCode = Keys.Left Then

        leftc = False


    End If

    If e.KeyCode = Keys.Right Then
        rightc = False
    End If

    If e.KeyCode = Keys.Up Then
        upc = False
    End If
    If e.KeyCode = Keys.Down Then
        downc = False
    End If
End Sub

    PictureBox1.BackgroundImage = My.Resources.GUystand
    blocks(1) = PictureBox1
    blocks(1) = PictureBox2
    blocks(1) = PictureBox3
    blocks(1) = PictureBox4
    blocks(1) = PictureBox5
    blocks(1) = PictureBox6
    blocks(1) = PictureBox7
    blocks(1) = PictureBox8
    blocks(1) = PictureBox3
    blocks(1) = PictureBox10
    blocks(1) = PictureBox11
    blocks(1) = PictureBox12
    blocks(1) = PictureBox13
    blocks(1) = PictureBox14
    blocks(1) = PictureBox15
    blocks(1) = PictureBox16
    blocks(1) = PictureBox17
    blocks(1) = PictureBox18
    blocks(1) = PictureBox19
    blocks(1) = PictureBox20
    blocks(1) = PictureBox21
    blocks(1) = PictureBox22
    blocks(1) = PictureBox23
    blocks(1) = PictureBox24
    blocks(1) = PictureBox25
    blocks(1) = PictureBox26
    blocks(1) = PictureBox27
    blocks(1) = PictureBox28
    blocks(1) = PictureBox29
    blocks(1) = PictureBox30
    blocks(1) = PictureBox31
    blocks(1) = PictureBox32
    blocks(1) = PictureBox33
    blocks(1) = PictureBox34
    blocks(1) = PictureBox35
    blocks(1) = PictureBox36
    blocks(1) = PictureBox37
    blocks(1) = PictureBox38
    blocks(1) = PictureBox39
    blocks(1) = PictureBox40
    blocks(1) = PictureBox41
    blocks(1) = PictureBox42
    blocks(1) = PictureBox43
    blocks(1) = PictureBox44
    blocks(1) = PictureBox45
    blocks(1) = PictureBox46
    blocks(1) = PictureBox47
    blocks(1) = PictureBox48
    blocks(1) = PictureBox49

    floor(1) = picturebox50


End Sub




    If leftc = True Then
        PictureBox1.Left -= speedofguy
        PictureBox1.BackgroundImage = My.Resources.guy1
    End If
    If rightc = True Then
        PictureBox1.Left += speedofguy
        PictureBox1.BackgroundImage = My.Resources.guy1
    End If
    If upc = True Then
        PictureBox1.Top -= speedofguy
        PictureBox1.BackgroundImage = My.Resources.guy1
    End If

    If downc = True Then
        PictureBox1.Top += speedofguy
        PictureBox1.BackgroundImage = My.Resources.guy1
    End If



Private Sub Timer1_Tick(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Timer1.Tick
    PictureBox2.Left -= speedofblocks
    PictureBox3.Left -= speedofblocks
    PictureBox4.Left -= speedofblocks
    PictureBox5.Left -= speedofblocks
    PictureBox6.Left -= speedofblocks
    PictureBox7.Left -= speedofblocks
    PictureBox8.Left -= speedofblocks
    PictureBox9.Left -= speedofblocks
    PictureBox10.Left -= speedofblocks
    PictureBox11.Left -= speedofblocks
    PictureBox12.Left -= speedofblocks
    PictureBox13.Left -= speedofblocks
    PictureBox14.Left -= speedofblocks
    PictureBox15.Left -= speedofblocks
    PictureBox16.Left -= speedofblocks
    PictureBox17.Left -= speedofblocks
    PictureBox18.Left -= speedofblocks
    PictureBox19.Left -= speedofblocks
    PictureBox20.Left -= speedofblocks
    PictureBox21.Left -= speedofblocks
    PictureBox22.Left -= speedofblocks
    PictureBox23.Left -= speedofblocks
    PictureBox24.Left -= speedofblocks
    PictureBox25.Left -= speedofblocks
    PictureBox26.Left -= speedofblocks
    PictureBox27.Left -= speedofblocks
    PictureBox28.Left -= speedofblocks
    PictureBox29.Left -= speedofblocks
    PictureBox30.Left -= speedofblocks
    PictureBox31.Left -= speedofblocks
    PictureBox32.Left -= speedofblocks
    PictureBox33.Left -= speedofblocks
    PictureBox34.Left -= speedofblocks
    PictureBox35.Left -= speedofblocks
    PictureBox36.Left -= speedofblocks
    PictureBox37.Left -= speedofblocks
    PictureBox38.Left -= speedofblocks
    PictureBox39.Left -= speedofblocks
    PictureBox40.Left -= speedofblocks
    PictureBox41.Left -= speedofblocks
    PictureBox42.Left -= speedofblocks
    PictureBox43.Left -= speedofblocks
    PictureBox44.Left -= speedofblocks

    PictureBox45.Left -= speedofblocks
    PictureBox46.Left -= speedofblocks
    PictureBox47.Left -= speedofblocks
    PictureBox48.Left -= speedofblocks
    PictureBox49.Left -= speedofblocks




End Sub

Private Sub Gravity_Tick(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Gravity.Tick
    PictureBox1.Top += 3

    For x As Integer = 1 To 49

        If PictureBox1.Bounds.IntersectsWith(floor(x).Bounds) And floor(x).Visible = True Then
            standing = True
            PictureBox1.Top -= 3
        End If

        If PictureBox1.Bounds.IntersectsWith(blocks(x).Bounds) And blocks(x).Visible = True Then
            standing = True
            PictureBox1.Top -= 3
        End If

    Next x

End Sub

我很确定我搞砸了数组,以及 Bounds.Intersectswith.. 等。基本上试图获得一些基本的碰撞和重力。我制作了一堆图片框,它们都是向左滚动的黑色方块,然后我希望玩家跳过它们。

4

1 回答 1

2

正如其他人所说,Winforms 并不是最适合游戏的,它针对数据输入和静态窗口进行了更多优化。也就是说,PictureBox 控件只是将图像绘制到屏幕上的控件。您想要做的是覆盖控件/表单的默认呈现,以便您可以自己完成所有绘图。请参阅下面的链接开始。

http://msdn.microsoft.com/en-us/library/b818z6z6.aspx

于 2012-12-04T14:29:23.833 回答