Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Tile Based RTS landscape thingy
#1
I'm making an RTS engine, hopefully with randomly generated landscapes. It's very very early days, just a simple map generator so far, just curious on how it runs on other hardware and if anyone has a flicker problem. Attachment required.

Use the mouse to scroll the landscape. Arrow keys also work. Use W and S to zoom in and out. Click to select a tile.

Code: (Select All)
REM RTS Engine
REM DP 2022
REM 0.1

REM icon, version info and error handler
ON ERROR GOTO errorhandler
LET consolelog$ = "data\consolelog.txt": REM sets console log file location
$EXEICON:'data\icon.ico'
_ICON

setup:
REM setup
LET setupboot = 1
REM timer
RANDOMIZE TIMER
LET itime = TIMER: REM timer function
LET ctime = 0: REM timer function
REM check os
IF INSTR(_OS$, "[WINDOWS]") THEN LET ros$ = "win"
IF INSTR(_OS$, "[LINUX]") THEN LET ros$ = "lnx"
IF INSTR(_OS$, "[MACOSX]") THEN LET ros$ = "mac"
REM check metadata exists, checks developer console settings and load engine values
IF _FILEEXISTS("data\engine.ddf") THEN
    OPEN "data\engine.ddf" FOR INPUT AS #1
    INPUT #1, devmode, displayconsole, consolelogging, title$, resx, resy, chunksizex, chunksizey, chunktotalx, chunktotaly, zoomscale, maxchunksizex, maxchunksizey, minchunksizex, minchunksizey, hertz, scrollspeed, selectboxblink, selectboxsize
    CLOSE #1
    IF ros$ = "win" THEN
        REM finds metadata directory paths (windoze)
        IF _FILEEXISTS("data\filelocwin.ddf") THEN
            OPEN "data\filelocwin.ddf" FOR INPUT AS #1
            INPUT #1, dloc$, sloc$, aloc$, cloc$, uiloc$, unitloc$, bloc$
            CLOSE #1
        ELSE
            ERROR 420
        END IF
    ELSE
        REM finds metadata directory paths (mac + linux)
        IF _FILEEXISTS("data\filelocother.ddf") THEN
            OPEN "data\filelocother.ddf" FOR INPUT AS #1
            INPUT #1, dloc$, sloc$, aloc$, cloc$, uiloc$, unitloc$, bloc$
            CLOSE #1
        ELSE
            ERROR 420
        END IF
    END IF
    $CONSOLE
    IF displayconsole = 1 THEN
        _CONSOLE ON
        IF title$ <> "" THEN
            _CONSOLETITLE title$ + " Console"
        ELSE
            _CONSOLETITLE "RTS ENGINE Console"
        END IF
    END IF
    IF displayconsole = 0 THEN _CONSOLE OFF
    REM reports system info to console
    LET eventtitle$ = "RTS ENGINE BOOTED"
    LET eventdata$ = ""
    LET eventnumber = 0
    GOSUB consoleprinter
    LET eventtitle$ = "OPERATING SYSTEM DETECTED:"
    IF ros$ = "win" THEN LET eventdata$ = "Microsoft Windows"
    IF ros$ = "lnx" THEN LET eventdata$ = "Linux"
    IF ros$ = "mac" THEN LET eventdata$ = "Apple macOS"
    LET eventnumber = 0
    GOSUB consoleprinter
    LET eventtitle$ = "LOADED METADATA:"
    LET eventdata$ = dloc$ + "engine.ddf"
    LET eventnumber = 0
    GOSUB consoleprinter
ELSE
    ERROR 420: REM error if directory unavailable
END IF
GOSUB screenload
_MOUSESHOW "CROSSHAIR"
GOSUB assetload
GOSUB dimmer
GOSUB menugenerator
LET setupboot = 0
GOTO game

dimmer:
REM assigns array values
LET chunktotal = chunktotalx * chunktotaly
DIM chunktype(chunktotal) AS INTEGER
DIM chunkgenerator(chunktotal) AS INTEGER
DIM chunkdata1(chunktotal) AS INTEGER
DIM chunkdata2(chunktotal) AS INTEGER
REM prints to console
LET eventtitle$ = "ARRAY VALUES ASSIGNED"
LET eventdata$ = ""
LET eventnumber = 0
GOSUB consoleprinter
RETURN

