title: VB6 pixel based object control Collision Detection
body: <p>Currently, I'm trying to make a simple platformer in VB6 and I'm drawing objects onto the WinForm using BitBlt. I can program rectangular, circular, and line collisions but I want to have pixel-based collision detection.</p>
  <p>I assume this can be done with Windows GDI APIs, like MaskBlt, StretchBlt, BitBlt, PltBlt... etc, but I can't get my head around how this would work out.</p>
  <p>This is my current VB code for the form:</p>
  <p>I currently have 2 PictureBox controls (one for player sprite, one for mask) and one timer control, and another PictureBox which is an obstacle.</p>
  <pre class="lang-vb prettyprint-override"><code>Option Explicit
  
  Dim Keys(255) As Boolean
  
  Dim Player As PlayerPos
  
  Private Type PlayerPos
      x As Integer
      y As Integer
  End Type
  
  Private Declare Function BitBlt Lib &quot;gdi32&quot; (ByVal hDestDC As Long, ByVal x As Long, ByVal y As Long, ByVal nWidth As Long, ByVal nHeight As Long, ByVal hSrcDC As Long, ByVal xSrc As Long, ByVal ySrc As Long, ByVal dwRop As Long) As Long
  
  Private Sub Form_KeyDown(KeyCode As Integer, Shift As Integer)
      Keys(KeyCode) = True
  End Sub
  
  Private Sub Form_KeyUp(KeyCode As Integer, Shift As Integer)
      Keys(KeyCode) = False
  End Sub
  
  Private Sub timTick_Timer()
      Cls
      ' Draw collision obj
      BitBlt Me.hDC, 100, 100, pic3.Width \ 15, pic3.Height \ 15, pic3.hDC, 0, 0, vbSrcAnd
      BitBlt Me.hDC, 100, 100, pic3.Width \ 15, pic3.Height \ 15, pic3.hDC, 0, 0, vbSrcPaint
      ' End Draw
      With Player
          Dim Result(0 To 2) As Integer
          If Keys(vbKeyUp) Then .y = .y - 5
          If Keys(vbKeyDown) Then .y = .y + 5
          If Keys(vbKeyRight) Then .x = .x + 5
          If Keys(vbKeyLeft) Then .x = .x - 5
          ' Draw player
          Result(0) = BitBlt(Me.hDC, .x, .y, pic1.Width \ 15, pic1.Height \ 15, pic1.hDC, 0, 0, vbSrcAnd)
          Result(1) = BitBlt(Me.hDC, .x, .y, pic1.Width \ 15, pic1.Height \ 15, pic1Mask.hDC, 0, 0, vbSrcPaint)
          Result(2) = BitBlt(Me.hDC, .x, .y, pic1.Width \ 15, pic1.Height \ 15, pic1.hDC, 0, 0, vbSrcAnd)
          ' End Draw
          lblTest.Caption = Result(0) &amp; Result(1) &amp; Result(2)
      End With
      Me.Refresh
  End Sub
  </code></pre>
  <p>Thanks in advance!</p>