Author Topic: Little maze thing with silly creature generator  (Read 4055 times)

0 Members and 1 Guest are viewing this topic.

Offline Cobalt

  • QB64 Developer
  • Forum Resident
  • Posts: 878
  • At 60 I become highly radioactive!
    • View Profile
Little maze thing with silly creature generator
« on: September 22, 2019, 04:56:55 pm »
taking my maze, or rather labyrinth, generator from https://www.qb64.org/forum/index.php?topic=848.0 and added a creature generator based on a very simplistic mechanism using Nouns, Adjectives, and Verbs to make some bizarre results. Some times they don't make sense but other times they can be very amusing, larger lists would improve this of course but I just wanted to see if I could even pull it off so the lists used are very short.

Code: QB64: [Select]
  1. 'on demand random retraceable maze
  2. TYPE Roomlook
  3.  up AS _BYTE
  4.  down AS _BYTE
  5.  left AS _BYTE
  6.  right AS _BYTE
  7.  
  8. TYPE room
  9.  North AS INTEGER 'what room lies in direction
  10.  South AS INTEGER
  11.  East AS INTEGER
  12.  West AS INTEGER
  13.  Walls AS Roomlook 'walls or passages
  14.  Created AS _BYTE 'as this room been visited?
  15.  Has_Trea AS _BYTE '0-4 max
  16.  Has_Mons AS _BYTE '0-3 max
  17.  
  18. TYPE Monsters
  19.  Noun AS _BYTE
  20.  Adjt AS _BYTE
  21.  Verb AS _BYTE
  22.  Atk AS _BYTE
  23.  Hp AS _BYTE
  24.  
  25. TYPE Treasures
  26.  Id AS _BYTE
  27.  Valu AS _UNSIGNED _BYTE 'number of gold or gems
  28.  Loose AS _BYTE 'in a container or loose on ground
  29.  locked AS _BYTE 'is container locked?
  30.  Corner AS _BYTE 'which corner is treasure lying in?
  31. 'OPEN "debug.txt" FOR OUTPUT AS #1
  32.  
  33. DIM SHARED Maze(32000) AS room, a$, b$, c$(1), d$(5), e$(1)
  34. DIM SHARED Mons(64000) AS Monsters, Tres(64000) AS Treasures
  35. DIM SHARED M(127) AS STRING * 16, A(127) AS STRING * 16, V(127) AS STRING * 16, W(127) AS STRING * 16
  36. DIM SHARED T(127) AS STRING * 32
  37. DIM SHARED lastmade%, wall$(3), Max_Mons_Noun AS _BYTE, Max_Mons_Adj AS _BYTE, Max_Mons_Verb AS _BYTE, Max_Mons_Weapon AS _BYTE
  38. DIM SHARED Monster_Count AS _UNSIGNED INTEGER
  39.  
  40. 'Preliminary monster controls
  41. CONST Max_Mons_Count = 250 'how many monsters to try to add to the maze(max 64000)
  42. CONST Mons_Chance = 75 'chance of monster appearing in room being made 0-100
  43. CONST Max_Mons_Room = 100 'the highest room number to contain a monster(max 32000)
  44. '-----------------------------
  45.  
  46. CONST TRUE = -1, FALSE = NOT TRUE
  47. CONST UP = 1, DOWN = 2, LEFT = 3, RIGHT = 4
  48. a$ = "To the "
  49. b$ = " there is a "
  50. c$(0) = "wall": c$(1) = "passage"
  51. d$(UP) = "north": d$(DOWN) = "south": d$(LEFT) = "west": d$(RIGHT) = "east"
  52. e$(0) = "unknown": e$(1) = "known"
  53. Nouns:
  54. DATA 11,"Rat","Spider","Bat","Snake","Dog","Cat","Lizard","Bear","Politician","Bearded Woman","Hairy Man"
  55. Adjectives:
  56. DATA 7,"Large","Huge","Mal-formed","Curvaceous","Busty","Masculine","Foul"
  57. Verbs:
  58. DATA 6,"swing","lunge","assault","gnaw","slash","suffocate"
  59. Weapon:
  60. DATA 9,"Bare Fist","Teeth","Fangs","Claws","Whip-like Tail","Racid Odor","Acidic Bile","Hard Feces","Grotesque Looks"
  61. Treasure:
  62. DATA 6,"Coin","Gem","Goblet","Ingot","Crown","Artifact"
  63. 'make maze ready to explore
  64. ClearMaze
  65. makerooms 'premake some wall sections
  66. Load_Monsters
  67. Add_Mons
  68. LOCATE 22, 1: PRINT Monster_Count
  69. 'create the starting room
  70. 'pick which walls you can pass
  71. Maze(0).Walls.up = INT(RND * 2)
  72. Maze(0).Walls.down = INT(RND * 2)
  73. Maze(0).Walls.left = INT(RND * 2)
  74. Maze(0).Walls.right = INT(RND * 2)
  75. Maze(0).Created = TRUE
  76.  
  77. current% = 0 'room player is in
  78. lastmade% = 0 'last room created
  79.  
  80.  LOCATE 8, , 0 ' turn cursor off
  81.  DescribeRoom current%
  82.  
  83.  drawroom current%
  84.  LOCATE 8, 1, 1 ' turn cursor on
  85.  
  86.  DO
  87.   kbd& = _KEYHIT
  88.   _DELAY .05
  89.  LOOP UNTIL kbd&
  90.  
  91.  SELECT CASE kbd&
  92.   CASE 18432 'up
  93.    MessageHandler "You head north..."
  94.    IF Maze(current%).Walls.up THEN 'if you can go up
  95.     IF Maze(current%).North >= 0 THEN 'is north already referenced
  96.      MessageHandler "you have been here before"
  97.      current% = Maze(current%).North
  98.     ELSE 'never been north in this room
  99.      MessageHandler "you find somewhere new"
  100.      lastmade% = lastmade% + 1
  101.      nul% = CreateRoom(lastmade%, current%, UP)
  102.      current% = lastmade%
  103.     END IF
  104.    END IF
  105.   CASE 20480 'down
  106.    MessageHandler "You head south..."
  107.    IF Maze(current%).Walls.down THEN 'if you can go down
  108.     IF Maze(current%).South >= 0 THEN 'is south already referenced
  109.      MessageHandler "you have been here before"
  110.      current% = Maze(current%).South
  111.     ELSE 'never been south in this room
  112.      MessageHandler "you find somewhere new"
  113.      lastmade% = lastmade% + 1
  114.      nul% = CreateRoom(lastmade%, current%, DOWN)
  115.      current% = lastmade%
  116.     END IF
  117.    END IF
  118.   CASE 19200 'left
  119.    MessageHandler "You head west..."
  120.    IF Maze(current%).Walls.left THEN 'if you can go left
  121.     IF Maze(current%).West >= 0 THEN 'is west already referenced
  122.      MessageHandler "you have been here before"
  123.      current% = Maze(current%).West
  124.     ELSE 'never been west in this room
  125.      MessageHandler "you find somewhere new"
  126.      lastmade% = lastmade% + 1
  127.      nul% = CreateRoom(lastmade%, current%, LEFT)
  128.      current% = lastmade%
  129.     END IF
  130.    END IF
  131.   CASE 19712 'right
  132.    MessageHandler "You head east..."
  133.    IF Maze(current%).Walls.right THEN 'if you can go right
  134.     IF Maze(current%).East >= 0 THEN 'is east already referenced
  135.      MessageHandler "you have been here before"
  136.      current% = Maze(current%).East
  137.     ELSE 'never been north in this room
  138.      MessageHandler "you find somewhere new"
  139.      lastmade% = lastmade% + 1
  140.      nul% = CreateRoom(lastmade%, current%, RIGHT)
  141.      current% = lastmade%
  142.     END IF
  143.    END IF
  144.   CASE 27
  145.    exitflag%% = TRUE
  146.  kbd& = 0
  147. LOOP UNTIL exitflag%%
  148.  
  149.  
  150. FUNCTION CreateRoom (Going%, From%, Direction%%)
  151.  Maze(Going%).Walls.up = INT(RND * 2)
  152.  Maze(Going%).Walls.down = INT(RND * 2)
  153.  Maze(Going%).Walls.left = INT(RND * 2)
  154.  Maze(Going%).Walls.right = INT(RND * 2)
  155.  Maze(Going%).Created = TRUE
  156.  'which direction did player head
  157.  SELECT CASE Direction%%
  158.   CASE UP 'player went up
  159.    Maze(Going%).Walls.down = 1 'down has to be open, direction coming from
  160.    Maze(Going%).South = From% 'south goes back to previous room
  161.    Maze(From%).North = Going% 'the room id north of previous room
  162.   CASE DOWN
  163.    Maze(Going%).Walls.up = 1 'up has to be open, direction coming from
  164.    Maze(Going%).North = From% 'north goes back to previous room
  165.    Maze(From%).South = Going% 'the room id south of previous room
  166.   CASE LEFT
  167.    Maze(Going%).Walls.right = 1 'left has to be open, direction coming from
  168.    Maze(Going%).East = From% 'east goes back to previous room
  169.    Maze(From%).West = Going% 'the room id west of previous room
  170.   CASE RIGHT
  171.    Maze(Going%).Walls.left = 1 'right has to be open, direction coming from
  172.    Maze(Going%).West = From% 'west goes back to previous room
  173.    Maze(From%).East = Going% 'the room id east of previous room
  174.  
  175. SUB DescribeRoom (id%)
  176.  MessageHandler "You are currently in room" + STR$(id%)
  177.  MessageHandler a$ + d$(UP) + b$ + c$(Maze(id%).Walls.up)
  178.  MessageHandler a$ + d$(DOWN) + b$ + c$(Maze(id%).Walls.down)
  179.  MessageHandler a$ + d$(LEFT) + b$ + c$(Maze(id%).Walls.left)
  180.  MessageHandler a$ + d$(RIGHT) + b$ + c$(Maze(id%).Walls.right)
  181.  MessageHandler blank$
  182.  IF Maze(id%).Has_Mons THEN Describe_Mons (id%)
  183.  
  184. SUB ClearMaze
  185.  FOR i% = 0 TO 32000
  186.   Maze(i%).North = -1
  187.   Maze(i%).South = -1
  188.   Maze(i%).West = -1
  189.   Maze(i%).East = -1
  190.   Maze(i%).Created = FALSE
  191.  NEXT i%
  192.  
  193. SUB dumpmap
  194.  FOR i% = 0 TO lastmade%
  195.   PRINT #1, "room ID"; i%
  196.   PRINT #1, "north leads to "; Maze(i%).North
  197.   PRINT #1, "south leads to "; Maze(i%).South
  198.   PRINT #1, "west leads to "; Maze(i%).West
  199.   PRINT #1, "east leads to "; Maze(i%).East
  200.   PRINT #1, "up wall status "; Maze(i%).Walls.up
  201.   PRINT #1, "down wall status "; Maze(i%).Walls.down
  202.   PRINT #1, "left wall status "; Maze(i%).Walls.left
  203.   PRINT #1, "right wall status "; Maze(i%).Walls.right
  204.   PRINT #1,
  205.  NEXT i%
  206.  
  207. SUB drawroom (id%)
  208.  IF Maze(id%).Walls.up THEN 'has passage
  209.   LOCATE 10, 1: PRINT wall$(1)
  210.   LOCATE 10, 1: PRINT wall$(0)
  211.  FOR i%% = 11 TO 20
  212.   LOCATE i%%, 2: PRINT "³"
  213.   LOCATE i%%, 11: PRINT "³"
  214.  NEXT i%%
  215.  IF Maze(id%).Walls.left THEN 'has passage
  216.   LOCATE 14, 2: PRINT "Ù": LOCATE 15, 2: PRINT " ": LOCATE 16, 2: PRINT "¿"
  217.  IF Maze(id%).Walls.right THEN 'has passage
  218.   LOCATE 14, 11: PRINT "À": LOCATE 15, 11: PRINT " ": LOCATE 16, 11: PRINT "Ú"
  219.  IF Maze(id%).Walls.down THEN 'has passage
  220.   LOCATE 21, 1: PRINT wall$(3)
  221.   LOCATE 21, 1: PRINT wall$(2)
  222.  
  223. SUB makerooms
  224.  'ÚÄ¿³ÀÙ
  225.  wall$(0) = " ÚÄÄÄÄÄÄÄÄ¿ "
  226.  wall$(1) = " ÚÄÄÙ  Ã€Ã„Ä¿ "
  227.  wall$(2) = " ÀÄÄÄÄÄÄÄÄÙ "
  228.  wall$(3) = " ÀÄÄ¿  ÃšÃ„ÄÙ "
  229.  
  230. SUB Add_Mons
  231.  FOR I~% = 1 TO Max_Mons_Count
  232.   Chance%% = INT(RND * 100) 'create a random chance for monster to be made (0-99)
  233.   IF Chance%% < Mons_Chance THEN 'if value is benieth the monster cutoff then make one
  234.    Room% = INT(RND * Max_Mons_Room) 'which room should monster appear in?(0-[Max room to find monster-1])
  235.    IF Maze(Room%).Has_Mons < 3 THEN 'only add monster to room if its not full already
  236.     Mon%% = INT(RND * Max_Mons_Noun) + 1 'pick a monster to populate room with
  237.     Mons(Current_Monster~%).Noun = Mon%%
  238.     Mons(Current_Monster~%).Hp = INT(RND * Mon%% ^ 2) + 1
  239.     Mons(Current_Monster~%).Atk = INT(RND * Max_Mons_Weapon) + 1
  240.     Mons(Current_Monster~%).Verb = INT(RND * Max_Mons_Verb) + 1
  241.     Mons(Current_Monster~%).Adjt = INT(RND * Max_Mons_Adj) + 1
  242.     Maze(Room%).Has_Mons = Maze(Room%).Has_Mons + 1
  243.     Mons(Current_Monster~%).Roomid = Room%
  244.     Current_Monster~% = Current_Monster~% + 1
  245.    END IF
  246.   END IF
  247.  NEXT I~%
  248.  Monster_Count = Current_Monster~%
  249.  
  250. SUB MessageHandler (txt$)
  251.  'define message area
  252.  VIEW PRINT 1 TO 9
  253.  'display message
  254.  LOCATE 9, 1: PRINT txt$
  255.  'restore screen area
  256.  _DELAY .13
  257.  
  258. SUB Load_Monsters
  259.  RESTORE Nouns
  260.  READ Max_Mons_Noun
  261.  FOR i%% = 1 TO Max_Mons_Noun
  262.   READ M(i%%)
  263.  NEXT i%%
  264.  RESTORE Adjectives
  265.  READ Max_Mons_Adj
  266.  FOR i%% = 1 TO Max_Mons_Adj
  267.   READ A(i%%)
  268.  NEXT i%%
  269.  RESTORE Verbs
  270.  READ Max_Mons_Verb
  271.  FOR i%% = 1 TO Max_Mons_Verb
  272.   READ V(i%%)
  273.  NEXT i%%
  274.  RESTORE Weapon
  275.  READ Max_Mons_Weapon
  276.  FOR i%% = 1 TO Max_Mons_Weapon
  277.   READ W(i%%)
  278.  NEXT i%%
  279.  
  280. SUB Describe_Mons (id%)
  281.  FOR i~% = 0 TO Monster_Count
  282.   IF Mons(i~%).Roomid = id% THEN
  283.    M1$ = "In the room there is a " + RTRIM$(A(Mons(i~%).Adjt)) + " " + RTRIM$(M(Mons(i~%).Noun)) + "."
  284.    M2$ = "It can " + RTRIM$(V(Mons(i~%).Verb)) + " with " + RTRIM$(W(Mons(i~%).Atk)) + " " + STR$(i~%)
  285.    MessageHandler M1$
  286.    MessageHandler M2$
  287.    Found%% = Found%% + 1
  288.    IF Found%% = Maze(id%).Has_Mons THEN i~% = Monster_Count + 1 'if all the monsters have been found for this room exit routine
  289.   END IF
  290.  NEXT i~%
 

