Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Resurrected for Halloween: ASCII Invaders Halloween Edition
#11
(10-04-2022, 06:28 PM)bplus Wrote:
(10-04-2022, 03:05 AM)TerryRitchie Wrote:
(10-04-2022, 12:42 AM)bplus Wrote: I think Terry wants games inspired by his manual.

But I am making a collection now to put in my corner here.

All games are welcome whether inspired by the site or not. The more game code for others to learn from the better. I would be honored to have any code you would like to share.

@TerryRitchie

I would be honored as well if you use anything of mine you feel helpful to the cause. I will gladly make edits if you need things to fit better with your lessons.

All I need in the source code, any asset files (sounds, images, etc..), and quick explanation of the game and usage. A ZIP file would be perfect. You can either post it here in the forum or send the ZIP to my email: quickbasic64@gmail.com

Thank you for contributing Smile

Terry
Reply
#12
I'm sorry for bringing up this topic almost two months after the last post LOL but it's fair for me to warn that I'm having trouble running this game on Spiral Linux. It might be today that I upgraded to Linux v6 kernel -- a first for Debian-based distro. Before that (with Linux v5.19.0 kernel) this program executed without problems. I tried to get fancy to get it to use a font other than the "system" one but it didn't work. I had been compiling and running the program as it was originally presented here.

Erm, an interruption to say... I really liked this game! More challenging because the alien missile "eats" the tank's, makes it harder when a few invaders remain. It's addictive because the user could press only one key. But that scheme falls apart because I want two-letter, not three-letter name on high scores list. But that's a childish request...

Anyway this might have to do with the kernel and other things. I should check this on the Arch-based distro installs that I have which have even newer point-point releases, the latest at this moment should be v6.0.10.

