Cameron,
The bullet needs a few variables, preferably an array. Each variable, or array dimension will hold a specific value. These values are:
life - how long the bullet last after shot
xpos# - bullet's x coordinate position
ypos# - bullet's y coordinate position
angle# - bullet's angle of direction
speed - speed the bullet travels
Note, that initially by program default, the value in life will equal to 0, as well as the others.
Now, to initiate the bullet's movement, we need to change the value in a variable to signal a group of code to be looped through, after the user presses the "fire" button. In this case, it will be the left mouse button(LMB). Our signal will be the value in
life. If it is above 0, then the bullet should move.
When the user first clicks the mouse button, we need to set all of the variables presented above.
Life should be set to something above 0.
xpos# and
ypos# should be set to either the tip of the gun barrel, or the current x and y position of the user character.
angle# should be set to either the angle the gun is currently pointed, or the angle the user character is currently facing.
speed should be set to, of course, the speed you wish the bullet to fly.
Therefore:
if mouseclick() = 1 and life = 0
life = 30
xpos# = charx#
ypos# = chary#
angle# = charangle#
speed# = 4
endif
The code above will "turn the bullet on" and set its properties. When I say "turn the bullet on", I mean that the code which makes the bullet to move across the screen, is only ran if so-be that the value in
life is greater than 0. The code above sets this value to 30. Now, we must make the bullet move.
Example:
if life > 0
REM << decrease life by 1, to eventually "kill" the bullet
dec life
REM << use math to move the bullet across screen at set angle and speed
xpos# = xpos# + (cos(angle#) * speed)
ypos# = ypos# + (sin(angle#) * speed)
endif
Once the value in
life = 0 again, the bullet will dissapear. Remember, when the user presses the "fire" button, set properties of the bullet according to the properties of the shooter character. These needed properties are listed above. Also, use the value in
life to make to bullet move, or not move. This keeps yoiu from having to use another variable to do so(killing two birds with one stone).
One last note, don't beg for help here.
+NanoBrain+