parin.joka.game
The game module provides game related types and functions.
Types 56
A generic color palette of RGBA colors.
A generic color palette of hexadecimal numbers.
A 2-color palette inspired by the Playdate. Link: https://kapendev.itch.io/will-of-the-hair-wisp
A 4-color palette inspired by the Game Boy. Link: https://lospec.com/palette-list/2-bit-matrix
An 8-color palette inspired by the NES. Link: https://lospec.com/palette-list/mf-8
A 16-color palette used by the PICO-8. Link: https://lospec.com/palette-list/pico-8
Flipping orientations.
A tile with a texture atlas id, size, and position.
float x() @safe nothrow @nogc @trusted refReturns a reference to the x component of the tile position.float y() @safe nothrow @nogc @trusted refReturns a reference to the y component of the tile position.Rect textureArea(Sz colCount) @safe nothrow @nogcReturns the rectangle of the tile in the texture atlas.bool hasIntersection(Rect otherArea) @safe nothrow @nogcReturns true if the tile area intersects with the given rectangle.bool hasIntersection(Tile otherTile) @safe nothrow @nogcReturns true if the tile area intersects with another tile.Rect intersection(Rect otherArea) @safe nothrow @nogcReturns the intersection rectangle of the tile area and the given rectangle.Rect intersection(Tile otherTile) @safe nothrow @nogcReturns the intersection rectangle of the tile area and another tile.Rect merger(Rect otherArea) @safe nothrow @nogcReturns the bounding rectangle of the tile area and the given rectangle.Rect merger(Tile otherTile) @safe nothrow @nogcReturns the bounding rectangle of the tile area and another tile.void followPosition(Vec2 target, float delta) @safe nothrow @nogcMoves the tile to follow the target position at the specified speed.void followPositionWithSlowdown(Vec2 target, float delta, float slowdown) @safe nothrow @nogcMoves the tile to follow the target position with gradual slowdown.A generic tile map. N is the maximum layer row or column size.
TileMapLayers layersSz rowCountSz colCountshort tileWidthshort tileHeightVec2 positionshort emptyTileId maxLayerRowColCountMaximum layer row or column size. maxLayerCapacityMaximum layer size. extraTileCountExtra tile padding added when computing visible tile ranges.short opIndex(Sz row, Sz col, Sz layerId = 0) @nogc @safe nothrow @trusted refReturns a reference to the tile id at the given row, column, and layer.short opIndex(IVec2 position, Sz layerId = 0) @nogc @safe nothrow refReturns a reference to the tile id at the given grid position and layer.void opIndexAssign(short rhs, Sz row, Sz col, Sz layerId = 0) @nogc @safe nothrow @trustedSets the tile id at the given row, column, and layer.void opIndexAssign(short rhs, IVec2 position, Sz layerId = 0) @nogc @safe nothrowSets the tile id at the given grid position and layer.void opIndexOpAssign(IStr op)(short rhs, Sz row, Sz col, Sz layerId = 0) @nogc @safe nothrow @trustedApplies a compound assignment operator to the tile id at the given row, column, and layer.void opIndexOpAssign(IStr op)(short rhs, IVec2 position, Sz layerId = 0) @nogc @safe nothrowApplies a compound assignment operator to the tile id at the given grid position and layer.float x() @nogc @safe nothrow @trusted refReturns a reference to the x component of the map position.float y() @nogc @safe nothrow @trusted refReturns a reference to the y component of the map position.Sz hardRowCount() @nogc @safe nothrowReturns the allocated row count of the first layer (the hard limit).Sz hardColCount() @nogc @safe nothrowReturns the allocated column count of the first layer (the hard limit).bool has(Sz row, Sz col) @nogc @safe nothrowReturns true if the given row and column are within the active map bounds.bool has(IVec2 position) @nogc @safe nothrowReturns true if the given grid position is within the active map bounds.bool hasSize() @nogc @safe nothrowReturns true if the map has a non-zero tile size and a non-zero active area.Vec2 worldPointAt(int gridX, int gridY) @nogc @safe nothrowReturns the world position of the top-left corner of the tile at the given grid coordinates.Vec2 worldPointAt(IVec2 gridPoint) @nogc @safe nothrowReturns the world position of the top-left corner of the tile at the given grid point.IVec2 gridPointAt(float worldX, float worldY) @nogc @safe nothrowReturns the grid coordinates of the tile that contains the given world position.IVec2 gridPointAt(Vec2 worldPoint) @nogc @safe nothrowReturns the grid coordinates of the tile that contains the given world point.Fault parseCsv(IStr csv, short newTileWidth, short newTileHeight, Sz layerId = 0, bool isMinZero = false, IStr file = __FILE__, Sz line = __LINE__) @safe nothrowParses a CSV string into the specified layer, using the given tile size. Returns a fault if the CSV is empty, contains invalid values, or exceeds the hard layer bounds. If `isMinZero` is true, tile...Fault parseCsv(IStr csv, Sz layerId = 0, bool isMinZero = false, IStr file = __FILE__, Sz line = __LINE__) @safe nothrowParses a CSV string into the specified layer using the current tile size. Returns a fault if parsing fails.Fault parseTmx(IStr tmx, IStr file = __FILE__, Sz line = __LINE__) @trusted @safe nothrowParses a TMX (Tiled XML) map file, extracting tile size and all CSV data layers. Does not support infinite maps. Returns a fault if parsing fails.void resizeHard(Sz newHardRowCount, Sz newHardColCount, IStr file = __FILE__, Sz line = __LINE__) @safe nothrowAllocates or resizes all layers to the given hard row and column counts. Clamps to `maxLayerRowColCount`. Creates a default layer if the map is empty.void free(IStr file = __FILE__, Sz line = __LINE__) @safe nothrowFrees all layers and associated memory.void resize(Sz newRowCount, Sz newColCount) @safe nothrow @nogcSets the active row and column count without reallocating. Asserts if either value exceeds the hard limit.void resizeTileSize(short newTileWidth, short newTileHeight) @safe nothrow @nogcSets the tile size in pixels.void followPosition(Vec2 target, float delta) @safe nothrow @nogcMoves the map to follow the target position at the specified speed.void followPositionWithSlowdown(Vec2 target, float delta, float slowdown) @safe nothrow @nogcMoves the map to follow the target position with gradual slowdown.auto gridPoints(Vec2 topLeftViewPoint, Vec2 bottomRightViewPoint) @safe nothrow @nogcReturns a lazy range of grid points visible within the given view corners. Includes one extra tile of padding on the far edges via `extraTileCount`.auto gridPoints(Rect viewArea) @safe nothrow @nogcReturns a lazy range of grid points visible within the given view rectangle.A grid path finder using the A* algorithm. Movement is in 4 directions and every step has the same cost. The working data is stored inside the struct, so no memory is allocated. It is big, so prefer global or heap storage.
ushort[maxCapacity] _stepsushort[maxCapacity] _parentsushort[maxCapacity] _heapushort[maxCapacity] _heapSlotsSz _heapLengthSz _colCountSz _targetRowSz _targetCol maxRowColCountMaximum grid row or column size of a square grid. maxCapacityMaximum grid size. Any grid with this many cells or fewer works. noIndexThe value used for cells without an index.IVec2[] find(const(short)[] data, Sz colCount, Sz startRow, Sz startCol, Sz targetRow, Sz targetCol, IVec2[] buffer, short empty = - 1) @safe nothrow @nogcFinds the shortest path from the start cell to the target cell. The `data` slice is a row-major grid with `colCount` columns. Cells equal to `empty` can be entered. The start cell does not need to ...IVec2[] find(const(short)[] data, Sz colCount, IVec2 start, IVec2 target, IVec2[] buffer, short empty = - 1) @safe nothrow @nogcFinds the shortest path from the start cell to the target cell. Positions use x as the column and y as the row.IVec2[] find(Sz M)(ref GTileMap!M map, Sz startRow, Sz startCol, Sz targetRow, Sz targetCol, IVec2[] buffer, Sz layerId = 0) @safe nothrow @nogcFinds the shortest path from the start cell to the target cell on the active area of a tile map layer. Tiles equal to the `emptyTileId` of the map can be entered.IVec2[] find(Sz M)(ref GTileMap!M map, IVec2 start, IVec2 target, IVec2[] buffer, Sz layerId = 0) @safe nothrow @nogcFinds the shortest path from the start cell to the target cell on the active area of a tile map layer. Positions use x as the column and y as the row.A single sprite animation, defined by its position in an atlas and playback settings.
ubyte frameRowubyte frameCountubyte frameSpeedbool canRepeatA sprite animation group that picks between 2 animations based on a direction angle.
ubyte[2] frameRowsubyte frameCountubyte frameSpeedbool canRepeat angleStepThe angle step in degrees used to snap the input angle.SpriteAnimation pick(float angle) @safe nothrow @nogcPicks an animation based on the given angle in degrees.A sprite animation group that picks between 4 animations based on a direction angle.
ubyte[4] frameRowsubyte frameCountubyte frameSpeedbool canRepeat angleStepThe angle step in degrees used to snap the input angle.SpriteAnimation pick(float angle) @safe nothrow @nogcPicks an animation based on the given angle in degrees.A sprite animation group that picks between 8 animations based on a direction angle.
ubyte[8] frameRowsubyte frameCountubyte frameSpeedbool canRepeat angleStepThe angle step in degrees used to snap the input angle.SpriteAnimation pick(float angle) @safe nothrow @nogcPicks an animation based on the given angle in degrees.A sprite animation group that picks between 16 animations based on a direction angle.
ubyte[16] frameRowsubyte frameCountubyte frameSpeedbool canRepeat angleStepThe angle step in degrees used to snap the input angle.SpriteAnimation pick(float angle) @safe nothrow @nogcPicks an animation based on the given angle in degrees.A sprite with support for animation, positioning, and movement.
short widthshort heightushort atlasLeftushort atlasTopfloat frameProgressbool isPausedSpriteAnimation animationVec2 positionHook hookFlip flipfloat x() @safe nothrow @nogc @trusted refReturns a reference to the x component of the sprite position.float y() @safe nothrow @nogc @trusted refReturns a reference to the y component of the sprite position.bool hasFirstFrameProgress() @safe nothrow @nogcReturns true if the sprite is on the first animation frame progress.bool hasLastFrameProgress() @safe nothrow @nogcReturns true if the sprite is on the last animation frame progress.void play(SpriteAnimation newAnimation, bool canKeepProgress = false) @safe nothrow @nogcStarts playing a new animation, optionally preserving current frame progress.void followPosition(Vec2 target, float delta) @safe nothrow @nogcMoves the sprite to follow the target position at the specified speed.void followPositionWithSlowdown(Vec2 target, float delta, float slowdown) @safe nothrow @nogcMoves the sprite to follow the target position with gradual slowdown.this(short width, short height, ushort atlasLeft, ushort atlasTop, Vec2 position = Vec2(), Hook hook = Hook.topLeft)Initializes the sprite with the specified size, atlas position, and optional world position.How to draw a sprite stack layer.
A sprite stack.
ubyte widthubyte heightushort atlasLeftushort atlasTopSpriteStackDrawMode drawModeubyte layerCountVec2 positionfloat rotationA helper for changing the color of sprite stack layers.
Rgba makeColor(float lightingProgress) @safe nothrow @nogcReturns a new color. Value `lightingProgress` should be between 0.0 and 1.0 (inclusive).Rgba makeColor(uint layer, uint layerCount) @safe nothrow @nogcReturns a new color. The lighting progress is `layer / layerCount` for this function.Rgba makeColorIfIsActive(float lightingProgress) @safe nothrow @nogcReturns a new color. Value `lightingProgress` should be between 0.0 and 1.0 (inclusive).Rgba makeColorIfIsActive(uint layer, uint layerCount) @safe nothrow @nogcReturns a new color. The lighting progress is `layer / layerCount` for this function.A generic timer with pause/resume and repeat support. The elapsedTickTimeFunc alias must be a function that returns a float or double value. That value should be the elapsed time at the start of the current tick.
float durationfloat pauseTimefloat startTimefloat stopTimeElapsedTimeBufferbool canRepeatvoid start(float newDuration, bool newCanRepeat) @safe nothrow @nogcStarts the timer with new duration and repeat behavior.void start(float newDuration = - 1.0f) @safe nothrow @nogcStarts the timer with an optional new duration.float time() @safe nothrow @nogcReturns the current time of the timer and handles stop/repeat logic.float timeLeft() @safe nothrow @nogcReturns the remaining time of the timer and handles stop/repeat logic.void setTime(float newTime) @safe nothrow @nogcSets the current time of the timer. If the given value is non-zero, the timer becomes active.float progressLeftOrZero() @safe nothrow @nogcReturns the remaining progress (between 0.0 to 1.0), or zero if inactive.void setProgress(float value) @safe nothrow @nogcSets the progress to a specific value (between 0.0 to 1.0).void setProgressLeft(float value) @safe nothrow @nogcSets the remaining progress to a specific value (between 0.0 to 1.0).this(float duration, bool canRepeat = false)Initializes the timer with the specified duration and repeat behavior.The kind of a story line.
An operation in the story expression language.
A fixed-size word in the story expression language.
A number in the story expression language.
The underlying data of a story value.
The stack of the story expression language.
A value in the story expression language, either a word or a number.
StoryValueData dataA named variable in the story expression language.
A start and end index pair used to identify ranges in the story.
uint auint bA story script with its associated state for parsing and execution.
LStr scriptList!StoryStartEndPair pairsList!StoryVariable labelsList!StoryVariable variablesStoryNumber lineIndexStoryNumber nextLabelIndexStoryNumber previousMenuResultStoryNumber faultPrepareIndexStoryOp faultOpSz faultTokenPositionbool debugModebool linearModeEchonFunc echonFuncFixedList!(StoryValue, defaultStoryFixedListCapacity) stackFault prepare(IStr file = __FILE__, Sz line = __LINE__) @trusted @safe nothrowSplits the script into lines and finds the labels.Fault parse(IStr text, IStr file = __FILE__, Sz line = __LINE__) @safe nothrowReplaces the script with the given text and prepares it.Fault execute(IStr expression, IStr file = __FILE__, Sz line = __LINE__) @trusted @safe nothrowExecutes a story expression.Fault update(IStr file = __FILE__, Sz line = __LINE__) @safe nothrowGoes to the next text, menu, procedure or pause line and executes the expression lines on the way. Returns an overflow fault if it goes through too many lines, like when a script loops forever with...Fault select(Sz i, IStr file = __FILE__, Sz line = __LINE__) @safe nothrowSelects a menu option, starting from 0, and updates the story.void reserve(Sz capacity, IStr file = __FILE__, Sz line = __LINE__) @safe nothrowReserves memory for the given number of items in each story list.void free(IStr file = __FILE__, Sz line = __LINE__) @safe nothrowFrees the story data and resets the story.bool hasKind(StoryLineKind kind) @safe nothrow @nogcReturns true if the current line is of the given kind.bool hasPause() @safe nothrow @nogcReturns true if the current line is a pause line or the story is at the end.IStr[] procedure() @trusted @safe nothrow @nogcReturns the words of the current procedure line. The result uses `procedureCallBuffer`, so the next call overwrites it.IStr[] menu() @trusted @safe nothrow @nogcReturns the options of the current menu line. The result uses `menuCallBuffer`, so the next call overwrites it.StoryNumber findVariable(StoryWord name) @safe nothrow @nogcReturns the index of the variable with the given name, or -1.StoryNumber findLabel(StoryWord name) @safe nothrow @nogcReturns the index of the label with the given name, or -1.void setNextLabelIndex(StoryNumber value) @safe nothrow @nogcSets the index of the next label. It wraps around after the last label.void setLineIndex(StoryNumber value) @safe nothrow @nogcSets the current line. It wraps around after the end.void resetLineIndex() @safe nothrow @nogcMoves the story to the end. The next update starts from the first line.void jumpLineIndex(StoryNumber labelIndex) @safe nothrow @nogcMoves the story to the label with the given index.T xT yA generic box ID.
Generic box flags.
An box actor ID.
A box wall ID.
A generic box ID pair.
A box actor ID pair.
A wall actor ID pair.
The side of a box.
The data of a box.
A box world.
Grid!BoxUnionIdGroup gridBoxIdBuffer collisionIdBufferBoxIdBuffer squishedIdBufferint gridTileWidthint gridTileHeightBoxWallId pushWall(Box box, BoxSide side = BoxSide.none, IStr file = __FILE__, Sz line = __LINE__) @safe nothrowBoxActorId pushActor(Box box, BoxSide side = BoxSide.none, IStr file = __FILE__, Sz line = __LINE__) @safe nothrowFault parseWallsCsv(IStr csv, int tileWidth, int tileHeight, IStr file = __FILE__, Sz line = __LINE__) @safe nothrowvoid enableGrid(Sz rowCount, Sz colCount, int tileWidth, int tileHeight, IStr file = __FILE__, Sz line = __LINE__) @safe nothrowEnables the spatial grid. A box is stored in the grid cell of its top-left corner and collision checks look at the 3x3 cells around it. The tile size should be at least as big as the biggest box, o...IVec2 gridPoint(Box box) @safe nothrow @nogcReturns the grid point of the box, or `IVec2(-1)` if the grid is disabled.BoxWallId moveActorXToWithSlowdown(BoxActorId id, float to, float amount, float slowdown) @safe nothrow @nogcBoxWallId moveActorYToWithSlowdown(BoxActorId id, float to, float amount, float slowdown) @safe nothrow @nogcBoxWallIdPair moveActorToWithSlowdown(BoxActorId id, Vec2 to, Vec2 amount, float slowdown) @safe nothrow @nogcBoxActorId[] moveWallXToWithSlowdown(BoxWallId id, float to, float amount, float slowdown) @safe nothrow @nogcBoxActorId[] moveWallYToWithSlowdown(BoxWallId id, float to, float amount, float slowdown) @safe nothrow @nogcBoxActorId[] moveWallToWithSlowdown(BoxWallId id, Vec2 to, Vec2 amount, float slowdown) @safe nothrow @nogcThe parts of a 9-slice.
Information about the viewport, including its drawing region and size constraints.
Functions 7
Variables 29
HexPalette!2 wisp2A 2-color palette inspired by the Playdate. Link: https://kapendev.itch.io/will-of-the-hair-wisp
HexPalette!4 gb4A 4-color palette inspired by the Game Boy. Link: https://lospec.com/palette-list/2-bit-matrix
HexPalette!8 nes8An 8-color palette inspired by the NES. Link: https://lospec.com/palette-list/mf-8
HexPalette!16 pico8A 16-color palette used by the PICO-8. Link: https://lospec.com/palette-list/pico-8
defaultStoryFixedListCapacity = 16blank = Rgba()#00000000
black = Rgba(0)#000000FF
white = Rgba(255)#FFFFFFFF
red = Rgba(255, 0, 0)#FF0000FF
green = Rgba(0, 255, 0)#00FF00FF
blue = Rgba(0, 0, 255)#0000FFFF
yellow = Rgba(255, 255, 0)#FFFF00FF
magenta = Rgba(255, 0, 255)#FF00FFFF
cyan = Rgba(0, 255, 255)#00FFFFFF
pink = Rgba(255, 192, 204)#FFC0CCFF
orange = Rgba(255, 165, 0)#FFA500FF
beige = Rgba(240, 235, 210)#F0EBD2FF
brown = Rgba(165, 72, 42)#A5482AFF
maroon = Rgba(128, 0, 0)#800000FF
gray1 = Rgba(32, 32, 32)#202020FF
gray2 = Rgba(96, 96, 96)#606060FF
gray3 = Rgba(159, 159, 159)#9F9F9FFF
gray4 = Rgba(223, 223, 223)#DFDFDFFF
gray = gray2#606060FF
boxNoneId = 0boxUnionTypeBit = (cast(BoxUnionId) 1) << (BoxUnionId.sizeof * 8 - 1)boxMaxCount = boxUnionTypeBit - 1boxErrorMessage = "Box is invalid or was never assigned."boxFixedCapacity = 256