Author Topic: A QB64 roguelike in 50 lines prettified (now 625 lines)  (Read 3976 times)

0 Members and 1 Guest are viewing this topic.

Offline madscijr

  • Seasoned Forum Regular
  • Posts: 295
    • View Profile
A QB64 roguelike in 50 lines prettified (now 625 lines)
« on: May 28, 2021, 04:22:41 pm »
Here's a program I came across at nippycodes.com which I cleaned up a little, maybe to expand in the future.
I'm not sure who the original author is, so I just cited the web site.
I thought I would post it as it might help aspiring RPG creators like it helped me.
Enjoy...

Title screen:
 
rogue50_10_screenshot_1.png


Gameplay:
 
rogue50_10_screenshot_2.png


Code:
Code: QB64: [Select]
  1. ' #############################################################################
  2. ' This game is from:
  3. '
  4. '     A QB64 roguelike in 50 lines
  5. '     https://nippycodes.com/coding/a-qb64-roguelike-in-50-lines/
  6. '
  7. ' cleaned up and made prettier.
  8.  
  9. ' ================================================================================================================================================================
  10. ' NOTES
  11. ' ================================================================================================================================================================
  12. ' The CSRLIN function returns the current text row position of the PRINT cursor.
  13. ' The POS function returns the current print cursor text column position.
  14. ' The SCREEN function returns the ASCII code of a text character or the color attribute at a set text location on the screen.
  15. ' codeorcolor% = SCREEN (row%, column% [, colorflag%])
  16. ' row and column are the INTEGER text coordinates of the SCREEN mode used.
  17. ' Optional colorflag INTEGER value can be omitted or 0 for ASCII code values or 1 for color attributes.
  18.  
  19. ' ================================================================================================================================================================
  20. ' TO DO
  21. ' ================================================================================================================================================================
  22. ' Code improvements:
  23. ' * Remove GOTO statements and make code more modular.
  24. ' * Store terrain, players, objects, etc. in different arrays/layers for more complex interaction
  25. ' * Include a level editor (not just random levels).
  26. ' * Add combat and RPG features similar to Ultima 1-5
  27. ' * Quests
  28. ' * Towns, Castles, etc.
  29.  
  30. ' Weapons:
  31. ' * Hands & Feet (default)
  32. ' * Club
  33. ' * Mace
  34. ' * Staff
  35. ' * Dagger
  36. ' * Sword
  37. ' * Great Sword
  38. ' * Spear
  39. ' * Bow / Arrow - player needs to find arrows
  40. ' * Sling - unlimited stones, can buy lead sling bullets for more damage
  41.  
  42. ' Armor:
  43. ' * Skin (default)
  44. ' * Cloth
  45. ' * Leather
  46. ' * Chain Mail
  47. ' * Plate
  48.  
  49. ' Armor (shields):
  50. ' * Leather Shield
  51. ' * Wood Shield
  52. ' * Small Metal Shield
  53. ' * Great Shield
  54.  
  55. ' Objects:
  56. ' * Healing Potion - restore HP
  57. ' * Torches - allow player to see in dark areas
  58.  
  59. ' Stats:
  60. ' * Food - decreases every n turns, if out of food player starves (loses HP)
  61. ' * Max HP - increases with higher levels
  62.  
  63. ' Attributes that affect combat, etc.:
  64. ' * Strength
  65. ' * Agility
  66. ' * Stamina
  67. ' * Intelligence
  68. ' * Wisdom
  69. ' * Charisma
  70. ' * weapon attack skill (increases per weapon type as you use it)
  71. ' * weapon defense skill (increases per weapon each time you fight someone with it)
  72.  
  73. ' Magic:
  74. ' ???
  75.  
  76. ' Monsters / NPCs:
  77. ' * different races
  78. ' * have their own inventory of items, food, etc.
  79. ' * have different HP, attributes, etc.
  80. ' * can be interacted with or yell things
  81.  
  82. ' Map:
  83. ' * include screens that are towns, not just random dungeons
  84.  
  85. ' Store:
  86. ' * buy weapons/armor/food/healing
  87. ' * located in certain "civilized" areas
  88.  
  89. ' ================================================================================================================================================================
  90. ' OPTIONS
  91. ' ================================================================================================================================================================
  92.  
  93. ' ================================================================================================================================================================
  94. ' GLOBAL DECLARATIONS a$=string, i%=integer, L&=long, s!=single, d#=double
  95. ' ================================================================================================================================================================
  96. Const FALSE = 0
  97. Const TRUE = Not FALSE
  98.  
  99. ' ----------------------------------------------------------------------------------------------------------------------------------------------------------------
  100. ' UDFs
  101. ' ----------------------------------------------------------------------------------------------------------------------------------------------------------------
  102. Type PlayerType
  103.     X As Integer
  104.     Y As Integer
  105.    
  106.     ' NEW:
  107.     Items As String
  108.     HP As Integer
  109.     XP As Integer
  110.     Level As Integer
  111.     Gold As Integer
  112. End Type ' PlayerType
  113.  
  114. Dim ProgramPath$
  115. Dim ProgramName$
  116.  
  117. ' =============================================================================
  118. ' INITIALIZE
  119. ProgramName$ = Mid$(Command$(0), _InStrRev(Command$(0), "\") + 1)
  120. ProgramPath$ = Left$(Command$(0), _InStrRev(Command$(0), "\"))
  121.  
  122. ' =============================================================================
  123. ' RUN THE MAIN PROGRAM
  124. main ProgramName$
  125.  
  126. ' =============================================================================
  127. ' FINISH
  128. System ' return control to the operating system
  129. Print ProgramName$ + " finished."
  130.  
  131. ' /////////////////////////////////////////////////////////////////////////////
  132.  
  133. Sub main (ProgName$)
  134.     ' ----------------------------------------------------------------------------------------------------------------------------------------------------------------
  135.     ' VARIABLES
  136.     Dim iLoop As Integer
  137.     Dim K$
  138.    
  139.     Dim iNewCol As Integer
  140.     Dim iNewRow As Integer
  141.     Dim iPosX As Integer
  142.     Dim iPosY As Integer
  143.     Dim x%
  144.     Dim y%
  145.     Dim c%
  146.     Dim bNewCave As Integer
  147.    
  148.     Dim bMonsterPlaced As Integer
  149.     Dim arrGuy(16) As PlayerType
  150.    
  151.     Dim in$
  152.    
  153.    
  154.    
  155.     ' ================================================================================================================================================================
  156.     ' SHOW INSTRUCTIONS
  157.     Cls
  158.     color cPeriwinkle&: Print "-------------------------------------------------------------------------------"
  159.     color cLtGreen&: Print "Rogue 50"
  160.     color cCyan&: Print "(a simple game based on " + chr$(34) + "A QB64 roguelike in 50 lines" + chr$(34) + " from nippycodes.com)"    
  161.     color cPeriwinkle&: Print "-------------------------------------------------------------------------------"
  162.     color cCyan&: Print "You are the adventurer........";: color cWhite&: Print "@"
  163.     color cCyan&: Print "Travel through the caves......";: color cGray&: Print "#"
  164.     color cCyan&: Print "Collect the treasure..........";: color cYellow&: Print "*"
  165.     color cCyan&: Print "And avoid the monsters........";: color cGreen&: Print "A"
  166.     color cCyan&: Print "Find doors to the next cave...";: color cLtGray&: Print "%"
  167.     color cCyan&: Print
  168.     color cCyan&: Print "If you touch a monster you will battle,"
  169.     color cCyan&: Print "and lose hit points but gain experience."
  170.     color cCyan&: Print
  171.     color cCyan&: Print "CONTROLS:"
  172.     color cCyan&: Print "Use the arrow keys to move around."
  173.     color cCyan&: Print "Press the ESC key when you want to quit."
  174.     color cCyan&: Print
  175.     color cCyan&: Input "Press ENTER to continue"; in$
  176.  
  177.     ' ================================================================================================================================================================
  178.     ' START NEW GAME
  179.     ' ================================================================================================================================================================
  180.  
  181.     ' ----------------------------------------------------------------------------------------------------------------------------------------------------------------
  182.     NewGame:
  183.    
  184.     Screen 0
  185.     Width 80, 60
  186.     arrGuy(0).Gold = 0
  187.     arrGuy(0).HP = 100
  188.     arrGuy(0).XP = 0
  189.     arrGuy(0).Level = 1
  190.     '_FullScreen
  191.    
  192.     ' ----------------------------------------------------------------------------------------------------------------------------------------------------------------
  193.     NewLevel:
  194.     Cls
  195.     bNewCave = FALSE
  196.     arrGuy(0).X = 40
  197.     arrGuy(0).Y = 30
  198.    
  199.     ' DRAW BORDERS
  200.     For iPosX = 2 To 79
  201.         For iPosY = 2 To 59
  202.             color cGray&
  203.             Locate iPosY, iPosX
  204.             Print "#";
  205.         Next iPosY
  206.     Next iPosX
  207.    
  208.     ' EMPTY OUT INSIDE
  209.     For iPosX = 5 To 76
  210.         For iPosY = 5 To 56
  211.             color cGray&
  212.             Locate iPosY, iPosX
  213.             Print ".";
  214.         Next iPosY
  215.     Next iPosX
  216.    
  217.     ' CREATE RANDOM WALLS
  218.     For iLoop = 0 To (80 * 60 / 8)
  219.         'color cGray&
  220.         'Locate Int(52 * Rnd + 5), Int(72 * Rnd + 5)
  221.         'Print "#";
  222.         x% = Int(72 * Rnd + 5)
  223.         y% = Int(52 * Rnd + 5)
  224.         PutCharXY x%, y%, "#", cGray&
  225.     Next iLoop
  226.    
  227.     ' SHOW PROGRESS
  228.     Locate 1, 40
  229.     Print "Step 1+" + cstr$(iLoop) + "    ";
  230.    
  231.     ' DROP RANDOM STUFF
  232.     For iLoop = 1 To 5
  233.         For iPosX = 5 To 75
  234.             For iPosY = 5 To 55
  235.                 ' DRAW WALL
  236.                 If Rnd < .15 And (Screen(iPosY - 1, iPosX) = 35 Or Screen(iPosY + 1, iPosX) = 35 Or Screen(iPosY, iPosX + 1) = 35 Or Screen(iPosY, iPosX - 1) = 35) Then
  237.                     'color cGray&
  238.                     'Locate iPosY, iPosX
  239.                     'Print "#";
  240.                     PutCharXY iPosX, iPosY, "#", cGray&
  241.                 End If
  242.                
  243.                 ' DRAW EMPTY
  244.                 If Screen(iPosY, iPosX) = 35 And (Screen(iPosY - 1, iPosX) = 46 And Screen(iPosY + 1, iPosX) = 46 And Screen(iPosY, iPosX + 1) = 46 And Screen(iPosY, iPosX - 1) = 46) Then
  245.                     'color cGray&
  246.                     'Locate iPosY, iPosX
  247.                     'Print ".";
  248.                     PutCharXY iPosX, iPosY, ".", cGray&
  249.                 End If
  250.                
  251.                 ' DRAW TREASURE
  252.                 If Rnd < .005 And Screen(iPosY, iPosX) = 46 Then
  253.                     'color cYellow&
  254.                     'Locate iPosY, iPosX
  255.                     'Print "*";
  256.                     PutCharXY iPosX, iPosY, "*", cYellow&
  257.                 End If
  258.                
  259.                 ' DRAW EXIT
  260.                 If Rnd < .001 And Screen(iPosY, iPosX) = 46 Then
  261.                     'color cWhite&
  262.                     'Locate iPosY, iPosX
  263.                     'Print "%";
  264.                     PutCharXY iPosX, iPosY, "%", cWhite&
  265.                 End If
  266.                
  267.             Next iPosY
  268.         Next iPosX
  269.        
  270.         ' SHOW PROGRESS
  271.         Locate 1, 40
  272.         Print "Step 2+" + cstr$(iLoop) + "    ";
  273.        
  274.     Next iLoop
  275.    
  276.     ' CLEAR SOME SPACE AROUND PLAYER
  277.     PutCharXY arrGuy(0).X - 1, arrGuy(0).Y - 1, ".", cGray&
  278.     PutCharXY arrGuy(0).X + 0, arrGuy(0).Y - 1, ".", cGray&
  279.     PutCharXY arrGuy(0).X + 1, arrGuy(0).Y - 1, ".", cGray&
  280.     PutCharXY arrGuy(0).X - 1, arrGuy(0).Y + 0, ".", cGray&
  281.     'PutCharXY arrGuy(0).X + 0, arrGuy(0).Y + 0, ".", cGray&
  282.     PutCharXY arrGuy(0).X + 1, arrGuy(0).Y + 0, ".", cGray&
  283.     PutCharXY arrGuy(0).X - 1, arrGuy(0).Y + 1, ".", cGray&
  284.     PutCharXY arrGuy(0).X + 0, arrGuy(0).Y + 1, ".", cGray&
  285.     PutCharXY arrGuy(0).X + 1, arrGuy(0).Y + 1, ".", cGray&
  286.    
  287.     ' PLACE MONSTERS
  288.     For iLoop = 1 To 15
  289.         bMonsterPlaced = FALSE
  290.         Do
  291.             '' Locate Y, X sets the current print position
  292.             'Locate Int(52 * Rnd + 5), Int(72 * Rnd + 5)
  293.             x% = Int(72 * Rnd + 5)
  294.             y% = Int(52 * Rnd + 5)
  295.            
  296.             '' Screen(CsrLin, Pos(0)) returns the character code at the current print position
  297.             'If Screen(CsrLin, Pos(0)) = 46 Then
  298.             If GetCharXY%(x%, y%) = 46 Then
  299.                 arrGuy(iLoop).X = x% ' Pos(0)
  300.                 arrGuy(iLoop).Y = y% ' CsrLin
  301.                 bMonsterPlaced = TRUE
  302.             End If
  303.         Loop Until bMonsterPlaced = TRUE
  304.     Next iLoop
  305.    
  306.     ' MAIN GAME LOOP
  307.     _Display
  308.     Do
  309.         ' GET KEYBOARD INPUT
  310.         K$ = InKey$
  311.        
  312.         ' DRAW PLAYER
  313.         'color cLtGray&
  314.         'Locate arrGuy(0).Y, arrGuy(0).X
  315.         'Print "@";
  316.         PutCharXY arrGuy(0).X, arrGuy(0).Y, "@", cLtGray&
  317.        
  318.         ' WRITE SCORE + STATS
  319.         color cWhite&
  320.         Locate 1, 1
  321.         Print "Gold:"; arrGuy(0).Gold, "HP:"; arrGuy(0).HP, "Exp:"; arrGuy(0).XP; "/"; (4 + arrGuy(0).Level * 2), "Level:"; arrGuy(0).Level;
  322.        
  323.         ' WRITE INSTRUCTIONS
  324.         color cWhite&
  325.         Locate 60, 1
  326.         Print "Arrows = Move", , "t = Teleport (-5HP on failure)";
  327.        
  328.         ' MOVE MONSTERS
  329.         For iLoop = 1 To 15
  330.             If arrGuy(0).XP >= (4 + arrGuy(0).Level * 2) Then
  331.                 arrGuy(0).XP = arrGuy(0).XP - (4 + arrGuy(0).Level * 2)
  332.                 arrGuy(0).Level = arrGuy(0).Level + 1
  333.                 arrGuy(0).HP = arrGuy(0).HP + (arrGuy(0).Level * 5)
  334.             End If
  335.            
  336.             If arrGuy(iLoop).X <> -1 And Rnd < .75 Then
  337.                 'color cGray&
  338.                 'Locate arrGuy(iLoop).Y, arrGuy(iLoop).X
  339.                 'Print ".";
  340.                 PutCharXY arrGuy(iLoop).X, arrGuy(iLoop).Y, ".", cGray&
  341.                
  342.                 If arrGuy(iLoop).X < arrGuy(0).X And Screen(arrGuy(iLoop).Y, arrGuy(iLoop).X + 1) = 46 Then
  343.                     arrGuy(iLoop).X = arrGuy(iLoop).X + 1
  344.                 End If
  345.                
  346.                 If arrGuy(iLoop).X > arrGuy(0).X And Screen(arrGuy(iLoop).Y, arrGuy(iLoop).X - 1) = 46 Then
  347.                     arrGuy(iLoop).X = arrGuy(iLoop).X - 1
  348.                 End If
  349.                
  350.                 If arrGuy(iLoop).Y < arrGuy(0).Y And Screen(arrGuy(iLoop).Y + 1, arrGuy(iLoop).X) = 46 Then
  351.                     arrGuy(iLoop).Y = arrGuy(iLoop).Y + 1
  352.                 End If
  353.                
  354.                 If arrGuy(iLoop).Y > arrGuy(0).Y And Screen(arrGuy(iLoop).Y - 1, arrGuy(iLoop).X) = 46 Then
  355.                     arrGuy(iLoop).Y = arrGuy(iLoop).Y - 1
  356.                 End If
  357.                
  358.                 'color cGreen&
  359.                 'Locate arrGuy(iLoop).Y, arrGuy(iLoop).X
  360.                 'Print Chr$(142);
  361.                 PutCharXY arrGuy(iLoop).X, arrGuy(iLoop).Y, Chr$(142), cGreen&
  362.                
  363.             End If
  364.         Next iLoop
  365.        
  366.         _Display
  367.        
  368.        
  369.         ' ERASE OLD POSITION
  370.         'color cGray&
  371.         'Locate arrGuy(0).Y, arrGuy(0).X
  372.         'Print ".";
  373.         PutCharXY arrGuy(0).X, arrGuy(0).Y, ".", cGray&
  374.        
  375.         ' SET NEXT POSITION = CURRENT
  376.         iNewCol = arrGuy(0).X
  377.         iNewRow = arrGuy(0).Y
  378.        
  379.         ' GET INPUT
  380.         K$ = GetKey$
  381.        
  382.         ' PROCESS INPUT
  383.         If K$ = Chr$(0) + "K" Then iNewCol = arrGuy(0).X - 1
  384.         If K$ = Chr$(0) + "M" Then iNewCol = arrGuy(0).X + 1
  385.         If K$ = Chr$(0) + "P" Then iNewRow = arrGuy(0).Y + 1
  386.         If K$ = Chr$(0) + "H" Then iNewRow = arrGuy(0).Y - 1
  387.        
  388.         ' TELEPORT TO A RANDOM LOCATION
  389.         If K$ = "t" Then
  390.             'color cWhite&
  391.             'Locate Int(52 * Rnd + 5), Int(72 * Rnd + 5)
  392.             'iNewCol = Pos(0)
  393.             'iNewRow = CsrLin
  394.             iNewCol = Int(72 * Rnd + 5)
  395.             iNewRow = Int(52 * Rnd + 5)
  396.             c% = GetCharXY%(iNewCol, iNewRow)
  397.            
  398.             ' IF YOU LAND ON NON-BLANK SPACE, LOSE HIT POINTS
  399.             'If Screen(CsrLin, Pos(0)) <> 46 Then
  400.             If c% <> 46 Then
  401.                 arrGuy(0).HP = arrGuy(0).HP - 5
  402.             End If
  403.         End If
  404.        
  405.         ' ATTACK MONSTER
  406.         'If Screen(iNewRow, iNewCol) = 142 Then
  407.         If GetCharXY%(iNewCol, iNewRow) = 142 Then
  408.            
  409.             ' GET EXPERIENCE
  410.             arrGuy(0).XP = arrGuy(0).XP + 1
  411.            
  412.             ' SUSTAIN DAMAGE
  413.             If Rnd > arrGuy(0).Level * .02 Then
  414.                 arrGuy(0).HP = arrGuy(0).HP - Int(20 * Rnd + arrGuy(0).Level)
  415.             End If
  416.            
  417.             ' ERASE OLD LOCATION
  418.             'color cGray&
  419.             'Locate iNewRow, iNewCol
  420.             'Print ".";
  421.             PutCharXY iNewCol, iNewRow, ".", cGray&
  422.            
  423.             ' DID MONSTERS REACH PLAYER?
  424.             For iLoop = 1 To 15
  425.                 If arrGuy(iLoop).X = iNewCol And arrGuy(iLoop).Y = iNewRow Then
  426.                     ' NOT SURE WHAT THIS IS FOR
  427.                     arrGuy(iLoop).X = -1
  428.                 End If
  429.             Next iLoop
  430.         End If
  431.        
  432.         ' PICK UP GOLD
  433.         If Screen(iNewRow, iNewCol) = 42 Then
  434.             arrGuy(0).Gold = arrGuy(0).Gold + Int((15 * Rnd + 1) * Rnd + 1)
  435.             'color cGray&
  436.             'Locate iNewRow, iNewCol
  437.             'Print ".";
  438.             PutCharXY iNewCol, iNewRow, ".", cGray&
  439.         End If
  440.        
  441.         ' EXIT CAVE
  442.         If Screen(iNewRow, iNewCol) = 37 Then
  443.             arrGuy(0).XP = arrGuy(0).XP + 5
  444.             bNewCave = TRUE
  445.             'color cGray&
  446.             'Locate iNewRow, iNewCol
  447.             'Print ".";
  448.             PutCharXY iNewCol, iNewRow, ".", cGray&
  449.         End If
  450.        
  451.         ' MOVE TO EMPTY SPACE
  452.         If Screen(iNewRow, iNewCol) = 46 Then
  453.             arrGuy(0).X = iNewCol
  454.             arrGuy(0).Y = iNewRow
  455.         Else
  456.             iNewRow = arrGuy(0).Y
  457.             iNewCol = arrGuy(0).X
  458.         End If
  459.        
  460.         ' KEEP GOING UNTIL QUIT (HIT ESC), OR DEAD, OR NEW CAVE
  461.     Loop While (K$ <> Chr$(27)) And arrGuy(0).HP > 0 And bNewCave = FALSE
  462.    
  463.     ' ================================================================================================================================================================
  464.     ' IS PLAYER DEAD?
  465.     If arrGuy(0).HP <= 0 Then
  466.         ' GAME OVER MAN
  467.         color cLtRed&
  468.         Locate 29, 31
  469.         Print "--== Game Over! ==--"
  470.     End If
  471.  
  472.     ' ================================================================================================================================================================
  473.     ' NEW CAVE
  474.     If bNewCave = TRUE Then
  475.         ' NEXT CAVE
  476.         color cPeriwinkle&
  477.         Locate 30, 35
  478.         Print "Next Cave!";
  479.        
  480.         _Display
  481.         'KEYDELAY 0
  482.         GoTo NewLevel
  483.     End If
  484.    
  485.     ' ================================================================================================================================================================
  486.     ' GAME OVER
  487.    
  488.     ' PLAY AGAIN?
  489.     color cWhite&
  490.     Locate 30, 33
  491.     Print "Play Again?(y/n)"
  492.     _Display
  493.    
  494.     K$ = YesOrNo$
  495.     If K$ = "y" Then
  496.         GoTo NewGame
  497.     End If
  498.    
  499. end sub ' Main
  500.  
  501. ' /////////////////////////////////////////////////////////////////////////////
  502. ' Convert a value to string and trim it (because normal Str$ adds spaces)
  503.  
  504. Function cstr$ (myValue)
  505.     'cstr$ = LTRIM$(RTRIM$(STR$(myValue)))
  506.     cstr$ = _Trim$(Str$(myValue))
  507. End Function ' cstr$
  508.  
  509. ' /////////////////////////////////////////////////////////////////////////////
  510.  
  511. Function GetCharXY%(x%, y%)
  512.     'Locate y%, x%
  513.     'GetCharXY% = Screen(CsrLin, Pos(0))
  514.     GetCharXY% = SCREEN(y%, x%, 0)     ' character code return parameter 0
  515. End Function ' GetCharXY%
  516.  
  517. ' /////////////////////////////////////////////////////////////////////////////
  518.  
  519. Function GetColorXY&(x%, y%)
  520.     GetColorXY& = SCREEN(y%, x%, 1)   ' character color return parameter 1
  521. End Function ' GetColorXY
  522.  
  523. ' /////////////////////////////////////////////////////////////////////////////
  524.  
  525. Sub PutCharXY(x%, y%, char$, myColor&)
  526.     color myColor&
  527.     Locate y%, x%
  528.     Print char$;
  529. End Sub ' PutCharXY
  530.  
  531. ' /////////////////////////////////////////////////////////////////////////////
  532.  
  533. Function GetKey$
  534.     DIM K$
  535.     K$ = ""
  536.     Do
  537.         K$ = InKey$
  538.     Loop While K$ = ""
  539.     GetKey$ = K$
  540. End Sub ' GetKey$
  541.  
  542. ' /////////////////////////////////////////////////////////////////////////////
  543.  
  544. Function YesOrNo$
  545.     Dim K$
  546.     Dim bFinished%
  547.    
  548.     bFinished% = FALSE
  549.     Do
  550.         K$ = lcase$(InKey$)
  551.         If K$ = "y" Or K$ = "n" Then
  552.             bFinished% = TRUE
  553.         End If
  554.     Loop While bFinished% = FALSE
  555.    
  556.     YesOrNo$ = K$
  557. End Function ' YesOrNo$
  558.  
  559. ' /////////////////////////////////////////////////////////////////////////////
  560.  
  561. ' ----------------------------------------------------------------------------------------------------------------------------------------------------------------
  562. ' COLOR CODE FUNCTIONS
  563. ' ----------------------------------------------------------------------------------------------------------------------------------------------------------------
  564. Function cBlue&
  565.     cBlue& = 1
  566.  
  567. Function cGreen&
  568.     cGreen& = 2
  569.  
  570. Function cLtBlue&
  571.     cLtBlue& = 3
  572.  
  573. Function cRed&
  574.     cRed& = 4
  575.  
  576. Function cPurple&
  577.     cPurple& = 5
  578.  
  579. Function cOrange&
  580.     cOrange& = 6
  581.  
  582. Function cWhite&
  583.     cWhite& = 7
  584.  
  585. Function cGray&
  586.     cGray& = 8
  587.  
  588. Function cPeriwinkle&
  589.     cPeriwinkle& = 9
  590.  
  591. Function cLtGreen&
  592.     cLtGreen& = 10
  593.  
  594. Function cCyan&
  595.     cCyan& = 11
  596.  
  597. Function cLtRed&
  598.     cLtRed& = 12
  599.  
  600. Function cPink&
  601.     cPink& = 13
  602.  
  603. Function cYellow&
  604.     cYellow& = 14
  605.  
  606. Function cLtGray&
  607.     cLtGray& = 15
  608.  
« Last Edit: May 28, 2021, 04:25:32 pm by madscijr »

Offline xra7en

  • Seasoned Forum Regular
  • Posts: 284
    • View Profile
Re: A QB64 roguelike in 50 lines prettified (now 625 lines)
« Reply #1 on: May 30, 2021, 10:46:06 am »
amazing!
Love anything DOS, which is why I love QB64!

Might have to play this. looks fun..
One thing you might wanna try it give your adventurer a light source and have him travel the map with just a circle of light, everything else is black!
I just like re-writing old DOS book games into modern QB64 code - weird hobby, I know!

Offline TempodiBasic

  • Forum Resident
  • Posts: 1792
    • View Profile
Re: A QB64 roguelike in 50 lines prettified (now 625 lines)
« Reply #2 on: May 30, 2021, 01:18:24 pm »
Cool!
... mmmh but where is the sound /music?
Waiting weapons to fight with monsters...
Programming isn't difficult, only it's  consuming time and coffee

Offline madscijr

  • Seasoned Forum Regular
  • Posts: 295
    • View Profile
Re: A QB64 roguelike in 50 lines prettified (now 625 lines)
« Reply #3 on: May 30, 2021, 01:33:50 pm »
amazing!
Love anything DOS, which is why I love QB64!

Might have to play this. looks fun..
One thing you might wanna try it give your adventurer a light source and have him travel the map with just a circle of light, everything else is black!

I made a list of possible future enhancements, the light idea is in there (see torch)!

Offline madscijr

  • Seasoned Forum Regular
  • Posts: 295
    • View Profile
Re: A QB64 roguelike in 50 lines prettified (now 625 lines)
« Reply #4 on: May 30, 2021, 01:36:15 pm »
Cool!
... mmmh but where is the sound /music?
Waiting weapons to fight with monsters...

As is, this was just the program as I found it, I just made the code easier to read. Sound effects & music, is a great idea, I just haven't added any mods. The farthest I got was listing some features I think it needs, sounds & music definitely belongs in there!

Note the code from my post here is my attempt at an RPG engine, where I am adapting this game with sounds and tile graphics:
https://www.qb64.org/forum/index.php?topic=3949.0

The thing is, it's a huge beast of a program with all those features, so I figured I'd post this much smaller one which is probably easier for people to digest :-)
« Last Edit: May 30, 2021, 01:41:37 pm by madscijr »

Offline Caligari87

  • Newbie
  • Posts: 1
    • View Profile
Re: A QB64 roguelike in 50 lines prettified (now 625 lines)
« Reply #5 on: September 25, 2021, 02:35:52 am »
Here's a program I came across at nippycodes.com which I cleaned up a little, maybe to expand in the future.
I'm not sure who the original author is, so I just cited the web site.
Hello! I know this is a fair few months bump but I wanted to comment that this was me!

Code: QB64: [Select]
  1. https://web.archive.org/web/20130410123327/www.[abandoned, outdated and now likely malicious qb64 dot net website - don’t go there]/forum/index.php?topic=10791.0
archive.org cache of original topic

Not sure how it ended up on nippycodes, but I'm glad someone's getting some mileage out of it. I'd be interested to see what else you've done with it in the meantime.
😎

Offline Petr

  • Forum Resident
  • Posts: 1720
  • The best code is the DNA of the hops.
    • View Profile
Re: A QB64 roguelike in 50 lines prettified (now 625 lines)
« Reply #6 on: September 25, 2021, 04:40:40 am »
@madscijr

Text mode is really not limitation for your game. I wrote small ugrade (in text mode) and if you now use fullscreen (for better view), your character @ is displayed in circle now. QB64 occurs really many options.

Code: QB64: [Select]
  1. 'Petr's modifications: Add TextCirlce& function [create hardware circle image],
  2. '                      Rows:  127, 128, 161, 330, 331, 382
  3.  
  4.  
  5. ' #############################################################################
  6. ' This game is from:
  7. '
  8. '     A QB64 roguelike in 50 lines
  9. '     https://nippycodes.com/coding/a-qb64-roguelike-in-50-lines/
  10. '
  11. ' cleaned up and made prettier.
  12.  
  13. ' ================================================================================================================================================================
  14. ' NOTES
  15. ' ================================================================================================================================================================
  16. ' The CSRLIN function returns the current text row position of the PRINT cursor.
  17. ' The POS function returns the current print cursor text column position.
  18. ' The SCREEN function returns the ASCII code of a text character or the color attribute at a set text location on the screen.
  19. ' codeorcolor% = SCREEN (row%, column% [, colorflag%])
  20. ' row and column are the INTEGER text coordinates of the SCREEN mode used.
  21. ' Optional colorflag INTEGER value can be omitted or 0 for ASCII code values or 1 for color attributes.
  22.  
  23. ' ================================================================================================================================================================
  24. ' TO DO
  25. ' ================================================================================================================================================================
  26. ' Code improvements:
  27. ' * Remove GOTO statements and make code more modular.
  28. ' * Store terrain, players, objects, etc. in different arrays/layers for more complex interaction
  29. ' * Include a level editor (not just random levels).
  30. ' * Add combat and RPG features similar to Ultima 1-5
  31. ' * Quests
  32. ' * Towns, Castles, etc.
  33.  
  34. ' Weapons:
  35. ' * Hands & Feet (default)
  36. ' * Club
  37. ' * Mace
  38. ' * Staff
  39. ' * Dagger
  40. ' * Sword
  41. ' * Great Sword
  42. ' * Spear
  43. ' * Bow / Arrow - player needs to find arrows
  44. ' * Sling - unlimited stones, can buy lead sling bullets for more damage
  45.  
  46. ' Armor:
  47. ' * Skin (default)
  48. ' * Cloth
  49. ' * Leather
  50. ' * Chain Mail
  51. ' * Plate
  52.  
  53. ' Armor (shields):
  54. ' * Leather Shield
  55. ' * Wood Shield
  56. ' * Small Metal Shield
  57. ' * Great Shield
  58.  
  59. ' Objects:
  60. ' * Healing Potion - restore HP
  61. ' * Torches - allow player to see in dark areas
  62.  
  63. ' Stats:
  64. ' * Food - decreases every n turns, if out of food player starves (loses HP)
  65. ' * Max HP - increases with higher levels
  66.  
  67. ' Attributes that affect combat, etc.:
  68. ' * Strength
  69. ' * Agility
  70. ' * Stamina
  71. ' * Intelligence
  72. ' * Wisdom
  73. ' * Charisma
  74. ' * weapon attack skill (increases per weapon type as you use it)
  75. ' * weapon defense skill (increases per weapon each time you fight someone with it)
  76.  
  77. ' Magic:
  78. ' ???
  79.  
  80. ' Monsters / NPCs:
  81. ' * different races
  82. ' * have their own inventory of items, food, etc.
  83. ' * have different HP, attributes, etc.
  84. ' * can be interacted with or yell things
  85.  
  86. ' Map:
  87. ' * include screens that are towns, not just random dungeons
  88.  
  89. ' Store:
  90. ' * buy weapons/armor/food/healing
  91. ' * located in certain "civilized" areas
  92.  
  93. ' ================================================================================================================================================================
  94. ' OPTIONS
  95. ' ================================================================================================================================================================
  96.  
  97. ' ================================================================================================================================================================
  98. ' GLOBAL DECLARATIONS a$=string, i%=integer, L&=long, s!=single, d#=double
  99. ' ================================================================================================================================================================
  100. CONST FALSE = 0
  101. CONST TRUE = NOT FALSE
  102.  
  103. ' ----------------------------------------------------------------------------------------------------------------------------------------------------------------
  104. ' UDFs
  105. ' ----------------------------------------------------------------------------------------------------------------------------------------------------------------
  106. TYPE PlayerType
  107.     X AS INTEGER
  108.     Y AS INTEGER
  109.  
  110.     ' NEW:
  111.     Items AS STRING
  112.     HP AS INTEGER
  113.     XP AS INTEGER
  114.     Level AS INTEGER
  115.     Gold AS INTEGER
  116. END TYPE ' PlayerType
  117.  
  118. DIM ProgramPath$
  119. DIM ProgramName$
  120.  
  121. ' =============================================================================
  122. ' INITIALIZE
  123. ProgramName$ = MID$(COMMAND$(0), _INSTRREV(COMMAND$(0), "\") + 1)
  124. ProgramPath$ = LEFT$(COMMAND$(0), _INSTRREV(COMMAND$(0), "\"))
  125.  
  126. DC& = TextCircle&
  127.  
  128. ' =============================================================================
  129. ' RUN THE MAIN PROGRAM
  130. main ProgramName$
  131.  
  132. ' =============================================================================
  133. ' FINISH
  134. SYSTEM ' return control to the operating system
  135. PRINT ProgramName$ + " finished."
  136.  
  137. ' /////////////////////////////////////////////////////////////////////////////
  138.  
  139. SUB main (ProgName$)
  140.     ' ----------------------------------------------------------------------------------------------------------------------------------------------------------------
  141.     ' VARIABLES
  142.     DIM iLoop AS INTEGER
  143.     DIM K$
  144.  
  145.     DIM iNewCol AS INTEGER
  146.     DIM iNewRow AS INTEGER
  147.     DIM iPosX AS INTEGER
  148.     DIM iPosY AS INTEGER
  149.     DIM x%
  150.     DIM y%
  151.     DIM c%
  152.     DIM bNewCave AS INTEGER
  153.  
  154.     DIM bMonsterPlaced AS INTEGER
  155.     DIM arrGuy(16) AS PlayerType
  156.  
  157.     DIM in$
  158.     DIM gPosX AS INTEGER, gPosY AS INTEGER
  159.  
  160.  
  161.  
  162.     ' ================================================================================================================================================================
  163.     ' SHOW INSTRUCTIONS
  164.     CLS
  165.     COLOR cPeriwinkle&: PRINT "-------------------------------------------------------------------------------"
  166.     COLOR cLtGreen&: PRINT "Rogue 50"
  167.     COLOR cCyan&: PRINT "(a simple game based on " + CHR$(34) + "A QB64 roguelike in 50 lines" + CHR$(34) + " from nippycodes.com)"
  168.     COLOR cPeriwinkle&: PRINT "-------------------------------------------------------------------------------"
  169.     COLOR cCyan&: PRINT "You are the adventurer........";: COLOR cWhite&: PRINT "@"
  170.     COLOR cCyan&: PRINT "Travel through the caves......";: COLOR cGray&: PRINT "#"
  171.     COLOR cCyan&: PRINT "Collect the treasure..........";: COLOR cYellow&: PRINT "*"
  172.     COLOR cCyan&: PRINT "And avoid the monsters........";: COLOR cGreen&: PRINT "A"
  173.     COLOR cCyan&: PRINT "Find doors to the next cave...";: COLOR cLtGray&: PRINT "%"
  174.     COLOR cCyan&: PRINT
  175.     COLOR cCyan&: PRINT "If you touch a monster you will battle,"
  176.     COLOR cCyan&: PRINT "and lose hit points but gain experience."
  177.     COLOR cCyan&: PRINT
  178.     COLOR cCyan&: PRINT "CONTROLS:"
  179.     COLOR cCyan&: PRINT "Use the arrow keys to move around."
  180.     COLOR cCyan&: PRINT "Press the ESC key when you want to quit."
  181.     COLOR cCyan&: PRINT
  182.     COLOR cCyan&: INPUT "Press ENTER to continue"; in$
  183.  
  184.     ' ================================================================================================================================================================
  185.     ' START NEW GAME
  186.     ' ================================================================================================================================================================
  187.  
  188.     ' ----------------------------------------------------------------------------------------------------------------------------------------------------------------
  189.     NewGame:
  190.  
  191.     SCREEN 0
  192.     WIDTH 80, 60
  193.     arrGuy(0).Gold = 0
  194.     arrGuy(0).HP = 100
  195.     arrGuy(0).XP = 0
  196.     arrGuy(0).Level = 1
  197.     '_FullScreen
  198.  
  199.     ' ----------------------------------------------------------------------------------------------------------------------------------------------------------------
  200.     NewLevel:
  201.     CLS
  202.     bNewCave = FALSE
  203.     arrGuy(0).X = 40
  204.     arrGuy(0).Y = 30
  205.  
  206.     ' DRAW BORDERS
  207.     FOR iPosX = 2 TO 79
  208.         FOR iPosY = 2 TO 59
  209.             COLOR cGray&
  210.             LOCATE iPosY, iPosX
  211.             PRINT "#";
  212.         NEXT iPosY
  213.     NEXT iPosX
  214.  
  215.     ' EMPTY OUT INSIDE
  216.     FOR iPosX = 5 TO 76
  217.         FOR iPosY = 5 TO 56
  218.             COLOR cGray&
  219.             LOCATE iPosY, iPosX
  220.             PRINT ".";
  221.         NEXT iPosY
  222.     NEXT iPosX
  223.  
  224.     ' CREATE RANDOM WALLS
  225.     FOR iLoop = 0 TO (80 * 60 / 8)
  226.         'color cGray&
  227.         'Locate Int(52 * Rnd + 5), Int(72 * Rnd + 5)
  228.         'Print "#";
  229.         x% = INT(72 * RND + 5)
  230.         y% = INT(52 * RND + 5)
  231.         PutCharXY x%, y%, "#", cGray&
  232.     NEXT iLoop
  233.  
  234.     ' SHOW PROGRESS
  235.     LOCATE 1, 40
  236.     PRINT "Step 1+" + cstr$(iLoop) + "    ";
  237.  
  238.     ' DROP RANDOM STUFF
  239.     FOR iLoop = 1 TO 5
  240.         FOR iPosX = 5 TO 75
  241.             FOR iPosY = 5 TO 55
  242.                 ' DRAW WALL
  243.                 IF RND < .15 AND (SCREEN(iPosY - 1, iPosX) = 35 OR SCREEN(iPosY + 1, iPosX) = 35 OR SCREEN(iPosY, iPosX + 1) = 35 OR SCREEN(iPosY, iPosX - 1) = 35) THEN
  244.                     'color cGray&
  245.                     'Locate iPosY, iPosX
  246.                     'Print "#";
  247.                     PutCharXY iPosX, iPosY, "#", cGray&
  248.                 END IF
  249.  
  250.                 ' DRAW EMPTY
  251.                 IF SCREEN(iPosY, iPosX) = 35 AND (SCREEN(iPosY - 1, iPosX) = 46 AND SCREEN(iPosY + 1, iPosX) = 46 AND SCREEN(iPosY, iPosX + 1) = 46 AND SCREEN(iPosY, iPosX - 1) = 46) THEN
  252.                     'color cGray&
  253.                     'Locate iPosY, iPosX
  254.                     'Print ".";
  255.                     PutCharXY iPosX, iPosY, ".", cGray&
  256.                 END IF
  257.  
  258.                 ' DRAW TREASURE
  259.                 IF RND < .005 AND SCREEN(iPosY, iPosX) = 46 THEN
  260.                     'color cYellow&
  261.                     'Locate iPosY, iPosX
  262.                     'Print "*";
  263.                     PutCharXY iPosX, iPosY, "*", cYellow&
  264.                 END IF
  265.  
  266.                 ' DRAW EXIT
  267.                 IF RND < .001 AND SCREEN(iPosY, iPosX) = 46 THEN
  268.                     'color cWhite&
  269.                     'Locate iPosY, iPosX
  270.                     'Print "%";
  271.                     PutCharXY iPosX, iPosY, "%", cWhite&
  272.                 END IF
  273.  
  274.             NEXT iPosY
  275.         NEXT iPosX
  276.  
  277.         ' SHOW PROGRESS
  278.         LOCATE 1, 40
  279.         PRINT "Step 2+" + cstr$(iLoop) + "    ";
  280.  
  281.     NEXT iLoop
  282.  
  283.     ' CLEAR SOME SPACE AROUND PLAYER
  284.     PutCharXY arrGuy(0).X - 1, arrGuy(0).Y - 1, ".", cGray&
  285.     PutCharXY arrGuy(0).X + 0, arrGuy(0).Y - 1, ".", cGray&
  286.     PutCharXY arrGuy(0).X + 1, arrGuy(0).Y - 1, ".", cGray&
  287.     PutCharXY arrGuy(0).X - 1, arrGuy(0).Y + 0, ".", cGray&
  288.     'PutCharXY arrGuy(0).X + 0, arrGuy(0).Y + 0, ".", cGray&
  289.     PutCharXY arrGuy(0).X + 1, arrGuy(0).Y + 0, ".", cGray&
  290.     PutCharXY arrGuy(0).X - 1, arrGuy(0).Y + 1, ".", cGray&
  291.     PutCharXY arrGuy(0).X + 0, arrGuy(0).Y + 1, ".", cGray&
  292.     PutCharXY arrGuy(0).X + 1, arrGuy(0).Y + 1, ".", cGray&
  293.  
  294.     ' PLACE MONSTERS
  295.     FOR iLoop = 1 TO 15
  296.         bMonsterPlaced = FALSE
  297.         DO
  298.             '' Locate Y, X sets the current print position
  299.             'Locate Int(52 * Rnd + 5), Int(72 * Rnd + 5)
  300.             x% = INT(72 * RND + 5)
  301.             y% = INT(52 * RND + 5)
  302.  
  303.             '' Screen(CsrLin, Pos(0)) returns the character code at the current print position
  304.             'If Screen(CsrLin, Pos(0)) = 46 Then
  305.             IF GetCharXY%(x%, y%) = 46 THEN
  306.                 arrGuy(iLoop).X = x% ' Pos(0)
  307.                 arrGuy(iLoop).Y = y% ' CsrLin
  308.                 bMonsterPlaced = TRUE
  309.             END IF
  310.         LOOP UNTIL bMonsterPlaced = TRUE
  311.     NEXT iLoop
  312.  
  313.     ' MAIN GAME LOOP
  314.     _DISPLAY
  315.  
  316.     DO
  317.         ' GET KEYBOARD INPUT
  318.         K$ = INKEY$
  319.  
  320.         ' DRAW PLAYER
  321.         'color cLtGray&
  322.         'Locate arrGuy(0).Y, arrGuy(0).X
  323.         'Print "@";
  324.         PutCharXY arrGuy(0).X, arrGuy(0).Y, "@", cLtGray&
  325.  
  326.         gPosX = arrGuy(0).X * 8 - 12 '-12 is for center image to text coordinate
  327.         gPosY = arrGuy(0).Y * 8 - 12
  328.  
  329.  
  330.         ' WRITE SCORE + STATS
  331.         COLOR cWhite&
  332.         LOCATE 1, 1
  333.         PRINT "Gold:"; arrGuy(0).Gold, "HP:"; arrGuy(0).HP, "Exp:"; arrGuy(0).XP; "/"; (4 + arrGuy(0).Level * 2), "Level:"; arrGuy(0).Level;
  334.  
  335.         ' WRITE INSTRUCTIONS
  336.         COLOR cWhite&
  337.         LOCATE 60, 1
  338.         PRINT "Arrows = Move", , "t = Teleport (-5HP on failure)";
  339.  
  340.         ' MOVE MONSTERS
  341.         FOR iLoop = 1 TO 15
  342.             IF arrGuy(0).XP >= (4 + arrGuy(0).Level * 2) THEN
  343.                 arrGuy(0).XP = arrGuy(0).XP - (4 + arrGuy(0).Level * 2)
  344.                 arrGuy(0).Level = arrGuy(0).Level + 1
  345.                 arrGuy(0).HP = arrGuy(0).HP + (arrGuy(0).Level * 5)
  346.             END IF
  347.  
  348.             IF arrGuy(iLoop).X <> -1 AND RND < .75 THEN
  349.                 'color cGray&
  350.                 'Locate arrGuy(iLoop).Y, arrGuy(iLoop).X
  351.                 'Print ".";
  352.                 PutCharXY arrGuy(iLoop).X, arrGuy(iLoop).Y, ".", cGray&
  353.  
  354.                 IF arrGuy(iLoop).X < arrGuy(0).X AND SCREEN(arrGuy(iLoop).Y, arrGuy(iLoop).X + 1) = 46 THEN
  355.                     arrGuy(iLoop).X = arrGuy(iLoop).X + 1
  356.                 END IF
  357.  
  358.                 IF arrGuy(iLoop).X > arrGuy(0).X AND SCREEN(arrGuy(iLoop).Y, arrGuy(iLoop).X - 1) = 46 THEN
  359.                     arrGuy(iLoop).X = arrGuy(iLoop).X - 1
  360.                 END IF
  361.  
  362.                 IF arrGuy(iLoop).Y < arrGuy(0).Y AND SCREEN(arrGuy(iLoop).Y + 1, arrGuy(iLoop).X) = 46 THEN
  363.                     arrGuy(iLoop).Y = arrGuy(iLoop).Y + 1
  364.                 END IF
  365.  
  366.                 IF arrGuy(iLoop).Y > arrGuy(0).Y AND SCREEN(arrGuy(iLoop).Y - 1, arrGuy(iLoop).X) = 46 THEN
  367.                     arrGuy(iLoop).Y = arrGuy(iLoop).Y - 1
  368.                 END IF
  369.  
  370.                 'color cGreen&
  371.                 'Locate arrGuy(iLoop).Y, arrGuy(iLoop).X
  372.                 'Print Chr$(142);
  373.                 PutCharXY arrGuy(iLoop).X, arrGuy(iLoop).Y, CHR$(142), cGreen&
  374.  
  375.             END IF
  376.         NEXT iLoop
  377.  
  378.         _PUTIMAGE (gPosX, gPosY), DC&
  379.         _DISPLAY
  380.  
  381.  
  382.         ' ERASE OLD POSITION
  383.         'color cGray&
  384.         'Locate arrGuy(0).Y, arrGuy(0).X
  385.         'Print ".";
  386.         PutCharXY arrGuy(0).X, arrGuy(0).Y, ".", cGray&
  387.  
  388.         ' SET NEXT POSITION = CURRENT
  389.         iNewCol = arrGuy(0).X
  390.         iNewRow = arrGuy(0).Y
  391.  
  392.         ' GET INPUT
  393.         K$ = GetKey$
  394.  
  395.         ' PROCESS INPUT
  396.         IF K$ = CHR$(0) + "K" THEN iNewCol = arrGuy(0).X - 1
  397.         IF K$ = CHR$(0) + "M" THEN iNewCol = arrGuy(0).X + 1
  398.         IF K$ = CHR$(0) + "P" THEN iNewRow = arrGuy(0).Y + 1
  399.         IF K$ = CHR$(0) + "H" THEN iNewRow = arrGuy(0).Y - 1
  400.  
  401.         ' TELEPORT TO A RANDOM LOCATION
  402.         IF K$ = "t" THEN
  403.             'color cWhite&
  404.             'Locate Int(52 * Rnd + 5), Int(72 * Rnd + 5)
  405.             'iNewCol = Pos(0)
  406.             'iNewRow = CsrLin
  407.             iNewCol = INT(72 * RND + 5)
  408.             iNewRow = INT(52 * RND + 5)
  409.             c% = GetCharXY%(iNewCol, iNewRow)
  410.  
  411.             ' IF YOU LAND ON NON-BLANK SPACE, LOSE HIT POINTS
  412.             'If Screen(CsrLin, Pos(0)) <> 46 Then
  413.             IF c% <> 46 THEN
  414.                 arrGuy(0).HP = arrGuy(0).HP - 5
  415.             END IF
  416.         END IF
  417.  
  418.         ' ATTACK MONSTER
  419.         'If Screen(iNewRow, iNewCol) = 142 Then
  420.         IF GetCharXY%(iNewCol, iNewRow) = 142 THEN
  421.  
  422.             ' GET EXPERIENCE
  423.             arrGuy(0).XP = arrGuy(0).XP + 1
  424.  
  425.             ' SUSTAIN DAMAGE
  426.             IF RND > arrGuy(0).Level * .02 THEN
  427.                 arrGuy(0).HP = arrGuy(0).HP - INT(20 * RND + arrGuy(0).Level)
  428.             END IF
  429.  
  430.             ' ERASE OLD LOCATION
  431.             'color cGray&
  432.             'Locate iNewRow, iNewCol
  433.             'Print ".";
  434.             PutCharXY iNewCol, iNewRow, ".", cGray&
  435.  
  436.             ' DID MONSTERS REACH PLAYER?
  437.             FOR iLoop = 1 TO 15
  438.                 IF arrGuy(iLoop).X = iNewCol AND arrGuy(iLoop).Y = iNewRow THEN
  439.                     ' NOT SURE WHAT THIS IS FOR
  440.                     arrGuy(iLoop).X = -1
  441.                 END IF
  442.             NEXT iLoop
  443.         END IF
  444.  
  445.         ' PICK UP GOLD
  446.         IF SCREEN(iNewRow, iNewCol) = 42 THEN
  447.             arrGuy(0).Gold = arrGuy(0).Gold + INT((15 * RND + 1) * RND + 1)
  448.             'color cGray&
  449.             'Locate iNewRow, iNewCol
  450.             'Print ".";
  451.             PutCharXY iNewCol, iNewRow, ".", cGray&
  452.         END IF
  453.  
  454.         ' EXIT CAVE
  455.         IF SCREEN(iNewRow, iNewCol) = 37 THEN
  456.             arrGuy(0).XP = arrGuy(0).XP + 5
  457.             bNewCave = TRUE
  458.             'color cGray&
  459.             'Locate iNewRow, iNewCol
  460.             'Print ".";
  461.             PutCharXY iNewCol, iNewRow, ".", cGray&
  462.         END IF
  463.  
  464.         ' MOVE TO EMPTY SPACE
  465.         IF SCREEN(iNewRow, iNewCol) = 46 THEN
  466.             arrGuy(0).X = iNewCol
  467.             arrGuy(0).Y = iNewRow
  468.         ELSE
  469.             iNewRow = arrGuy(0).Y
  470.             iNewCol = arrGuy(0).X
  471.         END IF
  472.  
  473.         ' KEEP GOING UNTIL QUIT (HIT ESC), OR DEAD, OR NEW CAVE
  474.     LOOP WHILE (K$ <> CHR$(27)) AND arrGuy(0).HP > 0 AND bNewCave = FALSE
  475.  
  476.     ' ================================================================================================================================================================
  477.     ' IS PLAYER DEAD?
  478.     IF arrGuy(0).HP <= 0 THEN
  479.         ' GAME OVER MAN
  480.         COLOR cLtRed&
  481.         LOCATE 29, 31
  482.         PRINT "--== Game Over! ==--"
  483.     END IF
  484.  
  485.     ' ================================================================================================================================================================
  486.     ' NEW CAVE
  487.     IF bNewCave = TRUE THEN
  488.         ' NEXT CAVE
  489.         COLOR cPeriwinkle&
  490.         LOCATE 30, 35
  491.         PRINT "Next Cave!";
  492.  
  493.         _DISPLAY
  494.         'KEYDELAY 0
  495.         GOTO NewLevel
  496.     END IF
  497.  
  498.     ' ================================================================================================================================================================
  499.     ' GAME OVER
  500.  
  501.     ' PLAY AGAIN?
  502.     COLOR cWhite&
  503.     LOCATE 30, 33
  504.     PRINT "Play Again?(y/n)"
  505.     _DISPLAY
  506.  
  507.     K$ = YesOrNo$
  508.     IF K$ = "y" THEN
  509.         GOTO NewGame
  510.     END IF
  511.  
  512. END SUB ' Main
  513.  
  514. ' /////////////////////////////////////////////////////////////////////////////
  515. ' Convert a value to string and trim it (because normal Str$ adds spaces)
  516.  
  517. FUNCTION cstr$ (myValue)
  518.     'cstr$ = LTRIM$(RTRIM$(STR$(myValue)))
  519.     cstr$ = _TRIM$(STR$(myValue))
  520. END FUNCTION ' cstr$
  521.  
  522. ' /////////////////////////////////////////////////////////////////////////////
  523.  
  524. FUNCTION GetCharXY% (x%, y%)
  525.     'Locate y%, x%
  526.     'GetCharXY% = Screen(CsrLin, Pos(0))
  527.     GetCharXY% = SCREEN(y%, x%, 0) ' character code return parameter 0
  528. END FUNCTION ' GetCharXY%
  529.  
  530. ' /////////////////////////////////////////////////////////////////////////////
  531.  
  532. FUNCTION GetColorXY& (x%, y%)
  533.     GetColorXY& = SCREEN(y%, x%, 1) ' character color return parameter 1
  534. END FUNCTION ' GetColorXY
  535.  
  536. ' /////////////////////////////////////////////////////////////////////////////
  537.  
  538. SUB PutCharXY (x%, y%, char$, myColor&)
  539.     COLOR myColor&
  540.     LOCATE y%, x%
  541.     PRINT char$;
  542. END SUB ' PutCharXY
  543.  
  544. ' /////////////////////////////////////////////////////////////////////////////
  545.  
  546. FUNCTION GetKey$
  547.     DIM K$
  548.     K$ = ""
  549.     DO
  550.         K$ = INKEY$
  551.     LOOP WHILE K$ = ""
  552.     GetKey$ = K$
  553. END SUB ' GetKey$
  554.  
  555. ' /////////////////////////////////////////////////////////////////////////////
  556.  
  557. FUNCTION YesOrNo$
  558.     DIM K$
  559.     DIM bFinished%
  560.  
  561.     bFinished% = FALSE
  562.     DO
  563.         K$ = LCASE$(INKEY$)
  564.         IF K$ = "y" OR K$ = "n" THEN
  565.             bFinished% = TRUE
  566.         END IF
  567.     LOOP WHILE bFinished% = FALSE
  568.  
  569.     YesOrNo$ = K$
  570. END FUNCTION ' YesOrNo$
  571.  
  572. ' /////////////////////////////////////////////////////////////////////////////
  573.  
  574. ' ----------------------------------------------------------------------------------------------------------------------------------------------------------------
  575. ' COLOR CODE FUNCTIONS
  576. ' ----------------------------------------------------------------------------------------------------------------------------------------------------------------
  577. FUNCTION cBlue&
  578.     cBlue& = 1
  579.  
  580. FUNCTION cGreen&
  581.     cGreen& = 2
  582.  
  583. FUNCTION cLtBlue&
  584.     cLtBlue& = 3
  585.  
  586. FUNCTION cRed&
  587.     cRed& = 4
  588.  
  589. FUNCTION cPurple&
  590.     cPurple& = 5
  591.  
  592. FUNCTION cOrange&
  593.     cOrange& = 6
  594.  
  595. FUNCTION cWhite&
  596.     cWhite& = 7
  597.  
  598. FUNCTION cGray&
  599.     cGray& = 8
  600.  
  601. FUNCTION cPeriwinkle&
  602.     cPeriwinkle& = 9
  603.  
  604. FUNCTION cLtGreen&
  605.     cLtGreen& = 10
  606.  
  607. FUNCTION cCyan&
  608.     cCyan& = 11
  609.  
  610. FUNCTION cLtRed&
  611.     cLtRed& = 12
  612.  
  613. FUNCTION cPink&
  614.     cPink& = 13
  615.  
  616. FUNCTION cYellow&
  617.     cYellow& = 14
  618.  
  619. FUNCTION cLtGray&
  620.     cLtGray& = 15
  621.  
  622. FUNCTION TextCircle& 'create HARDWARE image, this can be placed also to SCREEN 0, but _DISPLAY must be always used!
  623.     DIM s AS LONG, o
  624.     s = _NEWIMAGE(16, 16, 32)
  625.     o = _DEST
  626.     _DEST s
  627.     CIRCLE (7, 7), 7, &HFFFFFFFF
  628.     _DEST o
  629.     TextCircle& = _COPYIMAGE(s, 33)
  630.     _FREEIMAGE s
  631.  

Offline madscijr

  • Seasoned Forum Regular
  • Posts: 295
    • View Profile
Re: A QB64 roguelike in 50 lines prettified (now 625 lines)
« Reply #7 on: November 23, 2021, 12:25:44 pm »
Sorry for the delayed response, I have been a little busy...

Hello! I know this is a fair few months bump but I wanted to comment that this was me!
interested to see what else you've done with it in the meantime.

Aha, mystery solved!
I haven't gotten back to this little project yet, but when I do, i will definitely post an update.

Got any other RPG or other QuickBasic programs to share? LoL
« Last Edit: November 23, 2021, 11:21:26 pm by madscijr »

Offline madscijr

  • Seasoned Forum Regular
  • Posts: 295
    • View Profile
Re: A QB64 roguelike in 50 lines prettified (now 625 lines)
« Reply #8 on: November 23, 2021, 12:27:07 pm »
@madscijr
Text mode is really not limitation for your game. I wrote small ugrade (in text mode) and if you now use fullscreen (for better view), your character @ is displayed in circle now. QB64 occurs really many options.

Neat!
Thanks for sharing that!