Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Dream Hacking - qb45 text game converted into QB64
#1
hi this is my qb45 game i coded while back i converted it to qb64 - and it works

The game is called "dream hacking", music from modarchive.org. What's it about? Well, each night you try to access the "dream terminal" to hack your dream into "alpha state" and feel bliss. However, messing around with dream hacking too much, and your mental state goes down - I modified the game to use my new nick here - solo88 instead of my old one (i was hoping to have an option to change my display nickname in the user control panel, but there seems not to be any)

Here are a few screenshots of the game:
[Image: צילום_מסך_2025_11_25_140658.png]

[Image: zylwm-msk-2025-11-25-140734.png]

[Image: zylwm-msk-2025-11-25-140752.png]

Now let's upload the game zip folder (without executable) with just the source files:


.zip   DREAM64.zip (Size: 4.31 MB / Downloads: 26)

The game is not much, I admit. You play and try to play till you get bored, and you exit - there is no "good or bad" ending.

Thank you very much - will be happy for feedback - I hope to return to coding in QB64/QB64pe. 

solo88 (previously ron77)
aka ron77
Reply
#2
The artwork of that intro screen you posted looks beautiful, Ron.
The noticing will continue
Reply
#3
I asked Gemini 3 to update your code to use $EMBED and _EMBEDDED$ to store all the assets within the game executable. It seems to play fine.

Code: (Select All)
' ===================================================
' DREAM HACKING (Modernized for QB64PE)
' Now fully portable using $EMBED and _EMBEDDED$
' ===================================================

' --- EMBEDDED ASSETS ---
' Text Files - Days
$EMBED:'./DREAM64/DATA/BADAY1.TXT','BADAY1'
$EMBED:'./DREAM64/DATA/BADAY2.TXT','BADAY2'
$EMBED:'./DREAM64/DATA/BADAY3.TXT','BADAY3'
$EMBED:'./DREAM64/DATA/BADAY4.TXT','BADAY4'
$EMBED:'./DREAM64/DATA/BADAY5.TXT','BADAY5'
$EMBED:'./DREAM64/DATA/BADAY6.TXT','BADAY6'
$EMBED:'./DREAM64/DATA/BADAY7.TXT','BADAY7'
$EMBED:'./DREAM64/DATA/GOODAY1.TXT','GOODAY1'
$EMBED:'./DREAM64/DATA/GOODAY2.TXT','GOODAY2'
$EMBED:'./DREAM64/DATA/GOODAY3.TXT','GOODAY3'
$EMBED:'./DREAM64/DATA/GOODAY4.TXT','GOODAY4'
$EMBED:'./DREAM64/DATA/GOODAY5.TXT','GOODAY5'
$EMBED:'./DREAM64/DATA/GOODAY6.TXT','GOODAY6'
$EMBED:'./DREAM64/DATA/GOODAY7.TXT','GOODAY7'

' Text Files - Dreams
$EMBED:'./DREAM64/DATA/REGULAR0.TXT','REGULAR0'
$EMBED:'./DREAM64/DATA/REGULAR1.TXT','REGULAR1'
$EMBED:'./DREAM64/DATA/REGULAR2.TXT','REGULAR2'
$EMBED:'./DREAM64/DATA/REGULAR3.TXT','REGULAR3'
$EMBED:'./DREAM64/DATA/REGULAR4.TXT','REGULAR4'
$EMBED:'./DREAM64/DATA/REGULAR5.TXT','REGULAR5'
$EMBED:'./DREAM64/DATA/REGULAR6.TXT','REGULAR6'
$EMBED:'./DREAM64/DATA/REGULAR7.TXT','REGULAR7'
$EMBED:'./DREAM64/DATA/REGULAR8.TXT','REGULAR8'
$EMBED:'./DREAM64/DATA/REGULAR9.TXT','REGULAR9'

$EMBED:'./DREAM64/DATA/LUCIDE1.TXT','LUCIDE1'
$EMBED:'./DREAM64/DATA/LUCIDE2.TXT','LUCIDE2'
$EMBED:'./DREAM64/DATA/LUCIDE3.TXT','LUCIDE3'
$EMBED:'./DREAM64/DATA/LUCIDE4.TXT','LUCIDE4'
$EMBED:'./DREAM64/DATA/LUCIDE5.TXT','LUCIDE5'
$EMBED:'./DREAM64/DATA/LUCIDE6.TXT','LUCIDE6'
$EMBED:'./DREAM64/DATA/LUCIDE7.TXT','LUCIDE7'
$EMBED:'./DREAM64/DATA/LUCIDE8.TXT','LUCIDE8'
$EMBED:'./DREAM64/DATA/LUCIDE9.TXT','LUCIDE9'
$EMBED:'./DREAM64/DATA/LUCIDE10.TXT','LUCIDE10'

$EMBED:'./DREAM64/DATA/MARE1.TXT','MARE1'
$EMBED:'./DREAM64/DATA/MARE2.TXT','MARE2'
$EMBED:'./DREAM64/DATA/MARE3.TXT','MARE3'
$EMBED:'./DREAM64/DATA/MARE4.TXT','MARE4'
$EMBED:'./DREAM64/DATA/MARE5.TXT','MARE5'
$EMBED:'./DREAM64/DATA/MARE6.TXT','MARE6'
$EMBED:'./DREAM64/DATA/MARE7.TXT','MARE7'
$EMBED:'./DREAM64/DATA/MARE8.TXT','MARE8'
$EMBED:'./DREAM64/DATA/MARE9.TXT','MARE9'
$EMBED:'./DREAM64/DATA/MARE10.TXT','MARE10'