drawhud:
REM display controls / info
REM temp info box
IF selectedchunk > 0 THEN
IF chunktype(selectedchunk) = 1 THEN LET selectedchunkname$ = "Sand"
IF chunktype(selectedchunk) = 2 THEN LET selectedchunkname$ = "Rock"
IF chunktype(selectedchunk) = 3 THEN LET selectedchunkname$ = "Spice"
IF selectedchunkname$ <> "" THEN _PRINTSTRING(1, 1), selectedchunkname$
END IF
IF selectedchunk > 0 THEN GOSUB drawselectbox
RETURN

drawselectbox:
REM draws selectbox
LET drawposx = 0
LET drawposy = 0
FOR x = 1 TO chunktotal
REM detects if selextbox is on screen
IF camerax =< drawposx AND camerax =< (drawposx + resx) THEN LET drawpassx1 = 1
IF cameray =< (drawposy + chunksizey) AND cameray =< (drawposy + resy) THEN LET drawpassy1 = 1
IF (drawposx - chunksizex) <= (camerax + resx) THEN LET drawpassx2 = 1
IF drawposy <= (cameray + resy) ThEN LET drawpassy2 = 1
LET drawpasstotal = drawpassx1 + drawpassx2 + drawpassy1 + drawpassy2
REM draws selected chunk and select box if on screen
IF selectedchunk = x AND chunktype(selectedchunk) = 1 AND drawpasstotal = 4 THEN
REM sand chunk
_PUTIMAGE ((drawposx - camerax), (drawposy - cameray))-((drawposx - chunksizex) - camerax, (drawposy + chunksizey) - cameray), sandchunk
END IF
IF selectedchunk = x AND chunktype(selectedchunk) = 2 AND drawpasstotal = 4 THEN
REM rock chunk
_PUTIMAGE ((drawposx - camerax), (drawposy - cameray))-((drawposx - chunksizex) - camerax, (drawposy + chunksizey) - cameray), rockchunk
END IF
IF selectedchunk = x AND chunktype(selectedchunk) = 3 AND drawpasstotal = 4 THEN
REM spice chunk
_PUTIMAGE ((drawposx - camerax), (drawposy - cameray))-((drawposx - chunksizex) - camerax, (drawposy + chunksizey) - cameray), spicechunk
END IF
IF selectedchunk = x AND drawpasstotal = 4 THEN
REM select box
FOR y = 1 TO selectboxsize STEP zoomscale
LINE (((drawposx - camerax) - y), (drawposy - cameray) + (y - 1))-(((drawposx - chunksizex) - camerax) + (y - 1), ((drawposy + chunksizey) - cameray) - y), _RGBA(40, 250, 53, selectboxalpha), B
NEXT y
END IF
LET drawposx = drawposx + chunksizex
IF drawposx > ((chunksizex * chunktotalx) - chunksizex) THEN
LET drawposx = 0
LET drawposy = drawposy + chunksizey
END IF
LET drawpassx1 = 0
LET drawpassy1 = 0
LET drawpassx2 = 0
LET drawpassy2 = 0
LET drawpasstotal = 0
NEXT x
RETURN

assetload:
REM loads game assets
LET spicechunk = _LOADIMAGE(cloc$ + "spicechunk.png")
LET sandchunk = _LOADIMAGE(cloc$ + "sandchunk.png")
LET rockchunk = _LOADIMAGE(cloc$ + "rockchunk.png")
LET turbine = _LOADIMAGE(bloc$ + "turbine.png")
REM print to console
LET eventtitle$ = "GAME ASSETS LOADED"
LET eventdata$ = ""
LET eventnumber = 0
GOSUB consoleprinter
RETURN

assetunload:
REM unloads game assets
_FREEIMAGE spicechunk
_FREEIMAGE sandchunk
_FREEIMAGE rockchunk
_FREEIMAGE turbine
REM print to console
LET eventtitle$ = "GAME ASSETS UNLOADED"
LET eventdata$ = ""
LET eventnumber = 0
GOSUB consoleprinter
RETURN

