Available on:

TRAVEL

The TRAVEL command allows you to move an entity (for example, a character in a video game, a robot in a simulated environment, or a cursor on a map) from a starting point to a destination point, following a previous created PATH. The coordinates of the starting point and of the destination point are given using the CREATE PATH command. So, this command will update a pair of variables (x,y) with the next point. Optionally, you can give a multiplier factor (times), in order to move more than one pixel at a time. By adding the CLAMP keyword, the increment of the coordinate variables will be limited to the coordinates of the destination point. The function version can be used to check if destination coordinate is reached (if CLAMP has been requested).

The command uses the Bresenham algorithm to calculate the sequence of intermediate coordinates that define the most efficient path between the starting point and the destination point. The Bresenham algorithm is particularly suitable for drawing straight lines on discrete grids (such as pixel grids), ensuring an optimized path in terms of steps. In other words, the entity is moved along the calculated path, updating its coordinates at each step. The speed of the movement can be controlled by the times parameter. If the speed is not specified, a value of 1 is implicit considered.

The Bresenham algorithm is efficient and ensures an optimized path, but produces straight paths. In scenarios where more complex paths are required (e.g. with curves or obstacles), more advanced pathfinding algorithms may be needed.

SYNTAX

 TRAVEL path TO x, y [BY times] [CLAMP]
 = TRAVEL ( path TO x, y [BY times] [CLAMP] )


Legend
  • id : identifier
  • type : datatype
  • v : value
  • "..." : string
  • [...] : optional

EXAMPLE

 ebltPath = CREATE PATH(posX, posY TO endX, endY)
 DO
     EXIT IF TRAVEL( ebltPath TO ebltX, ebltY CLAMP )
     PUT IMAGE enmBlt FRAME 0 AT ebltX, ebltY
 LOOP


ABBREVIATION: Trv

Join BASIC 10Liner Contest with ugBASIC!

An interesting competition is held at the beginning of each year: the BASIC 10Liner Contest. It is possible to use ugBASIC to participate in the next "BASIC10Liner" competition, in the following categories:

  • PUR-120 - A game in 10 lines of max 120 characters (w/abbrev.)
  • EXTREME-256 - A game in 10 lines of max 256 characters (w/abbrev.)
  • SCHAU - Any program in 10 lines of max 256 characters (w/abbrev.)
In order to reduce space you can use this abbreviation for this instruction:

TRAVEL ↔ Trv

Any problem?

If you have found a problem with this keyword, if you think there is a bug or, more simply, you would like it to be improved, open an issue for this example on GitHub.
Thank you!

open an issue BACK TO KEYWORDS