' Text Files - Misc
$EMBED:'./DREAM64/DATA/START1.TXT','START1'
$EMBED:'./DREAM64/DATA/CREDITS.TXT','CREDITS'
$EMBED:'./DREAM64/DATA/DOCTOR1.TXT','DOCTOR1'
$EMBED:'./DREAM64/DATA/HOSPITAL.TXT','HOSPITAL'

' Sounds
$EMBED:'./DREAM64/SOUND/aa_siren.wav','AASIREN'
$EMBED:'./DREAM64/SOUND/achmed.wav','ACHMED'

' Images
$EMBED:'./DREAM64/IMGS/IMG24.BMQ','IMG24'
$EMBED:'./DREAM64/IMGS/img256.bmp','IMG256'
$EMBED:'./DREAM64/IMGS/title1.bmp','TITLE1'


DECLARE SUB ScrollCredits (handle$)
DECLARE SUB LucideDream ()
DECLARE SUB NightMares ()

Rem $DYNAMIC

DECLARE SUB MainLoop ()
DECLARE SUB DayTime ()
DECLARE SUB AccessTerminal ()
DECLARE SUB RegularDream ()
DECLARE FUNCTION RandomGenerator% (num!)
DECLARE FUNCTION GetKey$ (keysToCatch$)
DECLARE FUNCTION ShowMatrixMenu% ()
DECLARE SUB sleepex2 ()
DECLARE SUB DreamTerminal ()
DECLARE SUB LucideDreamGen ()
DECLARE SUB LoadBMPQ (handle AS STRING)
DECLARE SUB CheckCollisions ()
DECLARE SUB DrawGround ()
DECLARE SUB DrawObstacles ()
DECLARE SUB DrawScreen ()
DECLARE SUB UpdatePlayer ()
DECLARE SUB UpdateObstacles ()
DECLARE SUB GameOver ()
DECLARE SUB InitializeGame ()

DECLARE FUNCTION Replace$ (sInput AS STRING, sFind AS STRING, sReplace AS STRING)
DECLARE SUB Flying (musicHandle$)
DECLARE FUNCTION LightAnimation% ()
DECLARE SUB TerminalAnimation ()
DECLARE SUB sleepex ()
DECLARE SUB theme (musicHandle$, textHandle$)
DECLARE SUB ReadAndPrintEmbedded (handle$)
DECLARE SUB SoundDeInit ()
DECLARE SUB SoundPlayWav (handle AS STRING)
DECLARE SUB LoadBMP (handle AS STRING)
DECLARE SUB PlayMusic (handle AS STRING)
DECLARE SUB PrintCenter (row AS INTEGER, s AS STRING)
DECLARE FUNCTION GetEmbeddedData$ (handle AS STRING)

' Flying Game variables
Dim Shared playerX As Integer, playerY As Integer
Dim Shared score As Long
Dim Shared lives As Integer
Dim Shared groundRow As Integer
Dim Shared groundPattern As String
Dim Shared groundOffset As Integer
Dim Shared groundLength As Integer
Dim Shared isOver As Integer

' Obstacle arrays
Const maxObstacles = 10
Dim Shared obsType(1 To maxObstacles) As String
Dim Shared obsX(1 To maxObstacles) As Integer
Dim Shared obsY(1 To maxObstacles) As Integer
Dim Shared obsHeight(1 To maxObstacles) As Integer
Dim Shared obsChar(1 To maxObstacles) As String

' Player settings
Dim Shared player As String
player = "=>-=@="

Dim Shared lastWidth As Integer, lastHeight As Integer

' global for sound playing
Dim Shared songLong As Long

'global veriables
Dim Shared LCDCounter As Integer
Dim Shared SanityCounter As Integer
Dim Shared DayCounter As Integer
SanityCounter = 0
DayCounter = 0

'arrays
Dim Shared LDPlaces$(0 To 9)
Dim Shared LDPerson$(0 To 9)
Dim Shared LDAction$(0 To 9)
Dim Shared LDFeeling$(0 To 9)
Dim Shared LDSeeing$(0 To 9)
Dim Shared Question$(0 To 5)
Dim Shared Answer$(0 To 5)
Dim Shared BadDays$(0 To 6)
Dim Shared GoodDays$(0 To 6)
Dim Shared RegularDreams$(0 To 9)
Dim Shared NightMaresArray$(0 To 9)
Dim Shared LucideDreams$(0 To 9)

Dim Shared PlaceTag$
Dim Shared PersonTag$
Dim Shared ActionTag$
Dim Shared FeelingTag$
Dim Shared SeeingTag$

PlaceTag$ = "{P}"
PersonTag$ = "{PP}"
ActionTag$ = "{A}"
FeelingTag$ = "{F}"
SeeingTag$ = "{S}"