savegame:
REM saves game
IF setupboot = 1 THEN
REM divert for if no game is available to be saved
LET eventtitle$ = "NO GAME AVAILABLE TO SAVE"
LET eventdata$ = sloc$ + "savedata.ddf"
LET eventnumber = frames
GOSUB consoleprinter
RETURN
END IF
OPEN sloc$ + "savedata.ddf" FOR OUTPUT AS #666
FOR x = 1 TO chunktotal
WRITE #666, chunktype(x), chunkdata1(x), chunkdata2(x)
NEXT x
WRITE #666, camerax, cameray, chunksizex, chunksizey, selectedchunk
CLOSE #666
REM prints to console
LET eventtitle$ = "GAME SAVED"
LET eventdata$ = sloc$ + "savedata.ddf"
LET eventnumber = frames
GOSUB consoleprinter
RETURN

loadgame:
REM loads game
REM checks if save file is available
IF _FILEEXISTS(sloc$ + "savedata.ddf") THEN
REM nothing
ELSE
LET eventtitle$ = "NO SAVE DATA FOUND"
LET eventdata$ = sloc$ + "savedata.ddf"
LET eventnumber = 0
GOSUB consoleprinter
RETURN
END IF
REM loads save file
OPEN sloc$ + "savedata.ddf" FOR INPUT AS #666
FOR x = 1 TO chunktotal
INPUT #666, chunktype(x), chunkdata1(x), chunkdata2(x)
NEXT x
INPUT #666, camerax, cameray, chunksizex, chunksizey, selectedchunk
CLOSE #666
REM prints to console
LET eventtitle$ = "GAME LOADED"
LET eventdata$ = sloc$ + "savedata.ddf"
LET eventnumber = frames
GOSUB consoleprinter
IF setupboot = 1 THEN LET setupboot = 0: GOTO game: REM launches game if loading from first boot
RETURN

generatelandscape:
REM generates landscape
PRINT "GENRATING LANDSCAPE..."
FOR x = 1 TO chunktotal
LET chunkgenerator(x) = INT(RND * 100) + 1
IF chunkgenerator(x) <= 60 THEN LET chunktype(x) = 1
IF chunkgenerator(x) > 60 AND chunkgenerator(x) <= 80 THEN LET chunktype(x) = 2
IF chunkgenerator(x) > 80 THEN LET chunktype(x) = 3
NEXT x
LET selectedchunk = -1
LET chunksizex = minchunksizex
LET chunksizey = minchunksizey
LET camerax = 0
LET cameray = 0
REM print to console
LET eventtitle$ = "LANDSCAPE GENERATED"
LET eventdata$ = ""
LET eventnumber = chunktotal
GOSUB consoleprinter
RETURN

consoleprinter:
REM prints extra engine data to console / error log
IF consolelogging = 1 THEN
    IF _FILEEXISTS(consolelog$) THEN
        REM nothing
    ELSE
        OPEN consolelog$ FOR OUTPUT AS #2
        PRINT #2, DATE$, TIME$, "RTS ENGINE CONSOLE LOG"
        CLOSE #2
    END IF
    OPEN consolelog$ FOR APPEND AS #2
    IF eventnumber <> 0 THEN PRINT #2, DATE$, TIME$, eventtitle$, eventdata$; eventnumber
    IF eventnumber = 0 THEN PRINT #2, DATE$, TIME$, eventtitle$, eventdata$
    CLOSE #2
END IF
IF displayconsole = 1 THEN
    REM displays in console
    _DEST _CONSOLE
    IF eventnumber <> 0 THEN PRINT DATE$, TIME$, eventtitle$, eventdata$; eventnumber
    IF eventnumber = 0 THEN PRINT DATE$, TIME$, eventtitle$, eventdata$
    _DEST 0
END IF
REM flush values
LET eventtitle$ = "": LET eventdata$ = "": LET eventnumber = 0
RETURN

errorhandler:
REM handles expected in-game errors
IF ERR = 423 THEN LET errdescription$ = "MISSING SCRIPT FILE - " + scriptname$
IF ERR = 424 THEN LET errdescription$ = "MISSING ANIMATION FILE - " + anifile$
IF ERR = 425 THEN LET errdescription$ = "MISSING TERMINAL FILE - " + runterminal$
IF consolelogging = 1 THEN
    OPEN consolelog$ FOR APPEND AS #2
    IF errdescription$ <> "" THEN
PRINT #2, DATE$, TIME$, "ERROR: "; ERR, "LINE: "; _ERRORLINE, errdescription$
ELSE
PRINT #2, DATE$, TIME$, "ERROR: "; ERR, "LINE: "; _ERRORLINE, UCASE$(_ERRORMESSAGE$)
END IF
    CLOSE #2
