Shoot More Than Once

BlitzPlus Forums/BlitzPlus Programming/Shoot More Than Once

LeftyGuitar(Posted 2014) [#1]
Hello All,

I am playing around with BlitzBasic, I have a guy that walk around on the screen and shoot a bullet. However he only shoots the bullet once, no matter how much I press the spacebar, it only shoots one bullet. How do I get it so that he fires bullets repeadly?

Here is my code
AppTitle("Shoot")

Graphics 1080,720,0,2

Global bull_img

SetBuffer BackBuffer()

Flip

 guy_img = LoadImage("guy.bmp")
 bull_img = LoadImage("bullet.bmp")

Global guy_x = 10
Global guy_y = 10
Global bull_x = guy_x
Global bull_y = guy_y
Global bull_spd = 0
Global bull_vis = False


MaskImage guy_img,255,255,255
MaskImage bull_img,255,255,255

While Not KeyHit(1)
	Cls
	
Text 1,1,"X:" + bull_x
Text 1,12,"Y:" + bull_y
;Text 1,20,"Time:" + CurrentTime$()

	bull_x = bull_x + bull_spd

	DrawImage guy_img,guy_x,guy_y
	
	If KeyHit(57) Then
		bull_vis = True
		bull_spd = 10
	EndIf
	
	If KeyHit(203) Then
		guy_x = guy_x - 2
	EndIf
	
	If KeyHit(205) Then
	guy_x = guy_x + 2
	EndIf
	
	If guy_x <= 0 Then
		guy_x = 0
	EndIf
	
	If guy_x >= 1000 Then
		guy_x = 0
	EndIf
	
	
	If bull_x >= 1000 Then
	   bull_spd = 0
		bull_vis = False
	EndIf
	
	If bull_vis = True Then
	   DrawImage bull_img,bull_x,bull_y
	EndIf
			
	Flip
Wend


I know the code may not be the greatest, but I am trying to get more familiar with BlitzBasic.


Amanda Dearheart(Posted 2014) [#2]
I dont know if this will work, but have you tried the flushkeys() commands. Try it at the end of your while loop.


LeftyGuitar(Posted 2014) [#3]
Hi,

I tried the FlushKeys() command and it did not work. Thanks for the suggestion, though. Hopefully I can resolve this soon.


Matty(Posted 2014) [#4]
You never reset the bullet x position.


LeftyGuitar(Posted 2014) [#5]
Thank you Matty, I knew it was probably something simple. I got it to work after resetting the x position.