Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- For Roguelike:
- Draw the character on top of the map.
- 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.
- FUNCTION is_passable(x AS INTEGER, y AS INTEGER) AS BOOLEAN
- DIM tile_type AS INTEGER
- tile_type = floor(rows, cols)
- IF tile_type = "floor"
- RETURN true
- ELSE
- RETURN false
- END IF
- END FUNCTION
- Going off the map entirely can be solved by walling the border or making maps that don't touch the border
- To move with collision detection:
- . . .
- SELECT key_code
- . . .
- CASE key_up
- IF is_passable() = 1
- BREAK
- ELSE
- player.y -= 1
- END IF
- . . .
- END SELECT
- Drawing the map:
- This can be done with types:
- ENUMERATION
- TILE_FLOOR
- TILE_WALL
- TILE_TREE
- TILE_WATER
- TILE_BUILDING
- TILE_NPC
- END ENUMERATION
- TYPE tile_type
- character AS CHAR
- color_code AS SHORT
- passable AS BOOLEAN
- END TYPE
- DIM AS tile_type() current_tile = {
- 'Character, is passable
- ".", true, 'floor
- "#", false, 'wall
- "¥", false, 'tree
- "~", true, 'water
- "%", false, 'building
- "&", false 'npc
- }
- FUNCTION is_passable(x, y) AS BOOLEAN
- tile_value AS INTEGER = floor(y, x)
- RETURN current_tile(tile_type).passable
- END FUNCTION
- Shorten up case statement:
- DIM delta_x, delta_y, end_loop AS INTEGER
- 'x is ahead of you, y is ahead of you
- end_loop= 0
- DO
- SELECT key_code
- CASE up
- delta_x = 0
- delta_y = -1
- CASE down
- delta_x = 0
- delta_y = 1
- CASE left
- delta_x = -1
- delta_y = 0
- CASE right
- delta_x = 1
- delta_y = 0
- CASE escape
- End
- CASE not any of above
- delta_x = 0
- delta_y = 0
- END SELECT
- LOOP UNTIL end_loop = 1
- IF is_passable(player.x+delta_x, player.y+delta_y) THEN
- player.x += delta_x
- player.y += delta_y
- END IF
- Interacting with items:
- Add more things to the enumeration I made before:
- TILE_OPENDOOR
- TILE_CLOSEDDOOR
- TILE_OPENCHEST
- TILE_CLOSEDCHEST
- TILE_DOWNSTAIRCASE
- TILE_UPSTAIRCASE
- and add things to the Select/Case statement:
- CASE c
- IF floor/map(player.x+delta_x, player.y+delta_y) is OPENDOOR THEN
- floor/map(player.x+delta_x, player.y+delta_y) is CLOSEDDOOR
- END IF
- . . .
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement