Advertisement
GoToBread

Ideas for Roguelike

Jul 29th, 2013
206
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. For Roguelike:
  2.  
  3. Draw the character on top of the map.
  4.  
  5. Collision detection: make TYPES for the tiles. If the type is a wall or water, keep the player at its current tile position, else do the move. This can be done with a function call. If is_passable() == true, then move, else stay.
  6.  
  7. FUNCTION is_passable(x AS INTEGER, y AS INTEGER) AS BOOLEAN
  8.       DIM tile_type AS INTEGER
  9.       tile_type = floor(rows, cols)
  10.       IF tile_type = "floor"
  11.             RETURN true
  12.       ELSE
  13.             RETURN false
  14.       END IF
  15. END FUNCTION
  16.  
  17. Going off the map entirely can be solved by walling the border or making maps that don't touch the border
  18.  
  19. To move with collision detection:
  20. . . .
  21. SELECT key_code
  22. . . .
  23.     CASE key_up
  24.         IF is_passable() = 1
  25.             BREAK
  26.         ELSE
  27.             player.y -= 1
  28.         END IF
  29. . . .
  30. END SELECT
  31.  
  32. Drawing the map:
  33.  
  34. This can be done with types:
  35.  
  36. ENUMERATION
  37.     TILE_FLOOR
  38.     TILE_WALL
  39.     TILE_TREE
  40.     TILE_WATER
  41.     TILE_BUILDING
  42.     TILE_NPC
  43. END ENUMERATION
  44.  
  45. TYPE tile_type
  46.     character AS CHAR
  47.     color_code AS SHORT
  48.     passable AS BOOLEAN
  49. END TYPE
  50.  
  51.  DIM AS tile_type() current_tile = {
  52. 'Character, is passable
  53. ".", true, 'floor
  54. "#", false, 'wall
  55. "¥", false, 'tree
  56. "~", true, 'water
  57. "%", false, 'building
  58. "&", false 'npc
  59. }
  60.  
  61. FUNCTION is_passable(x, y) AS BOOLEAN
  62.     tile_value AS INTEGER = floor(y, x)
  63.     RETURN current_tile(tile_type).passable
  64. END FUNCTION
  65.  
  66. Shorten up case statement:
  67.  
  68. DIM delta_x, delta_y, end_loop AS INTEGER
  69. 'x is ahead of you, y is ahead of you
  70. end_loop= 0
  71. DO
  72. SELECT key_code
  73. CASE up
  74.     delta_x = 0
  75.     delta_y = -1
  76. CASE down
  77.     delta_x = 0
  78.     delta_y = 1
  79. CASE left
  80.     delta_x = -1
  81.     delta_y = 0
  82. CASE right
  83.     delta_x = 1
  84.     delta_y = 0
  85. CASE escape
  86.     End
  87. CASE not any of above
  88.     delta_x = 0
  89.     delta_y = 0
  90. END SELECT
  91. LOOP UNTIL end_loop = 1
  92. IF is_passable(player.x+delta_x, player.y+delta_y) THEN
  93.     player.x += delta_x
  94.     player.y += delta_y
  95. END IF
  96.  
  97. Interacting with items:
  98.  
  99. Add more things to the enumeration I made before:
  100.  
  101. TILE_OPENDOOR
  102. TILE_CLOSEDDOOR
  103. TILE_OPENCHEST
  104. TILE_CLOSEDCHEST
  105. TILE_DOWNSTAIRCASE
  106. TILE_UPSTAIRCASE
  107.  
  108. and add things to the Select/Case statement:
  109.  
  110. CASE c
  111. IF floor/map(player.x+delta_x, player.y+delta_y) is OPENDOOR THEN
  112.     floor/map(player.x+delta_x, player.y+delta_y) is CLOSEDDOOR
  113. END IF
  114. . . .
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement