Nice! That worked in Firefox.
Mon Mar 08, 2021 6:29pm

That's really cool! I never would have thought to make a ASCII style game like this in Javascript. I would totally play a full fledged game that was done like that.

Your screen drawing is similar to how I'm doing it. My 2d array just is a TILE type instead of straight integers so it can hold other values like foreground color, background color, teleport id, ASCII character code and isBlocking in a single x/y coordinate. (Or y/x in my case because I based it off the LOCATE command..)

Here's what my DrawPlayfield sub looks like:
SUB DrawPlayfield (player AS ACTOR)

    DIM charToDraw AS INTEGER
    DIM charColor AS INTEGER
    DIM bgColor AS INTEGER

    LOCATE 18, 1
    COLOR 7, 0
    PRINT "p.x: "; player.x; " p.y: "; player.y%

    LOCATE 19, 1
    PRINT "Free: "; FRE(-2)

    playerDrawX% = getPlayerDrawX%(player)
    playerDrawY% = getPlayerDrawY%(player)

    'SCRMAXY & SCRMAXX are max playfield size constants on the screen. Currently they're x=20 & y=15
    FOR y% = 1 TO SCRMAXY

        FOR x% = 1 TO SCRMAXX

            mapOffsetX% = x% + player.x - playerDrawX%
            mapOffsetY% = y% + player.y - playerDrawY%

            bgColor = 0
            IF mapOffsetX% <= UBOUND(map, 2) AND mapOffsetY% <= UBOUND(map, 1) THEN
                bgColor = map(mapOffsetY%, mapOffsetX%).bg
                IF x% = playerDrawX% AND y% = playerDrawY% THEN
                    charToDraw = player.char
                    charColor = player.c
                    charToDraw = map(mapOffsetY%, mapOffsetX%).char
                    charColor = map(mapOffsetY%, mapOffsetX%).fg
                END IF

            ELSE 'draw red hearts in out of bounds area
                charToDraw = 3
                charColor = 4

            END IF
            LOCATE y%, x%
            COLOR charColor, bgColor
            PRINT CHR$(charToDraw)
        NEXT x%
    NEXT y%


These are what the playerDrawX/Y functions look like. They just handle setting the player closer to the edge as they approach the inner edges of the map:

FUNCTION getPlayerDrawX% (player AS ACTOR)

    IF player.x < playerDrawX% THEN
        playerDrawX% = player.x
    END IF
    getPlayerDrawX% = playerDrawX%


FUNCTION getPlayerDrawY% (player AS ACTOR)

    IF player.y < playerDrawY% THEN
        playerDrawY% = player.y
    END IF

    getPlayerDrawY% = playerDrawY%


Mine still requires having a larger sized map to move around in instead of stitching multiple maps together. So far speed hasn't been an issue on my 486 or DOSBox running on lower cycles. I built an editor to create the maps which makes generating the data much easier as the maps are saved in binary using BSAVE/BLOAD to just copy the memory to disk and load it back up. (TILE type and other shared type declarations are shared between editor and game in a QBL so I don't have to worry about incompatible types when loading/saving from one to the other)

    • Kind of got something working... - Retna, Sun Mar 07 2021 10:12pm
      Still need to figure out how to move the viewport based on the characters position. And also how to stitch the two areas together. Should be able to copy and paste this into your browser console on newer browsers. document.write(` <html> <head> <style> body { overflow:hid... more
      • Started working on the same game using COBOL... - Erik_, Sun Mar 14 2021 3:32am
        Being that COBOL is more my programming language of interest outside of work lately, I decided I'd try to make the QB game in GnuCOBOL instead. So far, I don't have the area scrolling like I do in the QB version. It's just a full map view for now. (I'll be working on that next). This is defini... more
        • Got the scrolling working now. - Erik_, Wed Mar 17 2021 5:28pm
          Looping gif example:
          • Sweet! - Retna, Wed Mar 17 2021 9:43pm
            Do you scroll the viewport and the player position at the same time when they press the direction? I might try doing that too...
            • This is the second time of me writing this after clearing... I guess that's definitely a sign it needs to be rewritten. :) * Player position holds x/y coordinates on the tile map. * Screen is drawn based on player xy as the starting point and drawn until it reaches the defined screen width and ... more
              • I removed the "if player's position in the x/y is less than so and so" and just made the player's screen position constant. I was having a weird issue where as you approached 1,1 on the map, you would move 2 tiles instead of one. The new way fixes this. To get the player's map position, I just ne... more
      • Nice! That worked in Firefox.- Erik_, Mon Mar 08 2021 6:29pm
        • Having a tile type could be a good way to define define more things the player can interact with. Like a chest or a door that can be open or closed.
          • and then having some TileHandler or something that defines the action based performed based on the tile type. I guess you would also need some sort of id or something to specify that it was, for example, a specific treasure chest on this specific map? Currently, the only different tile type I hav... more
  • Click here to receive daily updates
    "Forces act when not restrained" - Puckdropper