QB64 bug or exception?
#7
Yah I discovered a problem last night with this code:
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 + ...
Reply


Messages In This Thread
QB64 bug or exception? - by Pete - 10-03-2022, 07:30 AM
RE: QB64 bug or exception? - by RhoSigma - 10-03-2022, 07:49 AM
RE: QB64 bug or exception? - by Pete - 10-03-2022, 11:11 AM
RE: QB64 bug or exception? - by James D Jarvis - 10-03-2022, 11:11 AM
RE: QB64 bug or exception? - by Pete - 10-03-2022, 11:19 AM
RE: QB64 bug or exception? - by James D Jarvis - 10-03-2022, 11:25 AM
RE: QB64 bug or exception? - by bplus - 10-03-2022, 02:46 PM
RE: QB64 bug or exception? - by TerryRitchie - 10-03-2022, 03:35 PM
RE: QB64 bug or exception? - by Pete - 10-03-2022, 05:22 PM
RE: QB64 bug or exception? - by James D Jarvis - 10-03-2022, 11:44 PM
RE: QB64 bug or exception? - by Pete - 10-04-2022, 12:10 AM
RE: QB64 bug or exception? - by James D Jarvis - 10-04-2022, 12:35 AM
RE: QB64 bug or exception? - by Pete - 10-04-2022, 12:52 AM
RE: QB64 bug or exception? - by mnrvovrfc - 10-04-2022, 02:05 AM



Users browsing this thread: 6 Guest(s)