User Tools

Site Tools


pathfinding-for-orx-scroll

Differences

This shows you the differences between two versions of the page.

Link to this comparison view

pathfinding-for-orx-scroll [2022/09/01 12:43] (current)
sausage created
Line 1: Line 1:
 +====== Pathfinding for games in Orx ======
  
 +If you are interested in pathfinding for games written in Orx (intended mainly for orx/Scroll-based games), I have been developing some routines for the game I'm working on. 
 +
 +You can get a copy here:
 +https://gitlab.com/sausagejohnson/room-paths-scroll
 +
 +The path-finding is loosely based on [[https://www.youtube.com/watch?v=-L-WgKMFuhE|A*]], though only deals with cell distance. I haven't bothered with F or G-cost. It's good for small and simple sized rooms and paths for robot or character navigation. 
 +
 +There's some demo rooms included and grid tile objects that render colours to demonstrate the pathing.
 +
 +{{ :orx:path-grid.png?nolink |}}
 +
 +The source code is well commented to help you understand what you need to do. It should be fairly trivial to apply the ''Room'' class to an orx/Scroll Scroll object so that your object or character will have a path it can take through a room.
 +
 +As this is not a full blown tutorial, I'll just point out the basic usage of the code.
 +
 +===== Room map configuration =====
 +
 +Here is an example of one of the defined rooms located in config:
 +
 +<code ini>
 +[Room]
 +Cells = O # O # X # X # X # X # X # O #
 + O # O # O # O # O # O # O # O #
 + X # X # X # O # X # X # O # O #
 + X # O # O # O # X # X # O # O #
 + X # O # O # O # O # O # O # O #
 + O # O # X # X # O # O # O # O #
 + O # O # X # X # O # X # X # O #
 + O # O # X # X # O # X # X # O
 +</code>
 +
 +''O'' is used to represent an empty cell, a place where a character can move to.
 +''X'' is used to represent a wall, or some kind of barrier block.
 +
 +Start and end positions are not defined in the map, because these can be set at any time.
 +
 +===== Basic usage =====
 +
 +<code cpp>
 + Room *room = new Room(cellsAcross, "Room3");
 +</code>
 +
 +This creates a new room, how many expected cells in both the horizontal and vertical directions, the the name of the room map to load from the config file.
 +
 +<code cpp>
 + room->SetStartCell(1, 0);
 + room->SetEndCell(7, 7);
 +</code>
 +
 +Set the start and end cells. This represents the positions where a character will start walking from and where it will end up.
 +
 +<code cpp>
 + room->PerformPathFind();
 +</code>
 +
 +This builds the actual path ready to use.
 +
 +<code cpp>
 + BuildTiles();
 +</code>
 +
 +This is for debugging and creates a grid of grey tiles to represent the room and the path. This should only be run once.
 +
 +<code cpp>
 + ColourTiles();
 +</code>
 +
 +This is for debugging and uses both the cell and path data to represent the room and the path in colour.
 +
 +<code cpp>
 + DumpPathData();
 + DumpCellData();
 +</code>
 +
 +These two dump functions log out path or cell data though only useful if you want to make changes to the code.
 +
 +Any additional uses of ''SetStartCell'' or ''SetEndCell'' will clear the map and reset all cells in the grid.
 +
 +===== Controls =====
 +
 +There's a few keys you can use for testing. Key ''1'' and ''2'' choose other rooms to reload in.
 +
 +The ''space'' key is used to cycle through every empty space and moving the start cell to that position. This way you can easily test every single position on the map.
 +
 +===== Have fun =====
 +
 +That's it have fun, and expand this code to suit your game. Eventually this might form a library for importing into an orx/Scroll game.
pathfinding-for-orx-scroll.txt ยท Last modified: 2022/09/01 12:43 by sausage