I'm assuming you're relatively new to DBC programming (hence the many rem statements in the code).
This first one is a simple shooting system:
rem First, we make our bullet objects - in this case, some simple cubes. Um... let's say 20 bullets
`(we hide the bullets right now because we only want them showing up when being fired)
For i = 1 to 20
Make Object Cube i,10
Hide Object i
Next i
rem Now let's make a very simple world (with some boxes for scenery)
Make Matrix 1,2500,2500,15,15
Make Object Box 100,50,200,50
Make Object Box 101,50,200,50
Make Object Box 102,50,200,50
Position Object 100,1250,100,1250
Position Object 101,750,100,1250
Position Object 102,750,100,750
rem Some variables (I'll explain these in the program itself)
currentBullet=1
Dim bulletLife(20)
ammo=1000
rem MAIN LOOP
SYNC ON : SYNC RATE 50 : DO
rem First, let's let the player do some simple camera movement using the mouse
If MouseClick()=2 Then Move Camera 10
XRotate Camera Wrapvalue(Camera Angle X()+MouseMoveY())
YRotate Camera Wrapvalue(Camera Angle Y()+MouseMoveX())
rem Now we handle the fun stuff - shooting! Let me tell you what's we want to happen here. First, we
rem want the player to be able to fire multiple bullets away from the camera at a certain speed. These bullets
rem should move out so that they come from the center of the camera position itself. Then we'll
rem want these bullets to "die off" eventually so that we can reuse them again - thus giving the impression that he's
rem able to fire continuously
`First, we've gotta check if the current bullet is "alive" or not i.e. if it has already been shot (in this program a value of 0 means dead and anything greater than 0 means alive)
`We've also gotta check if there's enough ammo left
If bulletLife(currentBullet)=0 and ammo>0
`If not, when player presses fire button (left mouse), then set the bulletLife to something, say 50, and increment currenBullet (that way the program will use the next bullet in
`line the next time). We also want the ammo variable to be reduced by one (obviously)
If MouseClick()=1 Then bulletLife(currentBullet)=50 : Inc currentBullet : Dec ammo
Endif
`Now, since any of the 20 bullets could be alive, we've gotta check *each* one's life value using (you guessed it right!) a for-next loop
For i = 1 to 20
`If the bullet (any one of the 20) is alive
If bulletLife(i)>0
`First show the bullet
Show Object i
`Make the bullet move straight ahead
Move Object i,20
`And decrement the life value so that it will ultimately die when bulletLife reaches 0
bulletLife(i)=bulletLife(i)-1
Endif
Next i
`Finally, we've gotta reset the position of the dead bullets to the camera's position and rotation so that it can be used properly again (otherwise the bullet will be fired from the last position it was when it was fired)
For i = 1 to 20
`If bullet is dead
If bulletLife(i)<=0
`Just in case the bulletLife slipped below zero, we wanna reset it to zero because otherwise that line "If bulletLife(currentbullet)=0" won't work
bulletLife(i)=0
`Hide the bullet object
Hide Object i
`Reposition and re-rotate the bullet to the cam's position and rotation
Position Object i,Camera Position X(),Camera Position Y(),Camera Position Z()
Rotate Object i,Camera Angle X(),Camera Angle Y(),0.0
Endif
Next i
`And we've gotta keep resetting the CurrentBullet variable to one everytime it exceeds 20 (since we've only got 20 bullets in this case - you can change it though)
If currentBullet>20 Then currentBullet=1
rem Finally-finally, some simple output for fancyness
Set Cursor 0,0
Print "Current Ammunition: ";ammo
Print "Ammo fired";1000-ammo
print currentBullet
SYNC : LOOP
This second one, builds on the first:
rem First, we make our bullet objects - in this case, some simple cubes. Um... let's say 20 bullets
`(we hide the bullets right now because we only want them showing up when being fired)
For i = 1 to 20
Make Object Cube i,10
Hide Object i
Next i
rem Now let's make a very simple world (with some boxes for scenery)
Make Matrix 1,2500,2500,15,15
Make Object Box 100,50,200,50
Make Object Box 101,50,200,50
Make Object Box 102,50,200,50
Position Object 100,1250,100,1250
Position Object 101,750,100,1250
Position Object 102,750,100,750
rem Some variables (I'll explain these in the program itself)
currentBullet=1
Dim bulletLife(20)
ammo=1000
shootDelay=0
rem MAIN LOOP
SYNC ON : SYNC RATE 50 : DO
rem First, let's let the player do some simple camera movement using the mouse
If MouseClick()=2 Then Move Camera 10
XRotate Camera Wrapvalue(Camera Angle X()+MouseMoveY())
YRotate Camera Wrapvalue(Camera Angle Y()+MouseMoveX())
rem Now we handle the fun stuff - shooting! Let me tell you what's we want to happen here. First, we
rem want the player to be able to fire multiple bullets away from the camera at a certain speed. These bullets
rem should move out so that they come from the center of the camera position itself. Then we'll
rem want these bullets to "die off" eventually so that we can reuse them again - thus giving the impression that he's
rem able to fire continuously
`First, we've gotta check if the current bullet is "alive" or not i.e. if it has already been shot (in this program a value of 0 means dead and anything greater than 0 means alive)
`We've also gotta check if there's enough ammo left
`And now, we add a delay so that the bullets are fired so quickly - only if this variable is zero would player be able to fire
If bulletLife(currentBullet)=0 and ammo>0 and shootDelay<=0
`If not, when player presses fire button (left mouse), then set the bulletLife to something, say 50, and increment currenBullet (that way the program will use the next bullet in
`line the next time). We also want the ammo variable to be reduced by one (obviously)
If MouseClick()=1 Then bulletLife(currentBullet)=50 : Inc currentBullet : Dec ammo : shootDelay=10
Endif
`Now, since any of the 20 bullets could be alive, we've gotta check *each* one's life value using (you guessed it right!) a for-next loop
For i = 1 to 20
`If the bullet (any one of the 20) is alive
If bulletLife(i)>0
`First show the bullet
Show Object i
`Make the bullet move straight ahead
Move Object i,20
`And decrement the life value so that it will ultimately die when bulletLife reaches 0
bulletLife(i)=bulletLife(i)-1
Endif
Next i
`Finally, we've gotta reset the position of the dead bullets to the camera's position and rotation so that it can be used properly again (otherwise the bullet will be fired from the last position it was when it was fired)
For i = 1 to 20
`If bullet is dead
If bulletLife(i)<=0
`Just in case the bulletLife slipped below zero, we wanna reset it to zero because otherwise that line "If bulletLife(currentbullet)=0" won't work
bulletLife(i)=0
`Hide the bullet object
Hide Object i
`Reposition and re-rotate the bullet to the cam's position and rotation
Position Object i,Camera Position X(),Camera Position Y(),Camera Position Z()
Rotate Object i,Camera Angle X(),Camera Angle Y(),0.0
Endif
Next i
`And we've gotta keep resetting the CurrentBullet variable to one everytime it exceeds 20 (since we've only got 20 bullets in this case - you can change it though)
If currentBullet>20 Then currentBullet=1
`And, of course, we've gotta keep decrementing shootDelay so that the player can shoot again (after the delay is up)
If shootDelay>0 Then Dec shootDelay
rem Finally-finally, some simple output for fancyness
Set Cursor 0,0
Print "Current Ammunition: ";ammo
Print "Ammo fired";1000-ammo
SYNC : LOOP
This third builds on the second:
Hide Mouse
Set Display Mode 640,480,16
rem First, we make our bullet objects - in this case, some simple cubes. Um... let's say 20 bullets
`(we hide the bullets right now because we only want them showing up when being fired)
For i = 1 to 20
Make Object Cube i,10
Hide Object i
Next i
rem Now let's make a very simple world (with some boxes for scenery)
Make Matrix 1,2500,2500,15,15
Make Object Box 100,50,200,50
Make Object Box 101,50,200,50
Make Object Box 102,50,200,50
Position Object 100,1250,100,1250
Position Object 101,750,100,1250
Position Object 102,750,100,750
rem Some variables (I'll explain these in the program itself)
currentBullet=1
Dim bulletLife(20)
ammo=1000
shootDelay=0
rem MAIN LOOP
SYNC ON : SYNC RATE 50 : DO
rem First, let's let the player do some simple camera movement using the mouse
If MouseClick()=2 Then Move Camera 10
XRotate Camera Wrapvalue(Camera Angle X()+MouseMoveY())
YRotate Camera Wrapvalue(Camera Angle Y()+MouseMoveX())
rem Now we handle the fun stuff - shooting! Let me tell you what's we want to happen here. First, we
rem want the player to be able to fire multiple bullets away from the camera at a certain speed. These bullets
rem should move out so that they come from the center of the camera position itself. Then we'll
rem want these bullets to "die off" eventually so that we can reuse them again - thus giving the impression that he's
rem able to fire continuously
`First, we've gotta check if the current bullet is "alive" or not i.e. if it has already been shot (in this program a value of 0 means dead and anything greater than 0 means alive)
`We've also gotta check if there's enough ammo left
`And now, we add a delay so that the bullets are fired so quickly - only if this variable is zero would player be able to fire
If bulletLife(currentBullet)=0 and ammo>0 and shootDelay<=0
`If not, when player presses fire button (left mouse), then set the bulletLife to something, say 50, and increment currenBullet (that way the program will use the next bullet in
`line the next time). We also want the ammo variable to be reduced by one (obviously)
If MouseClick()=1 Then bulletLife(currentBullet)=50 : Inc currentBullet : Dec ammo : shootDelay=10
Endif
`Now, since any of the 20 bullets could be alive, we've gotta check *each* one's life value using (you guessed it right!) a for-next loop
For i = 1 to 20
`If the bullet (any one of the 20) is alive
If bulletLife(i)>0
`First show the bullet
Show Object i
`Make the bullet move straight ahead
Move Object i,20
`And decrement the life value so that it will ultimately die when bulletLife reaches 0
bulletLife(i)=bulletLife(i)-1
Endif
Next i
`Finally, we've gotta reset the position of the dead bullets to the camera's position and rotation so that it can be used properly again (otherwise the bullet will be fired from the last position it was when it was fired)
For i = 1 to 20
`If bullet is dead
If bulletLife(i)<=0
`Just in case the bulletLife slipped below zero, we wanna reset it to zero because otherwise that line "If bulletLife(currentbullet)=0" won't work
bulletLife(i)=0
`Hide the bullet object
Hide Object i
`Reposition and re-rotate the bullet to the cam's position and rotation
Position Object i,Camera Position X(),Camera Position Y(),Camera Position Z()
Rotate Object i,Camera Angle X(),Camera Angle Y(),0.0
Endif
Next i
`And we've gotta keep resetting the CurrentBullet variable to one everytime it exceeds 20 (since we've only got 20 bullets in this case - you can change it though)
If currentBullet>20 Then currentBullet=1
`And, of course, we've gotta keep decrementing shootDelay so that the player can shoot again (after the delay is up)
If shootDelay>0 Then Dec shootDelay
rem Now for some ADDED fun, we are going to check collision with those pillars we included
`First, we scan all the 20 bullets and see if any one hits
For i = 1 to 20
`If it hits any pillar we rotate the pillar a random angle
If Object Collision(i,100)>0 Then Rotate Object 100,Rnd(360),Rnd(360),0.0
If Object Collision(i,101)>0 Then Rotate Object 101,Rnd(360),Rnd(360),0.0
If Object Collision(i,102)>0 Then Rotate Object 102,Rnd(360),Rnd(360),0.0
Next i
rem Finally, let's make some cool-looking cross hairs as the final touch!
`I'm just making 2D lines using the Line command from one point to another to make an open cross
Line 300,240,310,240
Line 330,240,340,240
Line 320,220,320,230
Line 320,250,320,260
rem Some simple output for fancyness
Set Cursor 0,0
Print "Current Ammunition: ";ammo
Print "Ammo fired";1000-ammo
SYNC : LOOP
Hello World Tommorrow