'data statments
Data "Flying in the Sky","Beach at Sunset","Shad on an Island","At Your Home","Lost On a HighWay","Deep In a Cave","Bout at Sea","Swimming At the Ocean","Street Somewhere","Sitting Dinning at a Resturant"
Data "Your Mom","Your Dad","Your Sister","Yisrael Your Roommate","Danny Your Old Friend","Aviv Your Lost Friend","the GrossHopper","The White Rabbit","Your Shadow","The Mad Hatter"
Data "Try To Run","You Ask Questions","You Talk With Them","You Leave Them","You Follow Them","You Lose Them","You Say Goodbye","You Hug Them","You Push Them Away From You","Wipe a Tear From Your Eyes"
Data "Angry","Happy","Sad","Don't Know How You feel","Crying","Thrilled","Feel Bad","Peaceful","Excited","Sick of Them"
Data "Sunlight in Your Eyes","Blue Skys","Pale Moon","Time Moving Backwards","Cloud of Birds","Sharks Flying in The Air","A Pool Of Blood","Shining Star","Desart Sand Blowing in The Wind","a Tombstone"

Data "Why are We Here?","plastic","What Eternity Is Made Of?","ashes and dust","What is the Meaning of Life the Universe and everything?","42","What is the Harderst Word to Say?","sorry","What is the Shortest English Sentence?","go."
Data "What is The Flavor of Life?","coca cola"

' Updated DATA to use Handles instead of File Paths
Data "REGULAR1","REGULAR2","REGULAR3","REGULAR4","REGULAR5","REGULAR6","REGULAR7","REGULAR8","REGULAR9","REGULAR0"
Data "LUCIDE1","LUCIDE2","LUCIDE3","LUCIDE4","LUCIDE5","LUCIDE6","LUCIDE7","LUCIDE8","LUCIDE9","LUCIDE10"
Data "MARE1","MARE2","MARE3","MARE4","MARE5","MARE6","MARE7","MARE8","MARE9","MARE10"
Data "GOODAY1","GOODAY2","GOODAY3","GOODAY4","GOODAY5","GOODAY6","GOODAY7"
Data "BADAY1","BADAY2","BADAY3","BADAY4","BADAY5","BADAY6","BADAY7"

' arrays initialization
For i% = 0 To 9
    Read LDPlaces$(i%)
Next i%
For i% = 0 To 9
    Read LDPerson$(i%)
Next i%
For i% = 0 To 9
    Read LDAction$(i%)
Next i%
For i% = 0 To 9
    Read LDFeeling$(i%)
Next i%
For i% = 0 To 9
    Read LDSeeing$(i%)
Next i%
For i% = 0 To 5
    Read Question$(i%), Answer$(i%)
Next i%
For i% = 0 To 9
    Read RegularDreams$(i%)
Next i%
For i% = 0 To 9
    Read LucideDreams$(i%)
Next i%
For i% = 0 To 9
    Read NightMaresArray$(i%)
Next i%
For i% = 0 To 6
    Read GoodDays$(i%)
Next i%
For i% = 0 To 6
    Read BadDays$(i%)
Next i%

Randomize Timer

InitializeGame

' Main program
Screen 12 ' 640x480 with 16 colors (compatible with LoadBMP logic)
_TITLE "Dream Hacking by Solo88"

LoadBMPQ "IMG24"
Color 3
PrintCenter 5, "DREAM HACKING"
Color 5
PrintCenter 7, "A GAME BY SOLO88"
PrintCenter 9, "MUSIC BY WALRUS"
Color 7

' Play intro music
PlayMusic "ACHMED"
SoundStopWav
sleepex

theme "AASIREN", "START1"

sleepex
MainLoop

Screen 0: Width 80: Color 7, 0: Cls
ScrollCredits "CREDITS"
Sleep
End

Rem $STATIC
Sub AccessTerminal
    Dim ans As String
   
    Screen 0: Width 80: Cls
    index% = Int(Rnd * 6)
    Print Question$(index%)
    Input "", ans
    If LCase$(ans) <> Answer$(index%) Then
        Print "wrong! answer is: " + Answer$(index%)
        Print "YOU DO NOT HAVE ACCESS TO THE DREAM TERMINAL!"
        Print "YOU'LL HAVE A REGULAR DREAM INSTEAD"
        sleepex
        RegularDream
        sleepex
        Exit Sub
    ElseIf LCase$(ans) = Answer$(index%) Then
        DreamTerminal
        sleepex
        Exit Sub
    End If
End Sub

Rem $DYNAMIC
Sub CheckCollisions
    For i = 1 To maxObstacles
        If obsType(i) = "BUILDING" Then
            If playerX + 6 >= obsX(i) And playerX <= obsX(i) And playerY >= groundRow - obsHeight(i) Then
                lives = lives - 1
                If lives <= 0 Then isOver = 1
                playerX = 20: playerY = 12
                Exit Sub
            End If
        ElseIf obsType(i) = "COMET" Or obsType(i) = "BIRD" Then
            If playerX + 6 >= obsX(i) And playerX <= obsX(i) And playerY = obsY(i) Then
                lives = lives - 1
                If lives <= 0 Then isOver = 1
                playerX = 20: playerY = 12
                Exit Sub
            End If
        End If
    Next i
End Sub

Rem $STATIC
Sub DayTime
    Dim handle$
   
    If DayCounter > 6 Then DayCounter = 0
    If SanityCounter > 4 Then
        handle$ = BadDays$(DayCounter)
    ElseIf SanityCounter <= 4 Then
        handle$ = GoodDays$(DayCounter)
    End If
    DayCounter = DayCounter + 1

    ReadAndPrintEmbedded handle$
End Sub

