ArcadeMaker has a feature called "paths" - you can draw a path in the IDE, and make an object following it using startPath(...) or draw it using drawPath(...).
But sometimes you want to get (in the code) the coordinates of a path, to check for intersection with it, for example. Currently, there's no function for getting the coordinates of a path.
And in other times you would want to dynamically construct a path in the code, and the engine lacks the right function for this too.
To implement a function that gets a path ID and returns an array of all of its coordinates, you should add to IGame.Funcs.cs a method like this:
/// <summary>
/// Gets an array of all the coordinates of the given path.
/// </summary>
/// <param name="expinst">The calling runtime instance (unused).</param>
/// <param name="args">(pathID).</param>
[EngineFunc(1)]
[Param("pathID", ParamType.Number, "The ID of the path to follow. Use 'Paths' enum for that, e.g. Paths.PthRoad.")]
Exp.Instance GetPathPoints(Exp.Instance? expinst, IValue?[] args)
{
// get the path
int id = (int)args[0].ThrowIfNull().Number;
Resources.Path path = Paths.GetById(id);
ExpSrc.General.PathPoint[] points = ...
return new Exp.Instance(ClassDefSpan.ExpArrayDef, points);
}
Resources.Path has properties for StartPositionX, StartPositionY and Steps, where each step has properties for Width (the x diff from previous coordinate) and Height (the y diff from previous coordinate), and Speed. These properties can be used to construct an array of PathPoints (a class that contains fields for x, y, and speed, and is a valid Exp value).
To implement a function that gets an array of coordinates, creates a new path from them and returns its ID, you should add to IGame.Funcs.cs a method like this:
/// <summary>
/// Creates a path from the given PathPoint array, and returns its ID
/// </summary>
/// <param name="expinst">The calling runtime instance (unused).</param>
/// <param name="args">(points).</param>
[EngineFunc(1)]
[Param("points", ParamType.Array + " of " + nameof(ExpSrc.General.PathPoint), "An array containing the points to create a paht from.")]
IValue CreatePath(Exp.Instance? expinst, IValue?[] args)
{
IValue[] arr = args[0].ThrowIfNull().Inst.ArrayValues ?? throw new EngineException("An array was expected");
List<ExpSrc.General.PathPoint> points = [];
foreach (var val in arr)
{
if (val is not ExpSrc.General.PathPoint pnt)
throw new EngineException("Invalid argument - an array of PathPoint instances was expected.");
else
points.Add(pnt);
}
Resources.Path path = ...;
Paths.Add(path);
return path.ID.ToExp();
}
Feel free to ask any question :)
ArcadeMaker has a feature called "paths" - you can draw a path in the IDE, and make an object following it using
startPath(...)or draw it usingdrawPath(...).But sometimes you want to get (in the code) the coordinates of a path, to check for intersection with it, for example. Currently, there's no function for getting the coordinates of a path.
And in other times you would want to dynamically construct a path in the code, and the engine lacks the right function for this too.
To implement a function that gets a path ID and returns an array of all of its coordinates, you should add to IGame.Funcs.cs a method like this:
Resources.Pathhas properties forStartPositionX,StartPositionYandSteps, where each step has properties forWidth(the x diff from previous coordinate) andHeight(the y diff from previous coordinate), andSpeed. These properties can be used to construct an array ofPathPoints (a class that contains fields for x, y, and speed, and is a valid Exp value).To implement a function that gets an array of coordinates, creates a new path from them and returns its ID, you should add to IGame.Funcs.cs a method like this:
Feel free to ask any question :)