bullet direction

Blitz3D Forums/Blitz3D Beginners Area/bullet direction

RyanD(Posted 2004) [#1]
I need some help with bullets....
When I shoot, the bullets go fine, but when i hit another key the bullets go the other way

AppTitle "Jim's Adventure"

Graphics 800,600,0,2

jimimage = LoadImage("jim.bmp")
cvimage = LoadAnimImage("cv.bmp",45,15,0,2)
bulletfont = LoadFont("Impact",20,False,False,False)
bulletimage = LoadImage("bullet.bmp")

;mask all the images
MaskImage jimimage,255,0,255
MaskImage cvimage,255,255,255

; make the type
Type jim
	Field x,y
	Field grav
End Type

Type cv
	Field x,y
	Field frame
	Field ammo_c ;ammo in clip
	Field ammo_t ;ammo total
	Field reload
	Field speed
	Field timer
	Field guntimer
	Field bullet
End Type

Type grenade 
	Field x,y
End Type

Type bullet
	Field x,y
	Field direction
End Type
;create the types
j.jim = New jim
cv.cv = New cv
gr.grenade = New grenade


;variables for guns anc char.
j\x = 400
j\y = 400
cv\ammo_c = 30
cv\ammo_t = 27
cv\timer = MilliSecs()
cv\speed = 10
cv\timer = 0
cv\reload = 0


cv_on = True
gr_on = False
direction = False
ammo_transfer = 0

SetBuffer BackBuffer()

;==========================MAIN CODING==================

While Not KeyDown(1)



;draw the jimimage 1st so the guns will go in front of him
DrawImage jimimage,j\x,j\y

;gun if's
;=================================CV============================
If cv_on = True
	cv\x = j\x - 9
	cv\y = j\y + 30
	DrawImage cvimage,cv\x,cv\y,direction
	Color 255,141,47
	SetFont bulletfont
Text 700,550,""+ cv\ammo_c,False,False
Text 730,550,"\",False,False
Text 755,550,""+cv\ammo_t,False,False
EndIf

;================================================================




;========================CHARACTER STATS=========================
If KeyDown(203)
	j\x = j\x - 3
	direction = 1
ElseIf KeyDown(205)
	j\x = j\x + 3
	direction = 0
EndIf

;------------------------------shot?----------------------------



;=================BULLET CLIP TESTS=================

If cv\ammo_c <= 0
ammo_transfer = cv\ammo_t
If ammo_transfer >= 30
ammo_transfer = 30
Else ammo_transfer = cv\ammo_t
cv\ammo_t = cv\ammo_t - ammo_transfer
cv\ammo_c = cv\ammo_c + ammo_transfer
EndIf
EndIf

;===================================================



;================CREATE BULLETS=====================

;--------------------CV-----------------------------



If KeyDown(57) And cv_on = True And cv\ammo_c > 0 
If MilliSecs() - cv\timer > 100      
	b.bullet = New bullet
	b\x = cv\x + Rnd(20,23)
	b\y = cv\y + Rnd(2,3)
	cv\ammo_c = cv\ammo_c - 1
DrawImage(bulletimage,cv\x,cv\y)
cv\timer = MilliSecs()
EndIf
EndIf

For b.bullet = Each bullet
If direction = 0
b\x = b\x + 10
DrawImage(bulletimage,b\x,b\y)
EndIf
Next
;draw cv bullets


For b.bullet = Each bullet
If direction = 1
b\x = b\x - 10

DrawImage(bulletimage,b\x,b\y)
EndIf
Next


;END CV
;------------------------------------------------------

Flip
Cls

Wend



RyanD(Posted 2004) [#2]
Maybe i didn't say enough... When i press the left key the direction is 0. So when I shoot the bullets go left. But when i hit the right button the bullets stop going to the left and then go right. Im not really looking for code, i want to know how to do it.


soja(Posted 2004) [#3]
I notice that you've got a direction field for your bullets, but that you don't use it. Instead, you're using a local direction variable only. (That's kind of confusing to have to direction variables.)

So my suggestions are:
a) When you create the bullet, set its direction according to the arrow key that is pressed (b.bullet\direction = direction)
b) When you draw the bullets, make sure you reference "if b\direction...", not just "if direction...".