PDA

Click to See Complete Forum and Search --> : Bullets...and the great VBWorld format...:)


Spie
Apr 9th, 2001, 10:00 PM
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?:)

Sastraxi
Apr 10th, 2001, 02:42 PM
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.

bff
Apr 11th, 2001, 04:53 PM
I have the same question as the original post but sasx can you simplify what you meant

Sastraxi
Apr 11th, 2001, 05:25 PM
Sure, this is what I meant:

What you have to do is have an array of X and Y values.
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.

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:


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 :D), 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.

bff
Apr 12th, 2001, 02:45 PM
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

Sastraxi
Apr 12th, 2001, 04:18 PM
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