Robot floor painter
#1
Smile 
This is a silly program that could almost be used as screensaver. It needs music LOL, so it's better.

I derrived the idea from a book on programming games in GW-BASIC by David L. Heiserman (had to look it up), but it's not the book being sold on Amazon that readily comes up in the searches. I think it was called "101 Games In BASIC" or alike. The programs weren't all games; some of them did silly things on the screen. My favorite from them was the "Hacker's Aid". I made my own version with fancy text-graphics and with beeping from "SOUND". It even emulated dial-tone telephone and ringing LOL.

Honorable mention was the "Surrogate Cusser" which could have gotten boring quickly. Fiddlesticks!

I don't remember very well but there might have been a version of that book for the Radio Shack TRS-80 Color Computer, or for the Model III which was incapable of sound. Instead of sound it had a subroutine that "blinked" a short message on the screen. That was its favorite trick.

This program has the "robot" moving in a different way from the old program it was derrived from. It has a quirk not found in the old program.

Code: (Select All)
'by mnrvovrfc 8-May-2023
OPTION _EXPLICIT

DIM AS LONG scren
DIM AS INTEGER px, py, xi, yi, xn, yn, xx, yy, c, l, nivel
DIM AS _UNSIGNED _BYTE redo

RANDOMIZE TIMER

scren = _NEWIMAGE(120, 31, 0)
SCREEN scren
_DELAY 0.5
_SCREENMOVE 0, 0
_TITLE "Press [ESC] to quit."

nivel = 1
px = Random1(100) + 10
py = Random1(29) + 1
xi = (Random1(2) - 1) * 2 - 1
yi = (Random1(2) - 1) * 2 - 1
xn = nivel
yn = nivel
c = 0
l = Random1(8) + 4
redo = 0

DO
    _LIMIT 100
    IF redo THEN
        redo = 0
    ELSE
        outchar px, py, 219, 0
    END IF
    px = px + xi * xn
    py = py + yi * yn
    IF px < 1 OR px > 120 THEN
        px = px - xi * xn
        py = py - yi * yn
        redo = 1
    END IF
    IF py < 1 OR py > 30 THEN
        px = px - xi * xn
        py = py - yi * yn
        IF nivel > 1 THEN nivel = nivel - 1
        IF Random1(2) = 1 AND xn > 1 THEN xn = xn - 1
        IF Random1(2) = 1 AND yn > 1 THEN yn = yn - 1
        redo = 1
    END IF
    IF redo = 0 THEN
        IF SCREEN(py, px) = 219 THEN
            px = px - xi * xn
            py = py - yi * yn
            IF c < l THEN
                IF Random1(2) = 1 THEN
                    xn = nivel
                    IF xn > 40 THEN xn = 40
                ELSEIF Random1(2) = 1 THEN
                    yn = nivel
                    IF yn > 16 THEN yn = 16
                ELSE
                    nivel = nivel + 1
                    IF nivel > 50 THEN
                        nivel = 1
                        FOR yy = 1 TO 30
                            FOR xx = 1 TO 120
                                outchar xx, yy, 32, 219
                            NEXT
                        NEXT
                    END IF
                END IF
            END IF
        END IF
        c = c + 1
        IF c > l THEN
            outchar px, py, 219, 0
            IF nivel > 1 THEN nivel = nivel - 1
            IF Random1(2) = 1 AND xn > 1 THEN xn = xn - 1
            IF Random1(2) = 1 AND yn > 1 THEN yn = yn - 1
            redo = 1
        END IF
    END IF
    IF redo THEN
        xi = (Random1(2) - 1) * 2 - 1
        yi = (Random1(2) - 1) * 2 - 1
        c = 0
        l = Random1(8) + 4
    ELSE
        outchar px, py, 82, 0
        _DISPLAY
    END IF
LOOP UNTIL _KEYDOWN(27)

_AUTODISPLAY
SYSTEM

SUB outchar (x AS INTEGER, y AS INTEGER, ca AS _UNSIGNED _BYTE, cb AS _UNSIGNED _BYTE)
    STATIC sch AS _UNSIGNED _BYTE
    IF cb THEN
        sch = SCREEN(y, x)
        IF sch = cb THEN sch = ca ELSE sch = cb
    ELSE
        sch = ca
    END IF
    LOCATE y, x: PRINT CHR$(sch);
END SUB

FUNCTION Random1& (maxvaluu&)
    DIM sg%
    sg% = SGN(maxvaluu&)
    IF sg% = 0 THEN
        Random1& = 0
    ELSE
        IF sg% = -1 THEN maxvaluu& = maxvaluu& * -1
        Random1& = INT(RND * maxvaluu& + 1) * sg%
    END IF
END FUNCTION
Reply


Messages In This Thread
Robot floor painter - by mnrvovrfc - 05-08-2023, 10:39 PM
RE: Robot floor painter - by bplus - 05-09-2023, 01:30 AM
RE: Robot floor painter - by bplus - 05-09-2023, 01:41 AM



Users browsing this thread: 3 Guest(s)