bullets

Blitz3D Forums/Blitz3D Beginners Area/bullets

pyro821(Posted 2004) [#1]
I need help with types. I know how to set then up but I can not get it to make more than one image with a type. For example make a bullet with the type function and every time I hit say shift a new bullet will shot, so I do not have to make a image for every shot. If some one can help me I would be very happy.


WolRon(Posted 2004) [#2]
Your question is very unclear...

To create another instance of a type, use the New command.


pyro821(Posted 2004) [#3]
Sorry it was not clear I will try again. Ok I need to make a type for a bullet (im using blitz plus by the way). I can set it up but how do I make it so when I hit shift a new bullet shots across the screen.


semar(Posted 2004) [#4]
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.


Rook Zimbabwe(Posted 2004) [#5]
Or you could just go to the TUTORIALS section where this has been shown in completeness!!!


semar(Posted 2004) [#6]
@pyro821,

were our answers of any help for you ?

Sergio.