Rem $DYNAMIC
Sub DrawGround
    ' Initialize ground string
    ground$ = Space$(80)
   
    If groundLength <= 0 Or Len(groundPattern) = 0 Then
        For col = 1 To 80
            Mid$(ground$, col, 1) = "-"
        Next col
    Else
        For col = 1 To 80
            patternIndex = ((col - 1 + groundOffset) Mod groundLength) + 1
            If patternIndex > 0 And patternIndex <= Len(groundPattern) Then
                Mid$(ground$, col, 1) = Mid$(groundPattern$, patternIndex, 1)
            Else
                Mid$(ground$, col, 1) = "-"
            End If
        Next col
    End If
   
    If groundRow >= 1 And groundRow <= 25 Then
        Locate groundRow, 1: Print ground$
    End If
End Sub

Sub DrawObstacles
    For i = 1 To maxObstacles
        If obsX(i) >= 1 And obsX(i) <= 80 Then
            If obsType(i) = "BUILDING" Then
                For h = 1 To obsHeight(i)
                    row = groundRow - h
                    If row >= 1 Then
                        Locate row, obsX(i): Print obsChar(i)
                    End If
                Next h
            Else
                Locate obsY(i), obsX(i): Print obsChar(i)
            End If
        End If
    Next i
End Sub

Sub DrawScreen
    Cls
    DrawGround
    DrawObstacles
    ' Draw player
    Locate playerY, playerX: Print player
    ' Draw HUD
    Locate 1, 1: Print "Score:"; score; " Lives:"; lives
End Sub

Rem $STATIC
Sub DreamTerminal
    TerminalAnimation
    sleepex
    choice% = ShowMatrixMenu%

    If choice% = 1 Then
        accessAlpha% = LightAnimation%
        If accessAlpha% = 1 Then
            Locate 10, 10
            Print "You entered the Light!"
            SanityCounter = SanityCounter + 1
            Sleep
            Flying "ACHMED"
            Exit Sub
        Else
            Locate 10, 10
            Print "You Did NOT Entered the Light!"
            Sleep
            SanityCounter = SanityCounter + 1
            NightMares
            sleepex
            Exit Sub
        End If

    ElseIf choice% = 2 Then
        LucideDream
        Exit Sub
    ElseIf choice% = 3 Then
        RegularDream
        SanityCounter = SanityCounter - 5
        Exit Sub
    ElseIf choice% = 4 Then
        Cls: Print "YOU SLIP INTO A DEEP RESTFUL SLEEP WITHOUT ANY DREAMS"
        SanityCounter = 0
        sleepex
        Exit Sub
    ElseIf choice% = 5 Then
        Exit Sub

    End If

End Sub

Rem $DYNAMIC
Sub Flying (musicHandle$)
    SoundPlayWav musicHandle$
    ' Main loop
    Do
        DrawScreen
        UpdatePlayer
        UpdateObstacles
        CheckCollisions
        If isOver = 1 Then
            SoundStopWav
            GameOver
            Exit Do
        End If
        _Limit 10
        If InKey$ = Chr$(27) Then Exit Do ' ESC to quit
    Loop
End Sub

Sub GameOver
    Cls
    Locate 12, 30
    Print "DREAM OVER"
    Locate 14, 28
    Print "Final Score:"; score
    Locate 16, 25
    Print "Press any key to exit"
    sleepex
End Sub

Sub InitializeGame
    playerX = 20
    playerY = 12
    score = 0
    lives = 3
    groundRow = 25
    groundPattern = "-="
    groundLength = Len(groundPattern)
    If groundLength <= 0 Then groundLength = 1: groundPattern = "-"
    groundOffset = 0
    isOver = 0

    ' Initialize obstacles
    For i = 1 To maxObstacles
        obsX(i) = 80 + (i - 1) * 15
        r = Int(Rnd * 3)
        If r = 0 Then
            obsType(i) = "BUILDING"
            obsHeight(i) = 2 + Int(Rnd * 5)
            obsY(i) = groundRow - obsHeight(i)
            obsChar(i) = Chr$(219) ' █
        ElseIf r = 1 Then
            obsType(i) = "COMET"
            obsHeight(i) = 0
            obsY(i) = 1 + Int(Rnd * (groundRow - 3))
            obsChar(i) = "*"
        Else
            obsType(i) = "BIRD"
            obsHeight(i) = 0
            obsY(i) = 5 + Int(Rnd * (groundRow - 8))
            obsChar(i) = ">"
        End If
    Next i
End Sub

Rem $STATIC
Sub LucideDream
    Do
        Screen 0: Cls
        LucideDreamGen
        Print "1. ACCEPT THIS DREAM 2. ROLL THE DICE"
        k$ = GetKey$("12")
        If k$ = "1" Then
            Exit Sub
        End If
        SanityCounter = SanityCounter + 1
    Loop Until k$ = "1"
End Sub