END IF
REM PRINTS TO CONSOLE
IF displayconsole = 1 THEN
    _DEST _CONSOLE
    IF errdescription$ <> "" THEN
PRINT DATE$, TIME$, "ERROR: "; ERR, "LINE: "; _ERRORLINE, errdescription$
ELSE
PRINT DATE$, TIME$, "ERROR: "; ERR, "LINE: "; _ERRORLINE, UCASE$(_ERRORMESSAGE$)
END IF
    _DEST 0
END IF
LET errdescription$ = "": REM scrub temp values
IF ERR < 420 THEN RESUME NEXT
REM halts program upon unexpected error
REM == FROM HERE, PROGRAM WILL HALT AND IS CONSIDERED NON-RECOVERABLE ==
ON ERROR GOTO errorduringerror: REM error handler for the error handler (ikr)
IF ERR = 420 THEN LET errdescription$ = "MISSING ENGINE METADATA - TRY REINSTALL"
IF ERR = 421 THEN LET errdescription$ = "MISSING METADATA DIRECTORY - TRY REINSTALL"
IF ERR = 422 THEN LET errdescription$ = "MISSING DEFAULT SAVE FILE - TRY REINSTALL"
IF ERR = 666 THEN LET errdescription$ = "DEMONIC ERROR - CONTACT LOCAL UAC REP"
IF ERR = 999 THEN LET errdescription$ = "UNSUPPORTED OPERATING SYSTEM - LOCATE UNFORKED BUILD"
LET errorcrash = 1: REM sets error crash value to 1
BEEP
PRINT "=== GURU MEDITATION ==="
PRINT DATE$, TIME$
PRINT "ERROR CODE: "; ERR
PRINT "LINE: "; _ERRORLINE
PRINT errdescription$
PRINT
IF title$ <> "" THEN
    PRINT title$; " will now close."
ELSE
    PRINT "RTS ENGINE will now close."
END IF
END

errorduringerror:
REM if error handler encounters an error
BEEP
PRINT "=== SUPER GURU ==="
PRINT "ERROR MANAGER HAS CRASHED!"
PRINT DATE$, TIME$
PRINT "ERROR CODE: "; ERR
PRINT "LINE: "; _ERRORLINE
PRINT errdescription$
PRINT "ERROR INFO WILL NOT BE DUMPED TO FILE."
PRINT
IF title$ <> "" THEN
    PRINT title$; " will now close."
ELSE
    PRINT "RTS ENGINE will now close."
END IF
END

drawlandscape:
REM draws landscape
LET drawposx = 0
LET drawposy = 0
LET chunkdrawcount = 0
FOR x = 1 TO chunktotal
REM detects if chunk is on screen
IF camerax =< drawposx AND camerax =< (drawposx + resx) THEN LET drawpassx1 = 1
IF cameray =< (drawposy + chunksizey) AND cameray =< (drawposy + resy) THEN LET drawpassy1 = 1
IF (drawposx - chunksizex) <= (camerax + resx) THEN LET drawpassx2 = 1
IF drawposy <= (cameray + resy) ThEN LET drawpassy2 = 1
LET drawpasstotal = drawpassx1 + drawpassx2 + drawpassy1 + drawpassy2
REM draws chunk if on screen
IF chunktype(x) = 1 AND drawpasstotal = 4 THEN
REM sand chunk
_PUTIMAGE ((drawposx - camerax), (drawposy - cameray))-((drawposx - chunksizex) - camerax, (drawposy + chunksizey) - cameray), sandchunk
LET chunkdrawcount = chunkdrawcount + 1
END IF
IF chunktype(x) = 2 AND drawpasstotal = 4 THEN
REM rock chunk
_PUTIMAGE ((drawposx - camerax), (drawposy - cameray))-((drawposx - chunksizex) - camerax, (drawposy + chunksizey) - cameray), rockchunk
LET chunkdrawcount = chunkdrawcount + 1
END IF
IF chunktype(x) = 3 AND drawpasstotal = 4 THEN
REM spice chunk
_PUTIMAGE ((drawposx - camerax), (drawposy - cameray))-((drawposx - chunksizex) - camerax, (drawposy + chunksizey) - cameray), spicechunk
LET chunkdrawcount = chunkdrawcount + 1
END IF
LET drawposx = drawposx + chunksizex
IF drawposx > ((chunksizex * chunktotalx) - chunksizex) THEN
LET drawposx = 0
LET drawposy = drawposy + chunksizey
END IF
LET drawpassx1 = 0
LET drawpassy1 = 0
LET drawpassx2 = 0
LET drawpassy2 = 0
LET drawpasstotal = 0
NEXT x
RETURN

