Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Tiny Space Invaders
#11
Well your routine works on QBJS, but mine doesn't; so +1 for that achievement! Mine throws an Error 8, and that's after I convert the GOSUB and get rid of the WIDTH statement.

QBJS Attempt...
[qbjs] _Title "Pete's Mini Space Invaders For QBJS"
bit = 1: TopRow = 5: a$ = "A A A A A A A A": For i = 0 To 4: a$(i) = a$: Next
trail = _Width \ 2 - Len(a$) \ 2: lag = .35: xbase = _Width \ 2: RowHeight = 5: terminate = _Height - 1
Do
    Cls: Locate _Height, xbase: Print Chr$(234);: Sound 500, .1
    For i = 0 To RowHeight - 1
        Locate TopRow + i, trail + l: Print RTrim$(Mid$(a$(i), l + 1));
    Next
    If TopRow - 1 + RowHeight = terminate Then Locate 3, 2: Print "GAME OVER - YOU LOST!": _Delay 5: End
    z1 = Timer
    Do
        If yfire Then
            If Abs(z2 - Timer) > .1 Then
                z2 = Timer
                If Screen(yfire, xfire) = 24 Then Locate yfire, xfire: Print " ";
                yfire = yfire - 1: If yfire < TopRow Then
                    yfire = 0
                Else
                    Locate yfire, xfire
                    If Screen(yfire, xfire) = 65 Then
                        RowCheck = 0: l = 0: r = 0
                        Mid$(a$(yfire - TopRow), xfire - trail + 1, 1) = " ": Sound 1000, .5: yfire = 0
                        If LTrim$(a$(0) + a$(1) + a$(2) + a$(3) + a$(4)) = "" Then Cls: Locate 3, 2: Print "GAME OVER - YOU WON!": _Delay 5: End
                        For i = 4 To 0 Step -1
                            If LTrim$(a$(i)) = "" And RowCheck = 0 Then RowHeight = i + 1 Else RowCheck = 1
                            If Len(RTrim$(a$(i))) > r Then r = Len(RTrim$(a$(i)))
                            If Len(LTrim$(a$(i))) > l Then l = Len(LTrim$(a$(i)))
                        Next
                        r = Len(a$) - r: l = Len(a$) - l
                    Else
                        Print Chr$(24);
                    End If
                End If
            End If
        End If
        Select Case _KeyHit
    Case 19200
        If xbase > 1 And restrict = 0 Then Locate _Height, xbase: Print " ";: xbase = xbase - 1: restrict = 1: Locate _Height, xbase: Print Chr$(234);
    Case 19712
        If xbase < _Width And restrict = 0 Then Locate _Height, xbase: Print " ";: xbase = xbase + 1: restrict = 1: Locate _Height, xbase: Print Chr$(234);
    Case -19200, -19712
        restrict = 0: _KeyClear
    Case 32
        If yfire = 0 Then Locate _Height - 1, xbase: Print Chr$(24);: yfire = _Height - 1: xfire = xbase
End Select
        If Abs(z1 - Timer) > lag Then z1 = Timer: Exit Do
    Loop
    If trail + Len(a$) - r > _Width And bit = 1 Or trail = 1 - l And bit = -1 Then bit = -bit: TopRow = TopRow + 1: lag = lag - .025 Else trail = trail + bit
Loop [/qbjs]

I made mine "adaptive" so it can handle the default screen, but the 40 x 20 screen is so much better. Maybe it's obvious to you what is throwing that ERROR 8. If not, I might have some time tonight or tomorrow to step through the code. Also, but I can't remember off the top of my head, I think _NEWIMAGE can mimic SCREEN 0, so I suppose I could set the screen size that way, but I'm not sure if my _WIDTH and _HEIGHT statements would still work. I might fiddle with that later, too.

Pete




Edit: Apologies, the QBJS code box icon didn't place the code in a window using my FireFox browser.
Reply
#12
Error 8 or do you misread error 0?
   

Yeah @dbox will have to check that out, it doesn't even give line number of problem. Have no idea what left habd assignment means. I noticed your 'bit' variable being blue highlighted as if it were a code word mistaken for _bit?

