VB2008拋物線碰撞偵測問題

Home Home
引用 | 編輯 za08280714
2011-11-13 17:22
樓主
推文 x0
請問各位大大..PictureBox1碰撞偵測PictureBox2程式裡的拋物線的碰撞偵測都沒有反應.請問是程式碼哪邊有錯誤碰撞偵測我是放在Timer1_Tick這裡.是位置放錯還是拋物線的碰撞偵測不能用那種碰撞偵測方式.


Public Class Form1

    '---------- Local structures ----------

    'Positions [位置的變數]
    Structure struc_pos
        Dim x, y As Integer 'Current position [目前的 x,y]
        Dim ini_x, ini_y As Integer 'Initial position [拋物線參考的最初 x,y,就是物理中表示的 x0,y0]
        Dim ang As Single 'Current angle [目前的角度,為碰撞時可轉換]
        Dim vx, vy As Single 'Current velocity [目前的速度分量]
        Dim ini_vx, ini_vy As Single 'Initial velocity [一開始的 速度分量,就是物理中表示的 vx0,vy0]
        Dim ini_v As Single 'Initial velocity [一開始的速度]
        Dim g As Single  'Gravity constant [重力常數]
    End Structure

    '---------- Local constants ----------

    'Initial positions
    Const user_ini_v As Single = 90 '[設定一開始的速度(可調整)]
    Const user_ini_x As Integer = 50, user_ini_y As Integer = 500 '[圖片一開始的座標(可調整)]

    '---------- Local variables ----------

    'Graphics [繪圖]
    Dim g As System.Drawing.Graphics
    Dim dstRect, srcRect As Rectangle

    'List [清單]
    Dim listPic As New List(Of Image) 'List of picture
    Dim listAng As New List(Of Integer) 'List of angle

    'Collection [集合]
    Dim collRep As New Collection

    'Positions [宣告座標的巢狀結構]
    Dim pos As struc_pos

    'Flags [旗標]
    Dim stat_moving As Integer 'Status (Pausing->0, Moving->1) [紀錄是否在移動]
    Dim stat_ang, max_ang As Integer 'Angle [角度(DEG),與最大值]
    Dim passedTime, multiTi As Single 'Time [已經過時間,與時間加倍量]

    'Help texts
    Const hlp_1 As String = "(1) 按 ""上"",""下"" 切換角度" & vbNewLine & "(2) 按 ""空白鍵"" 開始發射/停止" & vbNewLine & vbNewLine & "當物體碰撞到底下邊緣才會消失"


    Private Sub Form1_KeyDown(ByVal sender As Object, ByVal e As System.Windows.Forms.KeyEventArgs) Handles Me.KeyDown

        local_kc_dir(e.KeyCode)

    End Sub

    Private Sub Form1_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load

        Dim i As Integer

        '--- Variables ---

        'Position
        With pos
            .g = 9.8
            .ini_v = user_ini_v
        End With

        'Status
        stat_moving = 0
        stat_ang = 6 '[設定一開始是第三張圖片,30度的]

        'Time
        multiTi = 15 '[時間加倍量,太低圖片會跑很慢]

        '--- List of Images ---
        '[讀取圖片,並讀取角度值]
        max_ang = -1
        For i = 0 To 360 Step 15
            listPic.Add(Image.FromFile("00_" & i & ".gif"))
            listAng.Add(i)
            max_ang += 1
        Next

        '--- Obj. ---

        'PictureBox1
        local_renew_resetpic()
        PictureBox1.Visible = False

        'Timer1
        Timer1.Interval = 50

        '--- Sub ---
        local_change_pic()

    End Sub

    Private Sub Form1_Paint(ByVal sender As System.Object, ByVal e As System.Windows.Forms.PaintEventArgs) Handles MyBase.Paint

        dstRect = Me.ClientRectangle
        srcRect = dstRect

        g = e.Graphics

        '--- Picture ---
        dstRect = New Rectangle(New Point(pos.x, pos.y), PictureBox1.Size)

        g.DrawImage(PictureBox1.Image, dstRect, srcRect, GraphicsUnit.Pixe ..

訪客只能看到部份內容,免費 加入會員



獻花 x0
引用 | 編輯 Freelife
2011-11-15 11:18
1樓
  
PictureBox1.Location = New Point(pos.ini_x, pos.ini_y)

這一行取到的值都一樣,後續的動作就不會有效果囉。

獻花 x0
引用 | 編輯 za08280714
2011-11-15 16:24
2樓
  
請問大大那要如何修改才能有碰撞偵測

獻花 x0
引用 | 編輯 61039100
2011-12-28 14:24
3樓
  
回 覆 鎖 定 :

  此回覆已被鎖定,只有『管理員及回覆者』看的到 !!!



獻花 x0