I originally typed this to help out hellninjas, but I decided to give it to you since I already took the time to type it :P
This is actually longer than the one I gave him.
My setup is when a bullet's tasks are done, the bullet check changes. For example,
When the bullet check = 0
That means a new bullet is ready to be shot
When the bullet check = 1
That means the bullet's coordinates and left/right need to be set.
When the bullet check = 2
That means to move the bullet.
Now, to start the real programming.
Pick a variable for your for loops. I used V.
Pick L1, or L2, or L3, etc. I used L5.
Im taking this mostly from my game. These bullets will be shooting left and right, not up and down, so if that's what your game needs, you will have to tweak this code.
Outside the main loop,
:.The sprite.
:[FCFC000000000000]-> Pic2
:For(V,0,5)
:0->{V*4+L5}
:End
In my for loop, I put 5 there to say what the max possible bullets on the screen would be.
{V*4+L5} will be my bullet check. That sets the bullet check to zero.
As you can see by what I previously wrote, when the bullet check is zero, it means the bullet is ready to be fired.
:25->S->T
Actually, this also checks if a bullet to be fired. If only {V*4+L5} the only check, they would all fire at once. S and T will be what spaces the bullets. T will gain 1 every time the loop finishes and when it reaches S, which is set to 25, a bullet will be ready to be fired.
So together {V*4+L5} and S/T are what checks if a bullet can be fired. If you'd like to make it shoot faster, lower S and T. But where it says
For(V,0,5)
If you speed the bullets up you'll have to increase the 5 so that L5 wont run out of bullets!
:Repeat getkey(15)
:If getKey(54)
:For(V,0,5)
:If T=S
:.Checks if T=S so that the bullets are spaced out
:!If {V*4+L5}
:.If the bullet check is 0...
Above, I have the calculator find a bullet that is ready to be fired.
Now that we found a bullet, you have to change the bullet check to 1 and reset the spacer.
:.Change bullet check
:1->{V*4+L5}
:.Turns T back to 0 and it will have to go back up to 25 (S) to fire again
:0->T
:.Exits this loop now since we already have our bullet
:Goto X
:End
:End
:End
:End
:Lbl X
As I said before, when the bullet check is 1 it means the bullet's coordinates and left/right need to be set.
:For(V,0,5)
:If {V*4+L5}=1
:.If bullet check = 1
:.Set the coordnates of the player to the bullet
:X->{V*4+L5+1}
:Y->{V*4+L5+2}
:.Put it on the screen
:Pt-On({V*4+L5+1},{V*4+L5+2},Pic2
:.Turn on the bullet check to 2 now.
:2->{V*4+L5}
:.You should have a variable that tells if the character is left or right. Save that to the bullet like as shown here
:R->{V*4+L5+3}
:End
:End
If you dont have a variable that says if the character is facing left or right, add one!
Also where I have said
X->{V*4+L5+1}
Y->{V*4+L5+2}
Tweak that to exactly where you want the bullet to start, or it'll just start at the top left of your player.
Here, this will move the bullet, which is when the bullet check equals 2.
:For(V,0,5)
:If {V*4+L5}=2
:.Checks if the bullet check is 2...
:If {V*4+L5+3}
:.If facing right..
:{V*4+L5+1}+2->{V*4+L5+1}
:Else
:.If its not,
:{V*4+L5+1}-2->{V*4+L5+1}
:End
:.Show the bullet
:Pt-On({V*4+L5+1},{V*4+L5+2},Pic2)
:End
:End
Here, I have what checks if the bullet is off the screen and then resets the bullet.
:For(V,0,5)
:If {V*4+L5+1}>90
:.If the bullet is off the screen (Works for both left and right side)
:.Set the bullet checks back to zero and put the coordnates off the screen to not interfere
:0->{V*4+L5}+100->{V*5+L5+1}->{V*5+L5+2}
:.Now the bullet check is back to zero to start the cycle over again.
:Return
:End
:End
Don't forget to make T change so that bullet spacing will work!
:.Make T move up to S for the bullet spacing
:If T < S
:T++
:End
And that's it for bullet moving. Here's some collisions now!
In this example, A and B are the enemy's X and Y coordinates.
:For(V,0,5)
:.Collision detect
:If abs({V*4+L5+1}-A)<6
:If abs({V*4+L5+2}-B)<6
:. I'll use C for the enemy's health
:C--
:0->{V*4+L5}+100->{V*5+L5+1}->{V*5+L5+2}
:. The same thing as before, to reset the bullet
:End
:End
:End
It's the same idea for multiple enemies
Here, P and L1 are for the enemies and
{P*2+L1) = X coordinate
{P*2+L1+1) = Y coordinate
:For(V,0,5)
:For(P,0,3)
:. Has to check a For( for the enemies and the bullets
:. Collision detect
If abs({V*4+L5+1}-{P*2+L1})<6
If abs({V*4+L5+2}-{P*2+L1+1})<6
:. I'll use P+L2 as the enemy's health
:{P+L2}--
:. Remove one from the health
:0->{V*4+L5}+100->{V*5+L5+1}->{V*5+L5+2}
:. Bullet reset
End
End
End
End
End
OK! Now here's the whole code.
The only thing it's missing is the player.
Add the player and you'll be good to go!
Dont forget to tweak
X->{V*4+L5+1}
Y->{V*4+L5+2}
:[FCFC000000000000]->Pic2
:For(V,0,5)
:0->{V*4+L5}
:End
:25->S->T
:Repeat getkey(15)
:ClrDraw
:If getKey(54)
:For(V,0,5)
:If T=S
:!If {V*4+L5}
:1->{V*4+L5}
:0->T
:Goto X
:End
:End
:End
:End
:Lbl X
:For(V,0,5)
:If {V*4+L5}=1
:X->{V*4+L5+1}
:Y->{V*4+L5+2}
:Pt-On({V*4+L5+1},{V*4+L5+2},Pic2
:2->{V*4+L5}
:R->{V*4+L5+3}
:End
:End
:For(V,0,5)
:If {V*4+L5}=2
:If {V*4+L5+3}
:{V*4+L5+1}+2->{V*4+L5+1}
:Else
:{V*4+L5+1}-2->{V*4+L5+1}
:End
:Pt-On({V*4+L5+1},{V*4+L5+2},Pic2
:End
:End
:For(V,0,5)
:If {V*4+L5+1}>90
:0->{V*4+L5}+100->{V*5+L5+1}->{V*5+L5+2}
:Return
:End
:End
:If T < S
:T++
:End
:For(V,0,5)
:For(P,0,3)
If abs({V*4+L5+1}-{P*2+L1})<6
If abs({V*4+L5+2}-{P*2+L1+1})<6
:{P+L2}--
:0->{V*4+L5}+100->{V*5+L5+1}->{V*5+L5+2}
End
End
End
End
End
DispGraph
End