arsd.gamehelpers

Note: much of the functionality of gamehelpers was moved to arsd.game on May 3, 2020. If you used that code, change import arsd.gamehelpers; to import arsd.game; and add game.d to your build (in addition to gamehelpers.d; the new game.d still imports this module) and you should be good to go.

This module now builds on only arsd.color to provide additional algorithm functions and data types that are common in games.

Members

Enums

Dir
enum Dir

Represents the four basic directions on a grid. You can conveniently use it like:

DirFlag
enum DirFlag

Directions as a maskable bit flag.

Functions

crossProduct
void crossProduct(float u1, float u2, float u3, float v1, float v2, float v3, float s1, float s2, float s3)

Calculates the cross product of <u1, u2, u3> and <v1, v2, v3>, putting the result in <s1, s2, s3>.

dirFlag
DirFlag dirFlag(Dir dir)
directions
Point[4] directions()

The four directions as a static array so you can assign to a local variable then shuffle, etc.

generateMaze
Grid!ubyte generateMaze(int mazeWidth, int mazeHeight)

Generates a maze.

pathfind
Point[] pathfind(Point start, Point goal, Size size, bool delegate(Point) isPassable, int delegate(Point, Point) d, int delegate(Point) h)

Implements the A* path finding algorithm on a grid.

randomDirection
Point randomDirection()

A random value off Dir.

randomDirectionCycle
auto randomDirectionCycle(int cycleCount)

Cycles through all the directions the given number of times. If you have one cycle, it goes through each direction once in a random order. With two cycles, it will move each direction twice, but in random order - can be W, W, N, E, S, S, N, E, for example; it will not do the cycles in order but upon completion will have gone through them all.

rotateAboutAxis
void rotateAboutAxis(float theta, float x, float y, float z, float u, float v, float w, float xp, float yp, float zp)

3D rotates (x, y, z) theta radians about the axis represented by unit-vector (u, v, w), putting the results in (s1, s2, s3).

rotateAboutPoint
void rotateAboutPoint(float theta, float originX, float originY, float rotatingX, float rotatingY, float xp, float yp)

2D rotates (rotatingX, rotatingY) theta radians about (originX, originY), putting the result in (xp, yp).

Structs

Grid
struct Grid(T)

Represents a 2d grid like an array. To encapsulate the whole [y*width + x] thing.

Meta

History

Massive change on May 3, 2020 to move the previous flagship class out and to a new module, arsd.game, to make this one lighter on dependencies, just containing helpers rather than a consolidated omnibus import.