Sub LucideDreamGen
    Dim textLine$
    Dim handle$
    Dim content$
    Dim curPos As Long
    Dim nextPos As Long
    Dim char$
   
    LCDCounter = Int(Rnd * 10)
    handle$ = LucideDreams$(LCDCounter)
   
    content$ = GetEmbeddedData$(handle$)
    curPos = 1
   
    Screen 0: Width 80: Cls
 
    Do While curPos <= Len(content$)
        ' Extract line inline to avoid reference issues
        nextPos = curPos
        Do While nextPos <= Len(content$)
            char$ = Mid$(content$, nextPos, 1)
            If char$ = Chr$(13) Or char$ = Chr$(10) Then Exit Do
            nextPos = nextPos + 1
        Loop
       
        textLine$ = Mid$(content$, curPos, nextPos - curPos)
       
        ' Replace tags
        textLine$ = Replace$(textLine$, PlaceTag$, LDPlaces$(Int(Rnd * 10)))
        textLine$ = Replace$(textLine$, PersonTag$, LDPerson$(Int(Rnd * 10)))
        textLine$ = Replace$(textLine$, ActionTag$, LDAction$(Int(Rnd * 10)))
        textLine$ = Replace$(textLine$, FeelingTag$, LDFeeling$(Int(Rnd * 10)))
        textLine$ = Replace$(textLine$, SeeingTag$, LDSeeing$(Int(Rnd * 10)))
        Print textLine$
       
        ' Advance
        curPos = nextPos
        If curPos <= Len(content$) Then
            If Mid$(content$, curPos, 1) = Chr$(13) Then curPos = curPos + 1
        End If
        If curPos <= Len(content$) Then
            If Mid$(content$, curPos, 1) = Chr$(10) Then curPos = curPos + 1
        End If
    Loop
End Sub

Sub MainLoop
    Do
        DayTime
        sleepex
        Cls: Print "Okay Now it's Time for BedTime..."
        sleepex
        AccessTerminal
   
        sleepex
        If SanityCounter > 25 And DayCounter = 1 Then
            ReadAndPrintEmbedded "HOSPITAL"
        ElseIf (SanityCounter > 10 Or SanityCounter <= 25) And DayCounter = 4 Then
            ReadAndPrintEmbedded "DOCTOR1"
        End If
        Cls: Print "Okay Now it's Day Time..."
        Print "Press Esc to Exit press Enter to Continue..."
        k$ = GetKey$(Chr$(27) + Chr$(13))
        If k$ = Chr$(27) Then Exit Sub
        sleepex
    Loop Until k$ = Chr$(27)
End Sub

Sub NightMares
    Dim handle$
    NightMareCounter = Int(Rnd * 10)
    handle$ = NightMaresArray$(NightMareCounter)
    ReadAndPrintEmbedded handle$
End Sub

Rem $DYNAMIC
Sub PlayMusic (handle AS STRING)
    SoundPlayWav handle
End Sub

Sub PrintCenter (row As Integer, s As String)
    Locate row, (80 - Len(s)) \ 2: Print s
End Sub

Rem $STATIC
Function RandomGenerator% (num)
    Randomize Timer
    RandomGenerator% = Int(Rnd * num)
End Function

Sub RegularDream
    Dim handle$
    RegularCounter = Int(Rnd * 10)
    handle$ = RegularDreams$(RegularCounter)
    ReadAndPrintEmbedded handle$
End Sub

Rem $DYNAMIC
Function Replace$ (sInput As String, sFind As String, sReplace As String)
    Dim iStart As Integer, iRepLen As Integer, iFindLen As Integer, iFound As Integer
    Dim sText As String
    If sFind = "" Then
        Replace$ = sInput
        Exit Function
    End If
    iStart = 1
    iRepLen = Len(sReplace)
    iFindLen = Len(sFind)
    sText = sInput
    Do
        If iStart < 1 Then iStart = 1
        iFound = InStr(iStart, sText, sFind)
        If iFound = 0 Then
            Replace$ = sText
            Exit Function
        End If
        sText = Left$(sText, iFound - 1) + sReplace + Mid$(sText, iFound + iFindLen)
        iStart = iFound + iRepLen
    Loop
End Function

Sub ScrollCredits (handle$)
    Dim content$
    Dim curPos As Long
    Dim nextPos As Long
    Dim char$
   
    content$ = GetEmbeddedData$(handle$)
    curPos = 1
   
    Dim lines$(1000)
    lineCount = 0
   
    ' Read all lines
    Do While curPos <= Len(content$)
        nextPos = curPos
        Do While nextPos <= Len(content$)
            char$ = Mid$(content$, nextPos, 1)
            If char$ = Chr$(13) Or char$ = Chr$(10) Then Exit Do
            nextPos = nextPos + 1
        Loop
       
        lines$(lineCount) = Mid$(content$, curPos, nextPos - curPos)
        lineCount = lineCount + 1
       
        curPos = nextPos
        If curPos <= Len(content$) Then
            If Mid$(content$, curPos, 1) = Chr$(13) Then curPos = curPos + 1
        End If
        If curPos <= Len(content$) Then
            If Mid$(content$, curPos, 1) = Chr$(10) Then curPos = curPos + 1
        End If
    Loop
   
    Cls
    For i = 24 To -lineCount Step -1
        Cls
        For j = 0 To lineCount - 1
            If i + j >= 0 And i + j < 25 Then
                Locate i + j + 1, 1
                Print lines$(j)
            End If
        Next j
        _Delay 0.5
    Next i
End Sub

Sub sleepex
    Sleep
    While InKey$ = "": Wend
    While InKey$ <> "": Wend
End Sub

Rem $STATIC
Sub sleepex2
    Sleep
    While InKey$ = "": Wend
End Sub

Rem $DYNAMIC
Sub theme (musicHandle$, textHandle$)
    SoundPlayWav musicHandle$
    ReadAndPrintEmbedded textHandle$
    SoundStopWav
End Sub

