Results 1 to 7 of 7

Thread: What's wrong with this code? [SOLVED]

Threaded View

  1. #1

    Thread Starter
    Fanatic Member hothead's Avatar
    Join Date
    Mar 2002
    Location
    Missouri
    Posts
    692

    What's wrong with this code? [SOLVED]

    I have no problems getting the ball to wrap to the other side of the screen, but now I'm trying to get it to bounce like it does in a Breakout-type game. The code snippet below doesn't work, the ball just sticks to the bottom of the screen.

    NOTE: Right now I'm testing the code in a command button's click procedure inside a practice program, just to see if I can get it working.

    VB Code:
    1. Private Sub Command1_Click()
    2.     Dim T1 As Long, T2 As Long
    3.     myBackBuffer = CreateCompatibleDC(GetDC(0))
    4.     myBufferBMP = CreateCompatibleBitmap(GetDC(0), 320, 256)
    5.     SelectObject myBackBuffer, myBufferBMP
    6.     BitBlt myBackBuffer, 0, 0, 320, 256, 0, 0, 0, vbWhiteness
    7.     mySprite = LoadGraphicDC(App.Path & "\sprite1.bmp")
    8.     mySprite1 = LoadGraphicDC(App.Path & "\mask.bmp")
    9.     cmdTest.Enabled = False
    10.     T2 = GetTickCount
    11.     Do
    12.         DoEvents
    13.         T1 = GetTickCount
    14.         If (T1 - T2) >= 0.15 Then
    15.             BitBlt myBackBuffer, SpriteX - 1, SpriteY - 1, 32, 32, 0, 0, 0, vbBlackness
    16.             BitBlt myBackBuffer, SpriteX - 1, SpriteY - 1, 32, 32, 0, 0, 0, vbSrcAnd
    17.             BitBlt myBackBuffer, SpriteX, SpriteY, 32, 32, mySprite, 0, 0, vbSrcAnd
    18.             BitBlt myBackBuffer, SpriteX, SpriteY, 32, 32, mySprite1, 0, 0, vbSrcPaint
    19.             BitBlt Me.hdc, 0, 0, 320, 256, myBackBuffer, 0, 0, vbSrcCopy
    20.             SpriteX = SpriteX + 1
    21.             SpriteY = SpriteY + 1
    22.             T2 = GetTickCount
    23.         End If
    24.         If SpriteX = 320 Then
    25.             SpriteX = SpriteX - 1
    26.             SpriteY = SpriteY - 1
    27.         ElseIf SpriteY = 256 Then
    28.             SpriteX = SpriteX - 1
    29.             SpriteY = SpriteY - 1
    30.         End If
    31.     Loop
    32. End Sub

    The code works fine when I take it out of the If SpriteX = 320/If SpriteY = 256 statements, so it must be the correct code.
    Last edited by hothead; Oct 12th, 2003 at 07:10 PM.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width