This is the error message I've been getting ("altonly" is what I named this program LOL):
Code: (Select All)
[xcb] Unknown request in queue while dequeuing
[xcb] Most likely this is a multi-threaded client and XInitThreads has not been called
[xcb] Aborting, sorry about that.
altonly: ../../src/xcb_out.c:479: _xcb_out_flush_to: Assertion `XCB_SEQUENCE_COMPARE(request, <=, c->out.request)' failed.
Aborted

Sometimes the lines beginning with "[xcb]" aren't displayed. A window appears briefly, a mix of the desktop and any other window (usually the terminal) that might have been in its way, and then bumps back down to the terminal displaying the error.

c. 10 minutes later:

Switched to EndeavourOS. The program executed without problems without any change in the source code. However, something happened to the game after I killed all the aliens in the first round, and it stayed this way:

[Image: ascii-invaders-empty.png]
Reply
#13
Hmm, not sure why it froze up. Those remaining bat wings might be a clue as to some infrequent bug.

As for the wanting to just include 2 initials, just replace the existing displayhighscores sub with this slightly modified one. I set a new inmax variable to "2" for two initials. See it near the top of the displayhighscores sub. You can also change the value from "2" to 1 or 3 for one or three initials.

Code: (Select All)
SUB displayhighscores
    inmax = 2 ' Change to 1, 2 or 3 determine how many initils you want to enter for high score.

    IF inmax < 1 OR inmax > 3 THEN imax = 3
    COLOR 0, 3
    LOCATE 25, 68: PRINT "Score "; score$;

    DIM hs AS STRING * 25
    REDIM highscore$(6), hsdata$(6)

    DO
        IF _FILEEXISTS("ascii-invaders-high-score.dat") THEN
            OPEN "ascii-invaders-high-score.dat" FOR RANDOM AS #1 LEN = 25
            FOR i = 1 TO 5
                GET #1, i, hs
                highscore$(i) = MID$(hs, 10, 6): hsdata$(i) = hs
            NEXT
            CLOSE #1
        ELSE
            FOR i = 1 TO 5
                hsdata$(i) = SPACE$(25)
            NEXT
        END IF

        IF VAL(score$) > VAL(highscore$(5)) THEN

            IF VAL(score$) > VAL(highscore$(1)) THEN
                msg$ = " HIGH SCORE / Enter Your Initials! "
            ELSE
                msg$ = " Top 5 Score. Enter Your Initials! "
            END IF

            GOSUB hiscore

            a = 14
            OUT &H3C8, 0
            OUT &H3C9, 20 - a
            OUT &H3C9, 20 - a
            OUT &H3C9, 20 - a

            OUT &H3C8, 8
            OUT &H3C9, 30 - a
            OUT &H3C9, 30 - a
            OUT &H3C9, 30 - a

            OUT &H3C8, 7
            OUT &H3C9, 30 - a
            OUT &H3C9, 30 - a
            OUT &H3C9, 30 - a

            OUT &H3C8, 3
            OUT &H3C9, 30 - a
            OUT &H3C9, 30 - a
            OUT &H3C9, 30 - a

            GOSUB hardware_overlay

            _FONT 16

            COLOR White, 0
            t$ = msg$
            PSLC 4.6, 41 - LEN(msg$) \ 2, t$

            font = _LOADFONT("lucon.ttf", 20, "monospace")
            IF font <= 0 THEN font = 16
            _FONT font

            DEF SEG = 0
            delay = .4
            lscr = 19
            z3 = TIMER
            DO
                initials$ = "": i = 0: nxt = 0
                COLOR , _RGB(24, 24, 24): t$ = "  " ' Blank initials for redo. Okay to blank at start.
                PSL 5 + rank * 2, lscr, t$
                _DISPLAY
                DO
                    _LIMIT 60
                    IF ABS(z3 - TIMER) > .3 AND kflag > -2 THEN
                        underline 5 + rank * 2, lscr + nxt, 0
                        _DISPLAY
                        z3 = TIMER
                    END IF

                    SELECT CASE kflag
                        CASE 0
                            IF ABS(z1 - TIMER) > 1.5 AND i AND nxt < 3 THEN
                                SOUND 1500, 1
                                underline 5 + rank * 2, lscr + nxt, -1: uflag = 0
                                _DISPLAY
                                initials$ = initials$ + CHR$(64 + i)
                                nxt = nxt + 1 ' Next initial
                                i = 0 ' Reset alphabet.
                                z1 = TIMER
                                IF nxt = inmax THEN
                                    kflag = -2 ' All initials have been input.
                                    underline 5 + rank * 2, lscr + nxt, -1: uflag = 0
                                    _DISPLAY
                                END IF
                            END IF

                            IF PEEK(1047) MOD 16 = 7 OR PEEK(1047) MOD 16 = 8 THEN
                                kflag = -1 ' Alt key pressed.
                                z1 = TIMER: z2 = TIMER
                                i = i + 1: IF i > 26 THEN i = 1
                                COLOR , _RGB(24, 24, 24): t$ = " "
                                PSL 5 + rank * 2, lscr + nxt, t$
                                COLOR DarkOrange: t$ = CHR$(64 + i)
                                SOUND 1000, .1
                                PSL 5 + rank * 2, lscr + nxt, t$
                                underline 5 + rank * 2, lscr + nxt, 0
                                _DISPLAY
                            END IF
                        CASE -1
                            IF ABS(z2 - TIMER) > 2 THEN ' Key down long enough to indicate redo input.
                                IF nxt > 0 THEN ' Redo last initial input.
                                    SOUND 300, .5
                                    FOR nxt = 0 TO 3
                                        underline 5 + rank * 2, lscr + nxt, -1: uflag = 0
                                    NEXT
                                    nxt = 0: i = 0
                                    initials$ = ""
                                    COLOR , _RGB(24, 24, 24): t$ = "  "
                                    PSL 5 + rank * 2, lscr, t$
                                    _DISPLAY
                                    z1 = TIMER ' Reset enter timer.
                                ELSE
                                    SOUND 300, .5
                                    i = 0
                                    COLOR , _RGB(24, 24, 24): t$ = " "
                                    PSL 5 + rank * 2, lscr, t$
                                    _DISPLAY
                                    z1 = TIMER ' Reset enter timer.
                                END IF
                                z2 = TIMER
                            END IF

                            IF PEEK(1047) MOD 16 <> 7 AND PEEK(1047) MOD 16 <> 8 THEN ' Alt key was released.
                                kflag = 0 ' Alt key up
                                z1 = TIMER
                            END IF
                        CASE -2 ' Finished. Initials will flash until confirmed by 2-second timer.
                            z1 = TIMER: z2 = TIMER
                            j = 0
                            DO
                                IF ABS(z1 - TIMER) > .3 THEN j = -j - 1: z1 = TIMER
                                IF j THEN
                                    COLOR DarkOrange: t$ = initials$
                                    PSL 5 + rank * 2, lscr, t$
                                    _DISPLAY
                                ELSE
                                    COLOR _RGB(24, 24, 24): t$ = initials$
                                    PSL 5 + rank * 2, lscr, t$
                                    _DISPLAY
                                END IF

                                IF ABS(z2 - TIMER) > 2.5 AND j THEN
                                    kflag = -3
                                    EXIT DO
                                END IF

                                IF PEEK(1047) MOD 16 = 7 OR PEEK(1047) MOD 16 = 8 THEN
                                    BEEP
                                    kflag = -4
                                    EXIT DO
                                END IF
                            LOOP
                        CASE -3
                            _DELAY 1
                            l$ = "8"
                            n$ = "n24": PLAY "L" + l$ + n$
                            n$ = "n28": PLAY "L" + l$ + n$
                            n$ = "n28": PLAY "L" + l$ + n$
                            l$ = "7"
                            n$ = "n31": PLAY "L" + l$ + n$
                            l$ = "9"
                            n$ = "n28": PLAY "L" + l$ + n$
                            l$ = "3"
                            n$ = "n31": PLAY "L" + l$ + n$
                            kflag = 1
                            _DELAY 1: EXIT DO
                        CASE -4
                            kflag = 0 ' Repeat enter initials
                            nxt = 0
                            i = 0
                            EXIT DO
                    END SELECT
                LOOP
                IF kflag > 0 THEN kflag = 0: EXIT DO ' Exit routine.
            LOOP
            DEF SEG

            hsname$ = initials$

            MID$(hsdata$(rank), 5, 3) = hsname$ + SPACE$(3 - LEN(hsname$))
            OPEN "ascii-invaders-high-score.dat" FOR RANDOM AS #1 LEN = 25
            FOR i = 1 TO 5
                hs = hsdata$(i)
                IF LEFT$(hs, 1) = "" THEN MID$(hs, 1, 2) = "0" + LTRIM$(STR$(i))
                PUT #1, i, hs
            NEXT
            CLOSE #1

            _DELAY 1
            _DISPLAY ' Remove scoreboard.
            _DELAY 1
            _FREEIMAGE Overlay
            _FONT 16 'select inbuilt 8x16 default font
            _FREEFONT font

            _DEST 0 'Reset dest back to the normal screen 0.

            _AUTODISPLAY
            COLOR 6, 0
            msg$ = SPACE$(40)
            LOCATE 4, 41 - LEN(msg$) \ 2
            PRINT msg$;
            PALETTE
            _DELAY 1

            EXIT DO
        ELSE
            EXIT DO ' Not in the top 5 highest scores so exit sub.
        END IF
    LOOP
    EXIT SUB

    hardware_overlay:
    Overlay = _NEWIMAGE(_WIDTH * _FONTWIDTH, _HEIGHT * _FONTHEIGHT, 32)

    _DEST Overlay
    _DISPLAY ' Turn autodisplay off.

    font = _LOADFONT("lucon.ttf", 20, "monospace")
    IF font <= 0 THEN font = 16
    _FONT font

    bxy% = 3
    bxx% = 13
    COLOR DarkOrange, 0
    t$ = " " + CHR$(218) + STRING$(27, CHR$(196)) + CHR$(191) + " "
    PSL bxy%, bxx% - 1, t$
    FOR i = 1 TO 12
        t$ = " " + CHR$(179) + STRING$(27, CHR$(32)) + CHR$(179) + " "
        PSL bxy% + i, bxx% - 1, t$
    NEXT
    t$ = " " + CHR$(192) + STRING$(27, CHR$(196)) + CHR$(217) + " "
    PSL bxy% + i, bxx% - 1, t$

    bxy% = 4
    COLOR Black, DarkOrange
    t$ = "    NAME  SCORE    DATE  "
    PSL bxy% + 1, bxx% + 1, t$

    COLOR DarkOrange, 0
    FOR i = 1 TO 5
        t$ = hsdata$(i)
        PSL bxy% + 1 + i * 2, bxx% + 2, t$
    NEXT

    _DISPLAY

    RETURN

    hiscore:
    FOR i = 1 TO 5
        IF VAL(score$) > VAL(highscore$(i)) THEN rank = i: EXIT FOR
    NEXT

    hsdata$(6) = SPACE$(25)
    MID$(hsdata$(6), 10, 6) = score$
    MID$(hsdata$(6), 18, 8) = MID$(DATE$, 1, 6) + MID$(DATE$, 9, 2)
    highscore$(6) = score$
    FOR i = 1 TO 6
        FOR j = 1 TO 6
            IF i <> j THEN
                IF VAL(highscore$(i)) > VAL(highscore$(j)) THEN
                    SWAP highscore$(i), highscore$(j)
                    SWAP hsdata$(i), hsdata$(j)
                END IF
            END IF
        NEXT
    NEXT
    FOR i = 1 TO 5
        MID$(hsdata$(i), 1, 2) = "0" + LTRIM$(STR$(i))
    NEXT

    RETURN

END SUB

Pete
Reply
#14
Thumbs Up 
Thank you for this. I went further so the program accepted "2" or "3" at the command line, to be passed to the new subprogram.
Reply




Users browsing this thread: 3 Guest(s)