screenload:
REM sets screen mode
_TITLE title$
SCREEN _NEWIMAGE(resx, resy, 32)
$RESIZE:STRETCH
IF screenmode = 2 THEN _FULLSCREEN _OFF
IF screenmode = 1 THEN _FULLSCREEN _SQUAREPIXELS
IF devmode = 0 THEN _MOUSEHIDE: REM hides mouse (if devmode is off)
LET eventtitle$ = "SCREEN MODE SET:"
IF screenmode = 2 THEN LET eventdata$ = "windowed"
IF screenmode = 1 THEN LET eventdata$ = "fullscreen"
LET eventnumber = screenmode
GOSUB consoleprinter
RETURN

keyinputter:
REM keyboard input
IF _KEYDOWN(18432) THEN LET cameray = cameray - scrollspeed: LET drawscreen = 1: REM up
IF _KEYDOWN(20480) THEN LET cameray = cameray + scrollspeed: LET drawscreen = 1: REM down
IF _KEYDOWN(19712) THEN LET camerax = camerax + scrollspeed: LET drawscreen = 1: REM right
IF _KEYDOWN(19200) THEN LET camerax = camerax - scrollspeed: LET drawscreen = 1: REM left
IF _KEYDOWN(119) THEN
IF chunksizex <> maxchunksizex AND chunksizey <> maxchunksizey THEN
REM zoom in
REM increase chunk size
LET chunksizex = chunksizex + zoomscale
LET chunksizey = chunksizey + zoomscale
REM pan camera to account for chunk size change
LET camerax = camerax + INT((camerax / chunksizex) * zoomscale)
LET cameray = cameray + INT((cameray / chunksizey) * zoomscale)
LET drawscreen = 1
END IF
END IF
IF _KEYDOWN(115) THEN
IF chunksizex <> minchunksizex AND chunksizey <> minchunksizey THEN
REM zoom out
REM decrease chunk size
LET chunksizex = chunksizex - zoomscale
LET chunksizey = chunksizey - zoomscale
REM pan camera to account for chunk size change
LET camerax = camerax - INT((camerax / chunksizex) * zoomscale)
LET cameray = cameray - INT((cameray / chunksizey) * zoomscale)
LET drawscreen = 1
END IF
END IF
IF UCASE$(b$) = "Q" THEN GOSUB menugenerator
IF UCASE$(b$) = "I" THEN GOSUB dropbuilding
LET temp = 0: REM clears temp values
RETURN