the seeming random number printed after the attack description is the ID value of the monster, its for debugging purposes. the number at the bottom of the screen is how many monsters were generated(-1) no interactions yet just amusing possibilities!

To actually move ahead with this idea I will need to fix my variable naming and make things much more clear, as it is I just threw this together rather hastily. not even sure of my spelling with the Nouns, Adjectives, verbs, or weapon names.

I think Steve's Rogue-like game would be very amusing using this type of principle for the monsters\creatures. A little extra logic would keep things like "it can gnaw with whip-like tail' from happening. though at times it can give a laugh. Which in a way was my point to begin with. but for a more serious minded use some logic would go far.
Granted after becoming radioactive I only have a half-life!

Offline bplus

  • Global Moderator
  • Forum Resident
  • Posts: 8053
  • b = b + ...
    • View Profile
Re: Little maze thing with silly creature generator
« Reply #1 on: September 22, 2019, 10:48:28 pm »
LOL, Curvaceous lizard throwing feces!

Offline johnno56

  • Forum Resident
  • Posts: 1270
  • Live long and prosper.
    • View Profile
Re: Little maze thing with silly creature generator
« Reply #2 on: September 23, 2019, 03:29:27 pm »
Can someone show me what the display is meant to look like? My display is weird. See attached. The default font, on the Linux version of QB64, is lucon.ttf. Originally, according to "display" via "Options", the font was located in "c:\windows\fonts\lucon.ttf". I have installed lucon and pointed "Display" to the fonts location but my IDE and Console display of the game characters are still messed up. Could some please instruct me on how to correct this problem?

