Basically WolRon has already answered to your question.
Consider your type structure as a dynamic container, like for example:
type t_bullet
field x,y
field speedx,speedy
end type
Global bullet.t_bullet
When you create a new bullet with the New command:
bullet.t_bullet = New t_bullet
;create the bullet at the mouse x,y position
bullet\x = mousex()
bullet\y = mousey()
bullet\speedx = 2
bullet\speedy = 1
You have a brand new bullet in your bullet type collection. You don't see it unless you display an image for it:
while not keydown(1)
cls
;move all bullets
updategame()
;show all bullets
rendergame()
flip
wend
end
;===================================
function updategame()
;===================================
for bullet.t_bullet = each t_bullet
bullet\x = bullet\x + bullet\speedx
bullet\y = bullet\y + bullet\speedy
next
end function
;===================================
function rendergame()
;===================================
for bullet.t_bullet = each t_bullet
;the bullet image is a global image called image_bullet
drawimage image_bullet,bullet\x,bullet\y
next
end function
Now, each time you press your fire key, just create a new bullet as before, and you're done.
You should take care of bullet expiration too; for example, you may want to delete the bullets which have gone out of the screen.
So, in the updategame function, you can check for the bullet x and y position, and if they are outside, then delete the bullet.
Hope this helps, Sergio.
|