is there a way to have one array of bullets wrok for 2 different guns? like use a function or something?
1 array for 2 guns?
Blitz3D Forums/Blitz3D Beginners Area/1 array for 2 guns? Hi, tbh your going to be better off looking at using Types for this type of stuff.
ok, where can I find a good tutorial on types? I'm not that good with them, hard to understand...
Look through the tutorial above, And also do some forum searches, And you will find tons of info on types.
Here are some basics:
First, you need To set it up like this.
What I have done there is To create a type called "bullet" and within that type there are two variables. (X_position, Y_position)
Now when you are ready to create a type, you do this.
b.bullet = new bullet
This creates a new bullet type with the name "b". The actual name used is not that important as you will see in a little bit.
Now we need to assign values to the fields.
b\X_position = mouseX()
b\Y_position = mouseY()
What I have done there is assign the bullet position to the mouse coordinates on the screen.
to delete this type, you do this.
delete b
Here is a small example of how you can use these. This is in 2d to keep the code as small and simple as possible.
Here are some basics:
First, you need To set it up like this.
Type Bullet Field X_position Field Y_position End Type
What I have done there is To create a type called "bullet" and within that type there are two variables. (X_position, Y_position)
Now when you are ready to create a type, you do this.
b.bullet = new bullet
This creates a new bullet type with the name "b". The actual name used is not that important as you will see in a little bit.
Now we need to assign values to the fields.
b\X_position = mouseX()
b\Y_position = mouseY()
What I have done there is assign the bullet position to the mouse coordinates on the screen.
to delete this type, you do this.
delete b
Here is a small example of how you can use these. This is in 2d to keep the code as small and simple as possible.
Graphics 640,480,0,2 SetBuffer BackBuffer() Type Bullet Field X_position Field Y_position End Type While Not KeyHit(1) ; loop until esc key is hit If MouseHit(1) ; if the mouse button 1 is clicked, create a bullet and place it at the mouse postion b.bullet = New bullet b\X_position = MouseX() b\Y_position = MouseY() EndIf For b.bullet = Each bullet ;loop through all bullets Plot b\X_position,b\Y_position ;draw a dot on the screen at the bullet position b\Y_position = b\Y_position -5 ;move the dot up the screen 5 pixels If b\Y_position < 50 Text b\x_position,b\y_position,"/*" ,1 Delete b ;delete the bullet when it reaches 50 in the X EndIf Next Flip Cls Wend ; end main loop End ;end program
very good tutorial Mortiis:)
Very nice. That's one of the best I've seen.
Thanks Pongo and Mortiis, I'll look into these! thanks for your help guys! :)