dropbuilding:
REM enables a building to drop onto the map
REM temp building selector
LET dropmode = 1
INPUT "TYPE OF BUILDING: "; x
LET builddroptype = x
IF builddroptype = 1 THEN LET builddropname$ = "turbine"
REM loads building metadata
OPEN bloc$ + builddropname$ + ".ddf" FOR INPUT AS #1
INPUT #1, dummy$, builddropsizex, builddropsizey
CLOSE #1
REM main drop loop
LET drawscreen = 1
_MOUSESHOW "LINK"
DO
LET invaliddrop = 0
_LIMIT hertz
REM captures mouse input
DO WHILE _MOUSEINPUT
LET mousex = _MOUSEX
LET mousey = _MOUSEY
LET leftclick = _MOUSEBUTTON (1)
LET rightclick = _MOUSEBUTTON (2)
LET scrollwheel = scrollwheel + _MOUSEWHEEL
LOOP
REM draw existsing landscape
IF drawscreen = 1 THEN GOSUB drawlandscape
GOSUB timeframecounter: REM time keeper
REM draws drop building
LET pointerx = INT((mousex + camerax) / chunksizex)
LET pointery = INT((mousey + cameray) / chunksizey)
LET pointerx = pointerx + 2: REM some weird correction i dont understand yet
LET selectedchunk = pointerx + (pointery * chunktotalx)
IF oldselectedchunk = selectedchunk THEN
LET drawscreen = 0
ELSE
LET drawscreen = 1
END IF
LET drawposx = 0
LET drawposy = 0
FOR x = 1 TO chunktotal
IF selectedchunk = x THEN
LET oldselectedchunk = selectedchunk
REM checks if build location is valid
FOR y = 0 TO builddropsizex
FOR v = 0 TO buildropsizey
IF chunktype((chunktotalx * v) + (selectedchunk - y)) = 2 THEN LET invaliddrop = 1
NEXT v
NEXT y
REM building image
_PUTIMAGE (((drawposx - camerax) - y), (drawposy - cameray) + (y - 1))-(((drawposx - (chunksizex * builddropsizex)) - camerax) + (y - 1), ((drawposy + (chunksizey * builddropsizey)) - cameray) - y), turbine
REM select box
FOR y = 1 TO selectboxsize STEP zoomscale
IF invaliddrop = 1 THEN
LINE (((drawposx - camerax) - y), (drawposy - cameray) + (y - 1))-(((drawposx - (chunksizex * builddropsizex)) - camerax) + (y - 1), ((drawposy + (chunksizey * builddropsizey)) - cameray) - y), _RGBA(255, 0, 0, selectboxalpha), B: REM ivalid location select box
ELSE
LINE (((drawposx - camerax) - y), (drawposy - cameray) + (y - 1))-(((drawposx - (chunksizex * builddropsizex)) - camerax) + (y - 1), ((drawposy + (chunksizey * builddropsizey)) - cameray) - y), _RGBA(40, 250, 53, selectboxalpha), B: REM valid location select box
END IF
NEXT y
END IF
LET drawposx = drawposx + chunksizex
IF drawposx > ((chunksizex * chunktotalx) - chunksizex) THEN
LET drawposx = 0
LET drawposy = drawposy + chunksizey
END IF
NEXT x
LOOP
_MOUSESHOW "CROSSHAIR"
RETURN

menugenerator:
REM temp menugenerator
CLS
LOCATE 1, 1: PRINT "1) NEW GAME"
LOCATE 2, 1: PRINT "2) LOAD GAME"
LOCATE 3, 1: PRINT "3) SAVE GAME"
LOCATE 4, 1: PRINT "4) SCREEN MODE"
LOCATE 5, 1: PRINT "5) QUIT"
IF setupboot = 0 THEN LOCATE 6, 1: PRINT "6) RESUME GAME"
REM print to console
LET eventtitle$ = "MAIN MENU LOADED"
LET eventdata$ = ""
LET eventnumber = 0
GOSUB consoleprinter
INPUT x
IF x = 1 THEN LET x = 0: GOSUB generatelandscape: RETURN
IF x = 2 THEN LET x = 0: GOSUB loadgame
IF x = 3 THEN LET x = 0: GOSUB savegame
IF x = 4 THEN PRINT "COMING SOON!": _DELAY 2
IF x = 5 THEN LET x = 0: GOTO endgame
IF setupboot = 0 THEN IF x = 6 THEN LET x = 0: RETURN
GOTO menugenerator

endgame:
REM quits the game
REM prints to console
LET eventtitle$ = "SYSTEM QUIT REQUESTED"
LET eventdata$ = "frames:"
LET eventnumber = frames
GOSUB consoleprinter
REM unloads game assets
GOSUB assetunload
REM prints to console
LET eventtitle$ = "RTS ENGINE CLOSED"
LET eventdata$ = ""
LET eventnumber = 0
GOSUB consoleprinter
SYSTEM

mapcollision:
REM keeps map on screen
REM zoom
REM zoom out
IF chunksizex < minchunksizex THEN LET chunksizex = minchunksizex
IF chunksizey < minchunksizey THEN LET chunksizey = minchunksizey
REM zoom in
IF chunksizex > maxchunksizex THEN LET chunksizex = maxchunksizex
IF chunksizey > maxchunksizey THEN LET chunksizey = maxchunksizey
REM camera
IF camerax < 0 THEN LET camerax = 0
IF cameray < 0 THEN LET cameray = 0
IF camerax > ((chunksizex * (chunktotalx - 1)) - resx) THEN LET camerax = (chunksizex * (chunktotalx - 1)) - resx
IF cameray > ((chunksizey * chunktotaly) - resy) THEN LET cameray = (chunksizey * chunktotaly) - resy
RETURN

