Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Tiny Space Invaders
#1
Code: (Select All)
_Title "b+ Space Invaders" ' mod of one found at LB
Screen _NewImage(256, 320, 32) ' 32 x 20 chars
_ScreenMove 500, 150
Do
    ReDim A$(4)
    For i = 0 To 4
        A$(i) = "A A A A A A A A " ' len = 16  so make field 32 wide  0 31
    Next
    sy = 19 'ship y
    sx = 14 'ship x    ship is 1 chars wide so mx starts at sx + 1, my sy - 1  sx max = 31
    ax = 0 'left of alien hoard
    ay = 0 'top left of alien  hoard
    adx = 1
    by = ay + 6
    bx = ax + Int(Rnd * 16)
    my = -1
    Do
        Cls 'draw everything
        For i = 0 To 4 'field of A's  alien hoard
            _PrintString (ax * 8, (ay + i) * 16), A$(i)
        Next
        _PrintString (bx * 8, by * 16), "o"
        If my >= 0 Then _PrintString (mx * 8, my * 16), "*"
        _PrintString (sx * 8, sy * 16), "/I\" 'the ship / cannon
        For i = 0 To 4 'field of A's  alien hoard
            If i + ay = my Then
                For j = 1 To Len(A$(i))
                    If ax + j - 1 = mx And Mid$(A$(i), j, 1) = "A" Then Mid$(A$(i), j, 1) = " ": my = -1
                Next
            End If
        Next
        If ((bx >= sx And bx <= sx + 2) And by = sy) Or (ay + 4 = 19) Then Beep: Exit Do ' blew up ship   ' did bomb take out cannon or hoard reach ground
        ax = ax + adx 'update hoard
        If ax < 0 Then
            ay = ay + 1: adx = 1: ax = 0
        ElseIf ax + 16 > 31 Then 'run it back on same line to slow down the crush
            adx = -1: ax = 15
        End If
        by = by + 1 'alien bomb
        If by > 19 Then 'new bomb
            by = ay + 5
            bx = ax + Int(Rnd * 16)
        End If
        If my >= 0 Then my = my - 1 'update bullet ' missile
        If my < ay Then my = -1 ' deactivate after passed horde
        While _MouseInput: Wend
        sx = Int((_MouseX - 8) / 8)
        k$ = InKey$
        If k$ = " " Then
            If my < ay Then mx = sx + 1: my = sy - 1 ' fire cannon  if last missile has past the hoard
        End If
        _Display
        _Limit 5
    Loop
    Sleep
Loop Until _KeyDown(27)

' 2020-11-13 tiny space invaders b+ 2020-11-14

' ========================= Instructions ===================

' mouse to move ship/cannon left and right
' spacebar to fire cannon

'===========================================================

It kinda works might be simplified a bit... Anti-Unseen Machine style no libraries and no special directories LOL!
  724  855  599  923  575  468  400  206  147  564  878  823  652  556 bxor cross forever
Reply
#2
Dang it! Once again I try some simple code in QBJS and no...

   

I thought latest QBJS updates removed need to DIM everything before using?
  724  855  599  923  575  468  400  206  147  564  878  823  652  556 bxor cross forever
Reply
#3
+1. I would have rated it +2, but for some reason you didn't code it in SCREEN 0. You could have... You should have. Big Grin 

Pete
Reply
#4
Right again! maybe you'd like to fix it Smile
  724  855  599  923  575  468  400  206  147  564  878  823  652  556 bxor cross forever
Reply
#5
(09-09-2025, 05:32 PM)bplus Wrote: I thought latest QBJS updates removed need to DIM everything before using?

That is correct, the latest version doesn't require you to DIM your variables.  However, you did find a bug with the Mid$ statement, which was just added in the last release.  It was not correctly parsing the code when arrays were being passed in as arguments.  I've made a fix to the dev server which you can try out here:

Tiny Invaders (QBJS Dev Server)

(If you don't immediately see the fixed version you might need to refresh your browser.)

I'll include the fix in a patch release that I plan to put out soon.
Reply
#6
Quote:It kinda works might be simplified a bit... Anti-Unseen Machine style no libraries and no special directories LOL!
I used to code everything, over and over and over again, then I learnt about libraries and now you all have to suffer! Smile  I assume QbJS is Java script? Not a language ive ever tried...it'lll surely be a major plus though as its a major language.

John
Reply
#7
(09-09-2025, 10:21 PM)Unseen Machine Wrote: I assume QbJS is Java script? Not a language ive ever tried...it'lll surely be a major plus though as it’s a major language.

QBJS is essentially just QBasic that can run in the browser.  QB64 compiles to C.  QBJS compiles to Javascript.
https://github.com/boxgaming/qbjs/wiki/Q...ge-Support
Reply
#8
Ok your link works @dbox

Yeah @Unseen Machine give it a try maybe start with something simple normal QB64 working code, paste into left panel
https://qbjs.org

the triangle button is the "play" button for a run, it turns to square to stop. The rectangle with up arrow is for sharing code say on a forum like this.

eg copy and paste right into editor here.
https://boxgaming.github.io/qbjs/?code=X...on1X/fAccB
  724  855  599  923  575  468  400  206  147  564  878  823  652  556 bxor cross forever
Reply
#9
(09-09-2025, 07:35 PM)bplus Wrote: Right again! maybe you'd like to fix it Smile

You know I haven't coded anything since April, but...

Code: (Select All)
_Title "Pete's Mini Space Invaders"
Width 40, 20: _Font 16
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));
GoSub keyboard
Next
If TopRow - 1 + RowHeight = terminate Then Locate 3, 2: Print "GAME OVER - YOU LOST!": _Delay 5: End
z1 = Timer
Do
If yfire Then
GoSub keyboard
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
GoSub keyboard
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

keyboard:
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
Return

I've beat it a couple of times, but I wouldn't call it easy.

Right and left arrow keys to move, but don't hold them down, you have to tap each time to move.

Space bar to fire, and you can fire when the missile disappears, either with a hit (sound) or when it passes the last row occupied by ships.

I really didn't want a gosub routine, but polling the keyboard in multiple places makes it smoother.

Pete
Reply
#10
+1 yeah some nice improvements over my version eg, that you might actually win! LOL
  724  855  599  923  575  468  400  206  147  564  878  823  652  556 bxor cross forever
Reply


Possibly Related Threads…
Thread Author Replies Views Last Post
  Space Invaders knock off to show simple collisions Unseen Machine 10 1,069 09-09-2025, 07:23 PM
Last Post: Pete
  Tiny Maze Maker - ASCII SierraKen 19 1,676 08-09-2025, 11:39 PM
Last Post: SierraKen
  Space Pongy bplus 3 816 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,213 02-19-2024, 01:27 AM
Last Post: PhilOfPerth

Forum Jump:


Users browsing this thread: 1 Guest(s)