I confess I haven't worked on original code project in awhile either but I have so much material accumulated since 2014 when I came back to Basic programming with SmallBASIC. Man what a great ride, it turns out between the death of my father in 2014 and death of my mother in Dec 2024, 10 years. I hope I am not done.
  724  855  599  923  575  468  400  206  147  564  878  823  652  556 bxor cross forever
Reply
#13
I was able to get a version that would work for you @Pete, but you did find a couple of additional compatibility issues.

First, the error you were seeing was due to the same issue that @bplus was having with the Mid$ statement.  This has been fixed in the dev server but hasn't been pushed up to qbjs.org just yet.

Running it in the dev server I did find a couple of additional issues that were preventing it from working correctly.  First, I have not yet implemented the screen 0 behavior for the _Width and _Height methods.  (I'll add a ticket to support that in the next release.)  At present, they always return the sizing information in pixels rather than characters.  Next, QBJS does not yet have support for defining multiple variations of the same variable name that differ only by type.  So, it didn't like the fact that a$ was being used for both a string and as a separate array.

Here's a version that works on the dev server by using a little QBJS trick to define _Width and _Height as varaibles and redefining the string variable as s$:
Pete's Mini Space Invaders For QBJS

To use the QBJS embed tag you'll want to use the share link that is generated from the QBJS IDE instead of the full source file.  It will look something like this:
Code: (Select All)
[qbjs]https://qbjs.org?code=IF9UaXRsZSAiUGV0ZSdzIE1pbmkgU3BhY2UgSW52YWRlcnMgRm9yIFFCSlMiCkRpbSBfV2lkdGgsIF9IZWlnaHQ6xxEgPSA4....gSgyFfGCCvERwrkAKMg[/qbjs]
Reply
#14
Nice, you got it to run!

Thee were a couple of other places a$ needed to be changed to s$, too. I did that, but I noticed the lines of alien ships did not operate the same in QBJS. They would occasionally get skewed, and hits that generated sound would not result in the ship disappearing. That's possibly all related to the MID$(Crisis). Still, I'm really impressed it's so close. I recall having to do many more changes to get running on SmallBASIC.

+2 for getting up and running! I'll check back after some time to see how the _WIDTH and _HEIGHT stuff is coming along. Oh, I know for now 80, 25 can be changed to 40, 20 in the code you modified to match the boundaries of my original routine, but the window size still stays at 80, 25.

Pete
Reply
#15
Hey @Pete, turns out there is something already in place for sizing the screen using text coordinates.  If you use the _NewImage method and pass 0 as the last parameter it will treat the width and height parameters as characters rather than pixels:
Code: (Select All)
Screen _NewImage(40, 20, 0)

I'm still planning on making the updates to the default screen 0 to handle setting and retrieving the width in characters, but in the meantime here's an updated version that perhaps is closer to your original:
Pete's Mini Space Invaders For QBJS
Reply
#16
@dbox Yeah, I mentioned I recalled _NewImage could be used in a previous post, but I'd have to look up how again. Thanks for saving me the trouble!

Now not for me, but if you are interested in using this code to further your QBJS project, I think this counter code might help. What I noticed is the rows don't always stay lined up, but even when the do the explosion sounds in QBJS did not coincide with the removal of the ship that was hit. So I put a counter for the sounds that indicate hits, along with a counter of the number of ships in the cumulative arrays. I put the display on top, and 40 should always be the last number if it's working correctly. Run it in QB64 and you will see that is true, but it's way off in QBJS, which indicates to me there is more going on with the MID$() incompatibility.

Here is the modified code. I didn't want to save it to your server, to avoid any confusion.

Code: (Select All)
_Title "Pete's Mini Space Invaders For QBJS"
Screen _NewImage(40, 20, 0)
Dim _Width, _Height: _Width = 40: _Height = 20 'QBJS trickery to redefine _Width and _Height as variables ' REMARK OUT THIS LINE IF RUNNING IN QB64.
bit = 1: TopRow = 5: s$ = "A A A A A A A A": For i = 0 To 4: a$(i) = s$: Next
trail = _Width \ 2 - Len(a$) \ 2: lag = .35: xbase = _Width \ 2: RowHeight = 5: terminate = _Height - 1
Do
    ' Added Counter----------------------------------------------------------
    count = 0
    For i = 0 To 4
        For j = 1 To 8
            If Mid$(a$(i), j * 2 - 1, 1) = "A" Then count = count + 1
        Next
    Next
    '-----------------------------------------------------------------------------
    Cls: Locate _Height, xbase: Print Chr$(234);: Sound 500, .1
    Locate 1, 2: Print "Ships ="; count; " Bangs ="; explosions; " Proof 40 ="; count + explosions
    For i = 0 To RowHeight - 1
        Locate TopRow + i, trail + l: Print RTrim$(Mid$(a$(i), l + 1));
    Next
    If TopRow - 1 + RowHeight = terminate Then Locate 3, 2: Print "GAME OVER - YOU LOST!": _Delay 5: End
    z1 = Timer
    Do
        If yfire Then
            If Abs(z2 - Timer) > .1 Then
                z2 = Timer
                If Screen(yfire, xfire) = 24 Then Locate yfire, xfire: Print " ";
                yfire = yfire - 1: If yfire < TopRow Then
                    yfire = 0
                Else
                    Locate yfire, xfire
                    If Screen(yfire, xfire) = 65 Then
                        RowCheck = 0: l = 0: r = 0
                        Mid$(a$(yfire - TopRow), xfire - trail + 1, 1) = " ": Sound 1000, .5: yfire = 0: explosions = explosions + 1 ' ADDED EXPLOSIONS VARIABLE.
                        If LTrim$(a$(0) + a$(1) + a$(2) + a$(3) + a$(4)) = "" Then Cls: Locate 3, 2: Print "GAME OVER - YOU WON!": _Delay 5: End
                        For i = 4 To 0 Step -1
                            If LTrim$(a$(i)) = "" And RowCheck = 0 Then RowHeight = i + 1 Else RowCheck = 1
                            If Len(RTrim$(a$(i))) > r Then r = Len(RTrim$(a$(i)))
                            If Len(LTrim$(a$(i))) > l Then l = Len(LTrim$(a$(i)))
                        Next
                        r = Len(s$) - r: l = Len(s$) - l
                    Else
                        Print Chr$(24);
                    End If
                End If
            End If
        End If
        Select Case _KeyHit
            Case 19200
                If xbase > 1 And restrict = 0 Then Locate _Height, xbase: Print " ";: xbase = xbase - 1: restrict = 1: Locate _Height, xbase: Print Chr$(234);
            Case 19712
                If xbase < _Width And restrict = 0 Then Locate _Height, xbase: Print " ";: xbase = xbase + 1: restrict = 1: Locate _Height, xbase: Print Chr$(234);
            Case -19200, -19712
                restrict = 0: _KeyClear
            Case 32
                If yfire = 0 Then Locate _Height - 1, xbase: Print Chr$(24);: yfire = _Height - 1: xfire = xbase
        End Select
        If Abs(z1 - Timer) > lag Then z1 = Timer: Exit Do
        _Limit 60
    Loop
    If trail + Len(s$) - r > _Width And bit = 1 Or trail = 1 - l And bit = -1 Then bit = -bit: TopRow = TopRow + 1: lag = lag - .025 Else trail = trail + bit
Loop

Pete
Reply


Possibly Related Threads…
Thread Author Replies Views Last Post
  Space Invaders knock off to show simple collisions Unseen Machine 10 1,073 09-09-2025, 07:23 PM
Last Post: Pete
  Tiny Maze Maker - ASCII SierraKen 19 1,684 08-09-2025, 11:39 PM
Last Post: SierraKen
  Space Pongy bplus 3 818 11-29-2024, 11:18 PM
Last Post: SierraKen
  Tech Invaders 5 SierraKen 5 1,204 08-12-2024, 01:10 PM
Last Post: Dav
  sweet little circuit game space maker bplus 3 1,215 02-19-2024, 01:27 AM
Last Post: PhilOfPerth

Forum Jump:


Users browsing this thread: 1 Guest(s)