bullet help
Blitz3D Forums/Blitz3D Beginners Area/bullet help
| ||
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? |
| ||
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 |
| ||
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! |
| ||
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! |
| ||
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 |
| ||
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... |
| ||
Thank you soooo much Now I am going to make some grenades for this :P |
| ||
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 |
| ||
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. |
| ||
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. |