mouseinputter:
REM mouse input
DO WHILE _MOUSEINPUT
LET mousex = _MOUSEX
LET mousey = _MOUSEY
LET leftclick = _MOUSEBUTTON (1)
LET rightclick = _MOUSEBUTTON (2)
LET scrollwheel = scrollwheel + _MOUSEWHEEL
LOOP
IF mousex >= (resx - 10) THEN LET camerax = camerax + scrollspeed: LET drawscreen = 1
IF mousey >= (resy - 10) THEN LET cameray = cameray + scrollspeed: LET drawscreen = 1
IF mousex <= 10 THEN LET camerax = camerax - scrollspeed: LET drawscreen = 1
IF mousey <= 10 THEN LET cameray = cameray - scrollspeed: LET drawscreen = 1
IF leftclick = -1 THEN
REM click to select
LET pointerx = INT((mousex + camerax) / chunksizex)
LET pointery = INT((mousey + cameray) / chunksizey)
LET pointerx = pointerx + 2: REM some weird correction i dont understand yet
LET selectedchunk = pointerx + (pointery * chunktotalx)
LET selectboxalpha = 255: REM sets select box to to visible
LET selectboxalphadirection = 1: REM sets select box to fade out
REM prints to console
LET eventtitle$ = "CHUNK SELECTED"
LET eventdata$ = "X: " + STR$(pointerx) + " Y: " + STR$(pointery) + " type:"
LET eventnumber = chunktype(selectedchunk)
GOSUB consoleprinter
LET leftclick = 0
LET drawscreen = 1
END IF
LET scrollwheel = 0
RETURN

timeframecounter:
REM time + frame counter
IF _EXIT THEN GOTO endgame: REM ends game on window close
IF TIMER < 0 OR ctime < 0 THEN
    REM resets timer when value wraparound occurs
    RANDOMIZE TIMER
    LET itime = TIMER
    IF ctime > 0 THEN
        LET eventtitle$ = "TIMER RESET:"
    ELSE
        LET eventtitle$ = "COUNTER RESET:"
    END IF
    LET eventdata$ = TIME$
    LET eventnumber = frames
    GOSUB consoleprinter
END IF
REM timer keeper
LET ctime = (TIMER - itime): REM time keeper
LET frames = frames + 1: REM frame counter
REM select box fade
IF selectboxblink > 0 THEN
IF selectboxalphadirection = 1 THEN LET selectboxalpha = selectboxalpha - selectboxblink
IF selectboxalphadirection = 2 THEN LET selectboxalpha = selectboxalpha + selectboxblink
IF selectboxalpha =< 0 THEN LET selectboxalphadirection = 2
IF selectboxalpha => 255 THEN LET selectboxalphadirection = 1
END IF
REM calculate fps
LET temp7 = temp7 + 1
IF temp8 + 1 < ctime THEN
    LET fps = temp7
    LET temp7 = 0: REM scrub temp values
    LET temp8 = ctime: REM reset temp values
END IF
RETURN

game:
REM game loop
_MOUSEMOVE 20, 20
LET frames = 0
REM prints to console
LET eventtitle$ = "ENGINE LOOP STARTED"
LET eventdata$ = ""
LET eventnumber = 0
LET drawscreen = 1
GOSUB consoleprinter
DO
_LIMIT hertz
LET b$ = INKEY$
IF drawscreen = 1 THEN GOSUB drawlandscape: LET drawscreen = 0
GOSUB drawhud
GOSUB keyinputter
GOSUB mouseinputter
GOSUB mapcollision
GOSUB timeframecounter
LOOP


Attached Files
.zip   data.zip (Size: 35.79 KB / Downloads: 63)
Reply
#2
Cool work.
No flicker as such, but when scrolling it pauses, just for an eyeblink's worth of time, about every half-second or so, on my machine (Core i5 2500K @ 3.3GHz, NVIDIA GeForce 8400GS, Win 7 Pro 64-bit).
Reply
#3
(05-06-2022, 04:39 PM)JRace Wrote: Cool work.
No flicker as such, but when scrolling it pauses, just for an eyeblink's worth of time, about every half-second or so, on my machine (Core i5 2500K @ 3.3GHz, NVIDIA GeForce 8400GS, Win 7 Pro 64-bit).

Thanks for taking a look Smile ill look into that scrolling pause.
Reply




Users browsing this thread: 1 Guest(s)