Yah I discovered a problem last night with this code:
I can shoot (3 keypresses) Spacebar + Up and Right or Spacebar + Down and Left but not Spacebar + Up and Left Nor Spacebar + Down and Right. No problems if just Spacebar and one arrow key.
Even tried this mod:
If _KeyDown(32) And ((dx <> 0) Or (dy <> 0)) Then GoSub shoot
no difference.
Code: (Select All)
_Title "Use arrow keys to move our hero, spacebar to shoot."
Type bullet
As Integer x, y, dx, dy, alive
End Type
nBullets = 100
Dim bullets(1 To nBullets) As bullet
heroX = _Width \ 2: heroY = _Height \ 2 ' middle
Do
Cls
For i = 1 To nBullets
If bullets(i).alive Then
bullets(i).x = bullets(i).x + bullets(i).dx: bullets(i).y = bullets(i).y + bullets(i).dy
If bullets(i).x > 0 And bullets(i).x <= _Width Then
If bullets(i).y > 0 And bullets(i).y <= _Height Then
Locate bullets(i).y, bullets(i).x: Print "*";
Else
bullets(i).alive = 0
End If
Else
bullets(i).alive = 0
End If
End If
Next
dx = 0: dy = 0
Locate heroY, heroX: Print Chr$(1);
If _KeyDown(19200) Then heroX = heroX - 1: dx = -1
If _KeyDown(19712) Then heroX = heroX + 1: dx = 1
If _KeyDown(18432) Then heroY = heroY - 1: dy = -1
If _KeyDown(20480) Then heroY = heroY + 1: dy = 1
If _KeyDown(32) And (dx Or dy) Then GoSub shoot
If heroX < 1 Then heroX = 1
If heroX > _Width Then heroX = _Width
If heroY < 1 Then heroY = 1
If heroY > _Height Then heroY = _Height
_Limit 10
Loop
shoot:
For i = 1 To 100
If bullets(i).alive = 0 Then
bullets(i).alive = -1
bullets(i).x = heroX + dx * 2: bullets(i).y = heroY + dy * 2
bullets(i).dx = dx * 2: bullets(i).dy = dy * 2
Exit For
End If
Next
Return
I can shoot (3 keypresses) Spacebar + Up and Right or Spacebar + Down and Left but not Spacebar + Up and Left Nor Spacebar + Down and Right. No problems if just Spacebar and one arrow key.
Even tried this mod:
If _KeyDown(32) And ((dx <> 0) Or (dy <> 0)) Then GoSub shoot
no difference.
b = b + ...