User Tools

Site Tools


pathfinding-for-orx-scroll

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 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.

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:

[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

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

	Room *room = new Room(cellsAcross, "Room3");

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.

	room->SetStartCell(1, 0);
	room->SetEndCell(7, 7);

Set the start and end cells. This represents the positions where a character will start walking from and where it will end up.

	room->PerformPathFind();

This builds the actual path ready to use.

	BuildTiles();

This is for debugging and creates a grid of grey tiles to represent the room and the path. This should only be run once.

	ColourTiles();

This is for debugging and uses both the cell and path data to represent the room and the path in colour.

	DumpPathData();
	DumpCellData();

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