Results 1 to 6 of 6

Thread: Bullets...and the great VBWorld format...:)

  1. #1

    Thread Starter
    Lively Member Spie's Avatar
    Join Date
    Jul 2000
    Location
    On a very small coconut somewhere near Mars
    Posts
    126
    wow! VBWorld has changed a lot...*admires the new format* Oh, sorry, I ment to ask you guys how to make a bullet. I just want a simple picture or a yellow dot or something to come out of my little ship in mass numbers...Aka, I want to be able to shoot a number of simple bullets at the same time. Like on the old asteroids. Any suggestions?
    . <--My coconut

    (o) <--My L33t Coconut

    http://www.megatokyo.com/

  2. #2
    Good Ol' Platypus Sastraxi's Avatar
    Join Date
    Jan 2000
    Location
    Ontario, Canada
    Posts
    5,134
    Whenever they fire a blast (using the mouse or key or whatever) add an index to an array, but PRESERVE IT. Then put in the X and Y values and loop from 0 to ubound(array) and put them on the screen.
    All contents of the above post that aren't somebody elses are mine, not the property of some media corporation.
    (Just a heads-up)

  3. #3
    Member
    Join Date
    Feb 2001
    Location
    The Littlest State in the Union
    Posts
    57

    Exclamation Huh

    I have the same question as the original post but sasx can you simplify what you meant
    Visual Basic 6.0 Enterprise Edition
    Java 2
    Windows 98
    Mac OS 9.1

  4. #4
    Good Ol' Platypus Sastraxi's Avatar
    Join Date
    Jan 2000
    Location
    Ontario, Canada
    Posts
    5,134
    Sure, this is what I meant:

    What you have to do is have an array of X and Y values.
    Code:
    Type PointAPI
       X as Single
       Y as Single
    End Type
    
    Type Inertia
       spX as Integer
       spY as Integer
       jX as Integer
       jY as Integer
    End Type
    
    Dim nBullets as Integer
    Dim Bullets() as PointAPI
    Dim btExtended() as Intertia
    Note: I also included the Intertia TYPE, nBullets, and btExtended() which will be needed later.

    The next thing to do is run a function when the user intervenes.
    Code:
    Private Sub Form_KeyDown(.... blah ....)
       If KeyCode = vbKeyA then FireBullet
    End Sub
    Now we have to make the sub! But first, you must have some things available:
    • X position of bullet origin
    • Y position of bullet origin
    • Speed of bullet in milliseconds (1 pixel every ?? ms) for X axis
    • Speed of bullet in Y axis like the X axis variable


    Lets say for a second that these values are stored in global variables orgX, orgY, XSpeed, YSpeed.

    Here is the subroutine:

    Code:
    Function FireBullet()
       nBullets = nBullets + 1
       Redim Preserve Bullets(1 to nBullets) as PointAPI
       Redim Preserve btExtended(1 to nBullets) as Inertia
       Bullets(nBullets).X = orgX
       Bullets(nBullets).Y = orgY
       btExtended(nBullets).spX = XSpeed
       btExtended(nBullets).spY = YSpeed
       btExtended(nBullets).jX = -1 'can be -1, 0, or 1, -1 goes left
       btExtended(nBullets).jY = -1 'same as above
    End Function
    In this function, the number of bullets is increased and the arrays are re-dimensioned. Then the values of the new bullet are set to the presets.

    Now we must find a way to draw the picture on the screen, I personally use DDraw but you may use BITBLT.

    That's all I can write for now (too lazy ), but certainly you can find out how to work it! Every spX milliseconds, add jX to X. Every spY milliseconds, add jY to Y. Then Int() the values for X and Y and blit them onto the screen.
    All contents of the above post that aren't somebody elses are mine, not the property of some media corporation.
    (Just a heads-up)

  5. #5
    Member
    Join Date
    Feb 2001
    Location
    The Littlest State in the Union
    Posts
    57

    Exclamation

    Sastraxi okay i have the array coded but Im not sure how i use the array w/ bitblt.

    private sub GameLoop

    Do while doevents
    if (getkeystate(vbkeyspace) and keydown) then
    firebullet
    ' Not sure how to go about the bitblt portion
    end if
    loop


    end sub

    if you could help it would be appreciated!

    -BFF
    Visual Basic 6.0 Enterprise Edition
    Java 2
    Windows 98
    Mac OS 9.1

  6. #6
    Good Ol' Platypus Sastraxi's Avatar
    Join Date
    Jan 2000
    Location
    Ontario, Canada
    Posts
    5,134
    BitBlt PicToBlitTo.hDC, Int(Array(?).X), Int(Array(?).Y), (width in pixels), (height in pixels), PicOfBullet.hDC, 0, 0, SRCCOPY

    I think that's how you do it, I may be wrong so check out my tutorial:

    http://vbden.tripod.com/articles/invmask.htm
    All contents of the above post that aren't somebody elses are mine, not the property of some media corporation.
    (Just a heads-up)

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