Much appreciated.

Screenshot at 2019-09-24 05-20-35.png
* Screenshot at 2019-09-24 05-20-35.png (Filesize: 9.27 KB, Dimensions: 646x428, Views: 212)
Screenshot at 2019-09-24 05-21-14.png
* Screenshot at 2019-09-24 05-21-14.png (Filesize: 28.04 KB, Dimensions: 998x700, Views: 215)
Logic is the beginning of wisdom.

Offline bplus

  • Global Moderator
  • Forum Resident
  • Posts: 8053
  • b = b + ...
    • View Profile
Re: Little maze thing with silly creature generator
« Reply #3 on: September 23, 2019, 04:05:23 pm »
Hi Johnno,

Here is snap of my first screen in silly creature generator:
 
Silly creature generator.PNG


It looks like you need the old DOS ASCII set of characters that had lines and corners key codes for making boxes with single and double lines.

Offline johnno56

  • Forum Resident
  • Posts: 1270
  • Live long and prosper.
    • View Profile
Re: Little maze thing with silly creature generator
« Reply #4 on: September 23, 2019, 05:07:09 pm »
Well, that certainly looks a LOT neater... Do you know which font was used?
Logic is the beginning of wisdom.

Offline bplus

  • Global Moderator
  • Forum Resident
  • Posts: 8053
  • b = b + ...
    • View Profile
Re: Little maze thing with silly creature generator
« Reply #5 on: September 23, 2019, 05:10:22 pm »
https://www.qb64.org/wiki/ASCII

Might be Windows only ???

Offline johnno56

  • Forum Resident
  • Posts: 1270
  • Live long and prosper.
    • View Profile
Re: Little maze thing with silly creature generator
« Reply #6 on: September 24, 2019, 05:17:20 am »
... hmm... I was afraid you might say that... :(
Logic is the beginning of wisdom.

Offline johnno56

  • Forum Resident
  • Posts: 1270
  • Live long and prosper.
    • View Profile
Re: Little maze thing with silly creature generator
« Reply #7 on: September 24, 2019, 05:36:51 am »
Modified to display corners with "+". Top/bottom wall segment "-". left/right wall segments "|" and doorways with "*".

It isn't pretty but it works... lol
Screenshot at 2019-09-24 19-34-03.png
* Screenshot at 2019-09-24 19-34-03.png (Filesize: 8.28 KB, Dimensions: 646x428, Views: 201)
Logic is the beginning of wisdom.