Sub UpdateObstacles
    groundOffset = groundOffset + 1
    If groundOffset >= groundLength Then groundOffset = 0
 
    For i = 1 To maxObstacles
        obsX(i) = obsX(i) - 1 ' Move left
        If obsX(i) < 1 Then
            ' Respawn on right
            obsX(i) = 80
            r = Int(Rnd * 3)
            If r = 0 Then
                obsType(i) = "BUILDING"
                obsHeight(i) = 2 + Int(Rnd * 5)
                obsY(i) = groundRow - obsHeight(i)
                obsChar(i) = Chr$(219)
            ElseIf r = 1 Then
                obsType(i) = "COMET"
                obsHeight(i) = 0
                obsY(i) = 1 + Int(Rnd * (groundRow - 3))
                obsChar(i) = "*"
            Else
                obsType(i) = "BIRD"
                obsHeight(i) = 0
                obsY(i) = 5 + Int(Rnd * (groundRow - 8))
                obsChar(i) = ">"
            End If
            score = score + 10
        End If
    Next i
End Sub

Sub UpdatePlayer
    k$ = InKey$
    oldX = playerX
    oldY = playerY
    If k$ = Chr$(0) + Chr$(72) Then playerY = playerY - 1
    If k$ = Chr$(0) + Chr$(80) Then playerY = playerY + 1
    If k$ = Chr$(0) + Chr$(75) Then playerX = playerX - 1
    If k$ = Chr$(0) + Chr$(77) Then playerX = playerX + 1
    If playerX < 1 Then playerX = 1
    If playerX > 74 Then playerX = 74
    If playerY < 2 Then playerY = 2
    If playerY > groundRow - 1 Then playerY = groundRow - 1
End Sub

' ---------------------------------------------------------
' NEW: LoadBMP using _LOADIMAGE from memory
' ---------------------------------------------------------
Sub LoadBMP (handle AS STRING)
    Dim imgHandle AS LONG
    Dim resourceData$
    resourceData$ = GetEmbeddedData$(handle)
   
    If resourceData$ = "" Then
        Print "Image not found embedded: "; handle
        Exit Sub
    End If
   
    ' Load directly from embedded memory
    imgHandle = _LOADIMAGE(resourceData$, 32, "memory")
    If imgHandle < 0 Then
        ' Draw it to the current screen
        _PUTIMAGE , imgHandle
        _FREEIMAGE imgHandle
    Else
        Print "Failed to load image handle: "; handle
    End If
End Sub

' ---------------------------------------------------------
' NEW: LoadBMPQ (Custom Format) from memory
' ---------------------------------------------------------
Sub LoadBMPQ (handle AS STRING)
    Dim content$
    Dim iWid AS INTEGER, iHei AS INTEGER
    Dim x AS INTEGER, y AS INTEGER
    Dim pixelByte AS INTEGER
    Dim offset AS LONG
   
    content$ = GetEmbeddedData$(handle)
    If content$ = "" Then
        Print "BMQ not found: "; handle
        Exit Sub
    End If
   
    ' Header Check "BMQ"
    If Left$(content$, 3) <> "BMQ" Then
        Print "Invalid BMQ header for: "; handle
        Exit Sub
    End If
   
    ' Parse Width and Height (2 bytes each)
    iWid = CVI(Mid$(content$, 4, 2))
    iHei = CVI(Mid$(content$, 6, 2))
    lastWidth = iWid: lastHeight = iHei
   
    ' Offset starts after header (3+2+2 = 7 bytes) => 8th byte
    offset = 8
   
    Screen 12
    For y = 0 To iHei - 1
        For x = 0 To iWid - 1
            ' Safely read byte
            If offset <= Len(content$) Then
                pixelByte = Asc(Mid$(content$, offset, 1))
                PSet (x, y), pixelByte
                offset = offset + 1
            End If
        Next x
    Next y
End Sub

Function GetKey$ (keysToCatch$)
    Dim k$
    Do
        k$ = InKey$
        While Len(k$) = 0
            k$ = InKey$
            _Limit 60
        Wend
    Loop Until InStr(keysToCatch$, k$)
    GetKey$ = k$
End Function

' ---------------------------------------------------------
' NEW: Read and Print text from embedded memory
' ---------------------------------------------------------
Sub ReadAndPrintEmbedded (handle$)
    Dim content$
    Dim curPos As Long
    Dim nextPos As Long
    Dim textLine$
    Dim char$
   
    content$ = GetEmbeddedData$(handle$)
    If content$ = "" Then
        Print "Text not found: "; handle$
        Exit Sub
    End If
   
    curPos = 1
   
    Screen 0: Width 80: Cls
   
    Do While curPos <= Len(content$)
        ' Find end of line (CR or LF)
        nextPos = curPos
        Do While nextPos <= Len(content$)
            char$ = Mid$(content$, nextPos, 1)
            If char$ = Chr$(13) Or char$ = Chr$(10) Then Exit Do
            nextPos = nextPos + 1
        Loop
       
        ' Extract the line
        textLine$ = Mid$(content$, curPos, nextPos - curPos)
        Print textLine$
       
        ' Advance curPos past newline sequence
        curPos = nextPos
        If curPos <= Len(content$) Then
            If Mid$(content$, curPos, 1) = Chr$(13) Then curPos = curPos + 1
        End If
        If curPos <= Len(content$) Then
            If Mid$(content$, curPos, 1) = Chr$(10) Then curPos = curPos + 1
        End If
       
        ' Pagination logic
        If CsrLin > 22 Then
            Print "Press SPACE to continue..."
            While InKey$ <> Chr$(32): Wend
            Cls
        End If
    Loop
   
    Print "Press SPACE to continue..."
    While InKey$ <> Chr$(32): Wend
