重力与碰撞 - 简单的VB游戏

时间:2012-12-04 13:51:47

标签: vb.net

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

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

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

由于

ScreenShot

我有背景的动作不断离开,我可以移动汽车,但我想创造碰撞,这将是困难的seing,因为它将与更大的图片框,而不是内部的实际图像...


新规范/工作

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 ..等基本上试图获得一些基本的碰撞和重力。我制作了一堆图片框,这些图片框都是向左滚动的黑色块,然后我希望玩家跳过它们。

1 个答案:

答案 0 :(得分:2)

正如其他人所说,Winforms不是游戏的最佳选择,它针对数据输入和静态窗口进行了优化。话虽这么说,PictureBox控件只是一个将图像绘制到屏幕的控件。您想要做的是覆盖控件/表单的默认呈现,以便您可以自己完成所有绘图。请参阅以下链接以获取开始。

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