bullet help

Blitz3D Forums/Blitz3D Beginners Area/bullet help

RyanD(Posted 2004) [#1]
Hi, I'm new to blitz, I'm current;y working on my 3rd blitz game and I am trying to make it one of my finest. My problem is when I hit the spacebar the bullet appears for about half a second I think it has somethinf to do with this line

If KeyHit(57) And hpistol = 1 And pistol\ammo > 0
b.bullet = New bullet

b\x = pistol\x

b\y = pistol\y

pistol\ammo = pistol\ammo - 1
b\x = b\x + 1
DrawImage(ibullet,b\x,b\y)

If pistol\ammo <= 0
pistol\ammo = 0
EndIf
EndIf

Can some one help me?


Rook Zimbabwe(Posted 2004) [#2]
Read this tutorial:

http://www.blitzbasic.co.nz/Community/posts.php?topic=35127

I commented and got a lot of help but I think it can help you.

-Rook


Valgar(Posted 2004) [#3]
I know your error,'cause i made it sometimes :P
If you put the "drawimage"command in the same "if keyhit" ecc ecc you are drawing the image if the button is pressed,so when the button isn't pressed the image is not drawn!


Valgar(Posted 2004) [#4]
Try modify in this manner your function:
If KeyHit(57) And hpistol = 1 And pistol\ammo > 0
b.bullet = New bullet

b\x = pistol\x

b\y = pistol\y

pistol\ammo = pistol\ammo - 1
b\x = b\x + 1
;DrawImage(ibullet,b\x,b\y)commented!!must be uotside the loop!!

If pistol\ammo <= 0
pistol\ammo = 0
EndIf
EndIf 
DrawImage(ibullet,b\x,b\y)   ;must be outside and it works!



eBusiness(Posted 2004) [#5]
Valgar, I think that is only slightly better, this should do what you want:
If KeyHit(57) And hpistol = 1 And pistol\ammo > 0
b.bullet = New bullet

b\x = pistol\x

b\y = pistol\y

pistol\ammo = pistol\ammo - 1

If pistol\ammo <= 0
pistol\ammo = 0
EndIf
EndIf
For b.bullet = Each bullet
  b\x = b\x + 1
  DrawImage(ibullet,b\x,b\y)
Next



Valgar(Posted 2004) [#6]
Yes,i've made only this light modification for helping him only to know what caused the error.
He must add the "for--next"loop to cicle trough the bullet type(my mistake sorry)before using outside the function any of the bullet fields...


RyanD(Posted 2004) [#7]
Thank you soooo much Now I am going to make some grenades for this :P


RyanD(Posted 2004) [#8]
alright I need some more help, when I try to switch my guns everything works out fine but when I try to shoot them seperate, nothing comes out of the shotgun but both bullets come out of the pistol




eBusiness(Posted 2004) [#9]
Dude, when you loop trough all bullets, you loop trough ALL bullets. If you write s.bullet = New bullet or b.bullet = New bullet doesn't matter, they are all the same. Either you can create two different types, or you can add a few extra attributes to your type, for now you will need a speed field and an image handle field, later on you will probably need a field for the damage that the bullet will do. I don't know why your shotgun doesn't fire.


Valgar(Posted 2004) [#10]
I have resolved this to make a different type for every direction as eBusiness say.
So you must threat the types in different manner accordingly to the direction.