End Sub

Function ShowMatrixMenu%
    Dim options$(1 To 5)
    options$(1) = "Alpha State Dream"
    options$(2) = "Lucide Dream"
    options$(3) = "Regular Dream"
    options$(4) = "BlackOut"
    options$(5) = "Exit Dream Terminal"

    Color 10, 0
    Screen 0: Cls

    selected% = 1
    lastSelected% = 0

    Do
        If selected% <> lastSelected% Then
            Cls
            Locate 5, 20
            Print "=== DREAM TERMINAL ==="
            For i% = 1 To 5
                Locate 8 + i%, 20
                If i% = selected% Then
                    Color 0, 10
                    Print "> "; options$(i%); " <"
                    Color 10, 0
                Else
                    Print "  "; options$(i%)
                End If
            Next i%
            lastSelected% = selected%
        End If

        Do
            key$ = InKey$
        Loop Until key$ <> ""

        Select Case key$
            Case Chr$(0) + Chr$(72)
                If selected% > 1 Then selected% = selected% - 1
            Case Chr$(0) + Chr$(80)
                If selected% < 5 Then selected% = selected% + 1
            Case Chr$(13)
                Exit Do
            Case Chr$(27)
                selected% = 0
                Exit Do
        End Select
    Loop
    Color 7, 0
    Cls
    ShowMatrixMenu% = selected%
End Function

Function LightAnimation%
    Do
        s$ = "ENTER THE LIGHT!"
        Color 0, 15
        Screen 0: Width 80
        Cls
        Locate 10, (80 - Len(s$)) \ 2: Print s$
        If InKey$ = Chr$(13) Then
            Exit Do
        End If
        Sleep 1
        s2$ = String$(16, 255)
        Color 2, 0
        Screen 0: Width 80: Cls
        Color 15: Locate 10, (80 - Len(s2$)) \ 2: Print s2$
        If InKey$ = Chr$(13) Then
            Exit Do
        End If
        Sleep 1
        Color 7, 0
        Screen 0: Width 80: Cls
        s3$ = "YOU CANNOT ENTER NOW!"
        Locate 10, (80 - Len(s3$)) \ 2: Print s3$
        If InKey$ = Chr$(13) Then
            Exit Do
        End If
        Sleep 1
    Loop

    Cls
    result% = Int(Rnd * 3)
    sleepex
    LightAnimation% = result%
End Function

Sub TerminalAnimation
    Screen 0: Width 80: Cls
    Color 2
    Randomize Timer
    Dim i As Integer
    For i = 0 To 2000
        Locate Int(Rnd * 24) + 1, Int(Rnd * 79) + 1
        char$ = Chr$(Int(Rnd * 255))
        Print char$;
        _Delay 0.0001
    Next i
    Cls
    Locate 15, 10
    Print "YOU NOW HAVE ACCESS TO THE DREAM TERMINAL!"
    Color 7
    Sleep
End Sub

Sub SoundStopWav
    If songLong > 0 Then _SndStop (songLong)
End Sub

' ---------------------------------------------------------
' NEW: Load Sound from embedded Memory
' ---------------------------------------------------------
Sub SoundPlayWav (handle AS STRING)
    ' Load sound from embedded memory using the "memory" flag
    ' Requires QB64 Phoenix Edition v3.14+
    Dim resourceData$
    resourceData$ = GetEmbeddedData$(handle)
    If resourceData$ <> "" Then
        songLong = _SndOpen(resourceData$, "memory")
        If songLong > 0 Then
            _SndPlay songLong
        End If
    End If
End Sub

