Post by bplus on May 20, 2023 21:01:31 GMT -5
Curious if I could translate a PureBasic program to QB64 since I have been looking into PureBasic lately.
Yeah, I could and discovered PureBasic ain't nearly as easy as QB64 but it does seem to have Arrays in Structures = QB64 UDT's which QB64 doesn't have.
This code turns out to be an extremely boring straight line shot through 7 rooms in a row, just head South from the Cell.
_Title "Basic Text Adventure" ' b+ 2023-05-20
' I've been curious about PureBasic and so looking around for code.
' BTW this cross polination is great for new ideas.
' Attempt to translate ron77 PureBasic game to QB64.
' found here: https://retrocoders.phatcode.net/index.php?topic=158.0
'If your are reading this, I was successful.
Option _Explicit
Const Screen_Width = 500
Const Screen_Height = 100
'these came from a location structure but can't do arrays in a Type
Dim compass(3) As String
Dim location(6) As String
Dim places(6, 3) As Long
Dim see(6, 3) As String
Dim As Long i, ii
places(0, 0) = -1
places(0, 1) = -1
places(0, 2) = 1
places(0, 3) = -1
places(1, 0) = 0
places(1, 1) = -1
places(1, 2) = 2
places(1, 3) = -1
places(2, 0) = 1
places(2, 1) = -1
places(2, 2) = 3
places(2, 3) = -1
places(3, 0) = 2
places(3, 1) = -1
places(3, 2) = 4
places(3, 3) = -1
places(4, 0) = 3
places(4, 1) = -1
places(4, 2) = 5
places(4, 3) = -1
places(5, 0) = 4
places(5, 1) = -1
places(5, 2) = 6
places(5, 3) = -1
places(6, 0) = 5
places(6, 1) = -1
places(6, 2) = -1
places(6, 3) = -1
'Restore compass dont need Restore on first read through for loading data
For i = 0 To 3
Read compass(i)
Next
'Restore locations
For i = 0 To 6
Read location(i)
Next
'Restore directions
For i = 0 To 6
For ii = 0 To 3
Read see(i, ii)
Next
Next
Screen _NewImage(Screen_Width, Screen_Height, 32)
Dim As Long k, x, z
CPrint 10, "Warning: turn your volume down because"
CPrint 30, "I will beep if you try and walk where you can't."
CPrint 50, "Left or right arrow to turn, up to step forward."
CPrint 80, " zzz... press any to enter the Cell."
Sleep
Do
Cls
' corrections to x, z
If x < 0 Then x = 0 ' these room are in a row 0 and 6 are ends
If x > 6 Then x = 6
If z > 3 Then z = 0 ' cycle around in room
If z < 0 Then z = 3 ' cycle around in room
CPrint 40, compass(z)
CPrint 20, location(x)
CPrint 60, see(x, z)
'move around left right step forward with up key
k = _KeyHit
If k = 18432 Then ' Key_Up = step forward if can
If places(x, z) <> -1 Then x = places(x, z) Else Beep
End If
If k = 19712 Then z = z + 1 'Key_Right
If k = 19200 Then z = z - 1 'Key_Left
_Display
_Limit 30
Loop Until k = 27
End
'DataSection
compass:
Data "North","East","South","West"
locations:
Data "Cell Room","Corridor","Hallway","Chamber","Entrance Hall","Gateway","Outside"
directions:
Data "a wall with bar windows"
Data "a bed with a chair and a table"
Data "a cell door"
Data "a brick wall"
Data "a cell door"
Data "a long wall"
Data "a narrow path with stairs"
Data "a high wall of bricks"
Data "a narrow path with stairs"
Data "a wall with mirrors"
Data "an open door with light from it"
Data "a wall with lots of pictures on it"
Data "an open door"
Data "a large chamber with windows"
Data "a long path"
Data "a brick wall"
Data "a long path"
Data "a large entrance hall full of shelves with books"
Data "a gate is seen far in the next room"
Data "a brick wall with windows"
Data "entry to a hall"
Data "locked doors"
Data "a gate to the outside"
Data "a long tunnel with a locked door"
Data "a gate to enter a castle"
Data "green fields in bright sun light"
Data "a road to a distant village"
Data "a forest in the distance"
Sub CPrint (row As Long, text As String)
_PrintString ((Screen_Width - _PrintWidth(text)) / 2, row), text
End Sub
Yeah, I could and discovered PureBasic ain't nearly as easy as QB64 but it does seem to have Arrays in Structures = QB64 UDT's which QB64 doesn't have.
This code turns out to be an extremely boring straight line shot through 7 rooms in a row, just head South from the Cell.