' ---------------------------------------------------------
' NEW: Centralized Content Retrieval
' Maps string variables to hard-coded _EMBEDDED$ literals
' ---------------------------------------------------------
Function GetEmbeddedData$ (handle AS STRING)
    Select Case UCase$(handle)
        ' Days
        Case "BADAY1": GetEmbeddedData$ = _EMBEDDED$("BADAY1")
        Case "BADAY2": GetEmbeddedData$ = _EMBEDDED$("BADAY2")
        Case "BADAY3": GetEmbeddedData$ = _EMBEDDED$("BADAY3")
        Case "BADAY4": GetEmbeddedData$ = _EMBEDDED$("BADAY4")
        Case "BADAY5": GetEmbeddedData$ = _EMBEDDED$("BADAY5")
        Case "BADAY6": GetEmbeddedData$ = _EMBEDDED$("BADAY6")
        Case "BADAY7": GetEmbeddedData$ = _EMBEDDED$("BADAY7")
        Case "GOODAY1": GetEmbeddedData$ = _EMBEDDED$("GOODAY1")
        Case "GOODAY2": GetEmbeddedData$ = _EMBEDDED$("GOODAY2")
        Case "GOODAY3": GetEmbeddedData$ = _EMBEDDED$("GOODAY3")
        Case "GOODAY4": GetEmbeddedData$ = _EMBEDDED$("GOODAY4")
        Case "GOODAY5": GetEmbeddedData$ = _EMBEDDED$("GOODAY5")
        Case "GOODAY6": GetEmbeddedData$ = _EMBEDDED$("GOODAY6")
        Case "GOODAY7": GetEmbeddedData$ = _EMBEDDED$("GOODAY7")
       
        ' Dreams
        Case "REGULAR0": GetEmbeddedData$ = _EMBEDDED$("REGULAR0")
        Case "REGULAR1": GetEmbeddedData$ = _EMBEDDED$("REGULAR1")
        Case "REGULAR2": GetEmbeddedData$ = _EMBEDDED$("REGULAR2")
        Case "REGULAR3": GetEmbeddedData$ = _EMBEDDED$("REGULAR3")
        Case "REGULAR4": GetEmbeddedData$ = _EMBEDDED$("REGULAR4")
        Case "REGULAR5": GetEmbeddedData$ = _EMBEDDED$("REGULAR5")
        Case "REGULAR6": GetEmbeddedData$ = _EMBEDDED$("REGULAR6")
        Case "REGULAR7": GetEmbeddedData$ = _EMBEDDED$("REGULAR7")
        Case "REGULAR8": GetEmbeddedData$ = _EMBEDDED$("REGULAR8")
        Case "REGULAR9": GetEmbeddedData$ = _EMBEDDED$("REGULAR9")
       
        Case "LUCIDE1": GetEmbeddedData$ = _EMBEDDED$("LUCIDE1")
        Case "LUCIDE2": GetEmbeddedData$ = _EMBEDDED$("LUCIDE2")
        Case "LUCIDE3": GetEmbeddedData$ = _EMBEDDED$("LUCIDE3")
        Case "LUCIDE4": GetEmbeddedData$ = _EMBEDDED$("LUCIDE4")
        Case "LUCIDE5": GetEmbeddedData$ = _EMBEDDED$("LUCIDE5")
        Case "LUCIDE6": GetEmbeddedData$ = _EMBEDDED$("LUCIDE6")
        Case "LUCIDE7": GetEmbeddedData$ = _EMBEDDED$("LUCIDE7")
        Case "LUCIDE8": GetEmbeddedData$ = _EMBEDDED$("LUCIDE8")
        Case "LUCIDE9": GetEmbeddedData$ = _EMBEDDED$("LUCIDE9")
        Case "LUCIDE10": GetEmbeddedData$ = _EMBEDDED$("LUCIDE10")
       
        Case "MARE1": GetEmbeddedData$ = _EMBEDDED$("MARE1")
        Case "MARE2": GetEmbeddedData$ = _EMBEDDED$("MARE2")
        Case "MARE3": GetEmbeddedData$ = _EMBEDDED$("MARE3")
        Case "MARE4": GetEmbeddedData$ = _EMBEDDED$("MARE4")
        Case "MARE5": GetEmbeddedData$ = _EMBEDDED$("MARE5")
        Case "MARE6": GetEmbeddedData$ = _EMBEDDED$("MARE6")
        Case "MARE7": GetEmbeddedData$ = _EMBEDDED$("MARE7")
        Case "MARE8": GetEmbeddedData$ = _EMBEDDED$("MARE8")
        Case "MARE9": GetEmbeddedData$ = _EMBEDDED$("MARE9")
        Case "MARE10": GetEmbeddedData$ = _EMBEDDED$("MARE10")
       
        ' Misc Text
        Case "START1": GetEmbeddedData$ = _EMBEDDED$("START1")
        Case "CREDITS": GetEmbeddedData$ = _EMBEDDED$("CREDITS")
        Case "DOCTOR1": GetEmbeddedData$ = _EMBEDDED$("DOCTOR1")
        Case "HOSPITAL": GetEmbeddedData$ = _EMBEDDED$("HOSPITAL")
       
        ' Sounds
        Case "AASIREN": GetEmbeddedData$ = _EMBEDDED$("AASIREN")
        Case "ACHMED": GetEmbeddedData$ = _EMBEDDED$("ACHMED")
       
        ' Images
        Case "IMG24": GetEmbeddedData$ = _EMBEDDED$("IMG24")
        Case "IMG256": GetEmbeddedData$ = _EMBEDDED$("IMG256")
        Case "TITLE1": GetEmbeddedData$ = _EMBEDDED$("TITLE1")
    End Select
End Function
The noticing will continue
Reply
#4
Hi Ron! interesting program.
  724  855  599  923  575  468  400  206  147  564  878  823  652  556 bxor cross forever
Reply
#5
Hi bplus and SpriggsySpriggs...

yep decided to try out qb64pe cause you live only once :/

Call me old-fashioned but I like to have game resources in a subfolder and separate code from data/sound/images, but to be honest I have no clue about QB64PE's new features like $EMMBED and _EMBBEDDED$ sounds interesting.

I'll post some old/new games I made from 2020 (remember the COVID pandemic?)

cheers

solo88 (previously ron77)
aka ron77
Reply


Possibly Related Threads…
Thread Author Replies Views Last Post
  Hkikomori game (freebasic converted to qb64pe) from 2020 solo88 1 617 01-06-2026, 08:40 PM
Last Post: hsiangch_ong
  AI powered roleplay game in QB64 SquirrelMonkey 5 1,106 11-26-2025, 04:01 PM
Last Post: hsiangch_ong
  Cyberpunk Game Jam 2.0 entry: Prototype Amber (made in QB64) Hevanafa 5 1,034 08-13-2025, 09:02 AM
Last Post: TempodiBasic

Forum Jump:


Users browsing this thread: 1 Guest(s)