parin.joka.game

The game module provides game related types and functions.

Types 49

aliasPalette(Sz N) = StaticArray!(Rgba, N)

A generic color palette of RGBA colors.

aliasHexPalette(Sz N) = uint[N]

A generic color palette of hexadecimal numbers.

enumWisp2 : Rgba

A 2-color palette inspired by the Playdate. Link: https://kapendev.itch.io/will-of-the-hair-wisp

black = toRgb(wisp2[0])#322F29
white = toRgb(wisp2[1])#DAD6D0
enumGb4 : Rgba

A 4-color palette inspired by the Game Boy. Link: https://lospec.com/palette-list/2-bit-matrix

black = toRgb(gb4[0])#343434
darkGray = toRgb(gb4[1])#5B8C7C
lightGray = toRgb(gb4[2])#ADD9BC
white = toRgb(gb4[3])#F2FFF2
enumNes8 : Rgba

An 8-color palette inspired by the NES. Link: https://lospec.com/palette-list/mf-8

black = toRgb(nes8[0])#292320
brown = toRgb(nes8[1])#A7763E
purple = toRgb(nes8[2])#7F339A
red = toRgb(nes8[3])#E04113
green = toRgb(nes8[4])#32A75C
blue = toRgb(nes8[5])#1AC1FE
yellow = toRgb(nes8[6])#FDD156
white = toRgb(nes8[7])#FCF8EA
enumPico8 : Rgba

A 16-color palette used by the PICO-8. Link: https://lospec.com/palette-list/pico-8

black = toRgb(pico8[0])#000000
navy = toRgb(pico8[1])#1D2B53
maroon = toRgb(pico8[2])#7E2553
darkGreen = toRgb(pico8[3])#008751
brown = toRgb(pico8[4])#AB5236
darkGray = toRgb(pico8[5])#5F574F
lightGray = toRgb(pico8[6])#C2C3C7
white = toRgb(pico8[7])#FFF1E8
red = toRgb(pico8[8])#FF004D
orange = toRgb(pico8[9])#FFA300
yellow = toRgb(pico8[10])#FFEC27
lightGreen = toRgb(pico8[11])#00E436
blue = toRgb(pico8[12])#29ADFF
purple = toRgb(pico8[13])#83769C
pink = toRgb(pico8[14])#FF77A8
peach = toRgb(pico8[15])#FFCCAA
enumFlip : ubyte

Flipping orientations.

noneNo flipping.
xFlipped along the X-axis.
yFlipped along the Y-axis.
xyFlipped along both X and Y axes.
structTile

A tile with a texture atlas id, size, and position.

Fields
short width
short height
short id
Flip flip
byte idOffset
Vec2 position
Methods
float x() @trusted refReturns a reference to the x component of the tile position.
float y() @trusted refReturns a reference to the y component of the tile position.
Sz row(Sz colCount)Returns the row of the tile in the atlas.
Sz col(Sz colCount)Returns the column of the tile in the atlas.
Vec2 size()Returns the size of the tile as a 2D vector.
Rect area()Returns the bounding rectangle of the tile.
Rect textureArea(Sz colCount)Returns the rectangle of the tile in the texture atlas.
bool isEmpty()Returns true if the tile has no valid id.
bool hasId()Returns true if the tile has a valid id.
bool hasSize()Returns true if the tile has a non-zero size.
bool hasIdAndSize()Returns true if the tile has a valid id and a non-zero size.
bool hasIntersection(Rect otherArea)Returns true if the tile area intersects with the given rectangle.
bool hasIntersection(Tile otherTile)Returns true if the tile area intersects with another tile.
Rect intersection(Rect otherArea)Returns the intersection rectangle of the tile area and the given rectangle.
Rect intersection(Tile otherTile)Returns the intersection rectangle of the tile area and another tile.
Rect merger(Rect otherArea)Returns the bounding rectangle of the tile area and the given rectangle.
Rect merger(Tile otherTile)Returns the bounding rectangle of the tile area and another tile.
void followPosition(Vec2 target, float delta)Moves the tile to follow the target position at the specified speed.
void followPositionWithSlowdown(Vec2 target, float delta, float slowdown)Moves the tile to follow the target position with gradual slowdown.
Constructors
this(short width, short height, short id, Vec2 position = Vec2())Constructs a tile with the given size, id, and position.
this(short width, short height, short id, float x, float y)Constructs a tile with the given size, id, and position components.
structGTileMap(Sz N)

A generic tile map. N is the maximum layer row or column size.

Fields
maxLayerRowColCountMaximum layer row or column size.
maxLayerCapacityMaximum layer size.
extraTileCountExtra tile padding added when computing visible tile ranges.
TileMapLayers layers
Sz rowCount
Sz colCount
short tileWidth
short tileHeight
Vec2 position
Methods
short opIndex(Sz row, Sz col, Sz layerId = 0) @trusted refReturns a reference to the tile id at the given row, column, and layer.
short opIndex(IVec2 position, Sz layerId = 0) 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) @trustedSets the tile id at the given row, column, and layer.
void opIndexAssign(short rhs, IVec2 position, Sz layerId = 0)Sets the tile id at the given grid position and layer.
void opIndexOpAssign(IStr op)(T rhs, Sz row, Sz col, Sz layerId = 0) @trustedApplies a compound assignment operator to the tile id at the given row, column, and layer.
void opIndexOpAssign(IStr op)(T rhs, IVec2 position, Sz layerId = 0)Applies a compound assignment operator to the tile id at the given grid position and layer.
float x() @trusted refReturns a reference to the x component of the map position.
float y() @trusted refReturns a reference to the y component of the map position.
int width()Returns the total pixel width of the active map area.
int height()Returns the total pixel height of the active map area.
Vec2 size()Returns the total pixel size of the active map area as a 2D vector.
Vec2 tileSize()Returns the size of a single tile as a 2D vector.
Sz hardRowCount()Returns the allocated row count of the first layer (the hard limit).
Sz hardColCount()Returns the allocated column count of the first layer (the hard limit).
bool isEmpty()Returns true if the map has no layers.
bool has(Sz row, Sz col)Returns true if the given row and column are within the active map bounds.
bool has(IVec2 position)Returns true if the given grid position is within the active map bounds.
bool hasTileSize()Returns true if the map has a non-zero tile size.
bool hasSize()Returns true if the map has a non-zero tile size and a non-zero active area.
Vec2 worldPointAt(int gridX, int gridY)Returns the world position of the top-left corner of the tile at the given grid coordinates.
Vec2 worldPointAt(IVec2 gridPoint)Returns the world position of the top-left corner of the tile at the given grid point.
IVec2 gridPointAt(float worldX, float worldY)Returns the grid coordinates of the tile that contains the given world position.
IVec2 gridPointAt(Vec2 worldPoint)Returns 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__)Parses 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__)Parses 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__) @trustedParses 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__)Allocates 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__)Frees all layers and associated memory.
void resize(Sz newRowCount, Sz newColCount)Sets the active row and column count without reallocating. Asserts if either value exceeds the hard limit.
void resizeTileSize(short newTileWidth, short newTileHeight)Sets the tile size in pixels.
void clear()Fills all layers with the empty tile id (-1).
void clear(Sz layerId)Fills the specified layer with the empty tile id (-1).
void ignoreLeak()Marks all layers as ignored for leak detection purposes.
void followPosition(Vec2 target, float delta)Moves the map to follow the target position at the specified speed.
void followPositionWithSlowdown(Vec2 target, float delta, float slowdown)Moves the map to follow the target position with gradual slowdown.
auto gridPoints(Vec2 topLeftViewPoint, Vec2 bottomRightViewPoint)Returns 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)Returns a lazy range of grid points visible within the given view rectangle.
auto tiles(Vec2 topLeftViewPoint, Vec2 bottomRightViewPoint, Sz layerId = 0)Returns a lazy range of `Tile` values visible within the given view corners on the specified layer. Each tile carries its size, id, and world-space position. Includes one extra tile of padding on t...
auto tiles(Rect viewArea, Sz layerId = 0)Returns a lazy range of `Tile` values visible within the given view rectangle on the specified layer.
Constructors
this(Sz rowCount, Sz colCount, short tileWidth, short tileHeight, IStr file = __FILE__, Sz line = __LINE__)Constructs a tile map with the given row and column count and tile size.
this(short tileWidth, short tileHeight, IStr file = __FILE__, Sz line = __LINE__)Constructs a tile map with the maximum layer size and the given tile size.
aliasTileMap = GTileMap!128

A tile map.

A single sprite animation, defined by its position in an atlas and playback settings.

Fields
ubyte frameRow
ubyte frameCount
ubyte frameSpeed
bool canRepeat

A sprite animation group that picks between 2 animations based on a direction angle.

Fields
ubyte[2] frameRows
ubyte frameCount
ubyte frameSpeed
bool canRepeat
angleStepThe angle step in degrees used to snap the input angle.
Methods
SpriteAnimation pick(float angle)Picks an animation based on the given angle in degrees.

A sprite animation group that picks between 4 animations based on a direction angle.

Fields
ubyte[4] frameRows
ubyte frameCount
ubyte frameSpeed
bool canRepeat
angleStepThe angle step in degrees used to snap the input angle.
Methods
SpriteAnimation pick(float angle)Picks an animation based on the given angle in degrees.

A sprite animation group that picks between 8 animations based on a direction angle.

Fields
ubyte[8] frameRows
ubyte frameCount
ubyte frameSpeed
bool canRepeat
angleStepThe angle step in degrees used to snap the input angle.
Methods
SpriteAnimation pick(float angle)Picks an animation based on the given angle in degrees.

A sprite animation group that picks between 16 animations based on a direction angle.

Fields
ubyte[16] frameRows
ubyte frameCount
ubyte frameSpeed
bool canRepeat
angleStepThe angle step in degrees used to snap the input angle.
Methods
SpriteAnimation pick(float angle)Picks an animation based on the given angle in degrees.
structSprite

A sprite with support for animation, positioning, and movement.

Fields
short width
short height
ushort atlasLeft
ushort atlasTop
float frameProgress
bool isPaused
SpriteAnimation animation
Vec2 position
Hook hook
Flip flip
Methods
float x() @trusted refReturns a reference to the x component of the sprite position.
float y() @trusted refReturns a reference to the y component of the sprite position.
Vec2 size()Returns the size of the sprite as a 2D vector.
Rect area()Returns the bounding rectangle of the sprite, adjusted by the hook.
bool hasSize()Returns true if the sprite has a non-zero size.
bool isActive()Returns true if the sprite is currently active (running).
bool hasAnimation()Returns true if the sprite has an animation assigned.
bool hasFirstFrame()Returns true if the sprite is on the first animation frame.
bool hasLastFrame()Returns true if the sprite is on the last animation frame.
bool hasFirstFrameProgress()Returns true if the sprite is on the first animation frame progress.
bool hasLastFrameProgress()Returns true if the sprite is on the last animation frame progress.
int frame()Returns the current animation frame of the sprite.
void reset(int resetFrame = 0)Resets the animation frame of the sprite.
void play(SpriteAnimation newAnimation, bool canKeepProgress = false)Starts playing a new animation, optionally preserving current frame progress.
void stop()Stops the current animation of the sprite.
void pause()Pauses the current animation of the sprite.
void resume()Resumes the current animation of the sprite.
void toggleIsPaused()Toggles the paused state of the sprite.
void update(float dt)Updates the state of the sprite.
void followPosition(Vec2 target, float delta)Moves the sprite to follow the target position at the specified speed.
void followPositionWithSlowdown(Vec2 target, float delta, float slowdown)Moves the sprite to follow the target position with gradual slowdown.
Constructors
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.
this(short width, short height, ushort atlasLeft, ushort atlasTop, float x, float y, Hook hook = Hook.topLeft)Initializes the sprite with the specified size, atlas position, and world position.
this(short width, short height, ushort atlasLeft, ushort atlasTop, Hook hook)Initializes the sprite with the specified size, atlas position, and world position.
structGTimer(alias tickTimeFunc)

A generic timer with pause/resume and repeat support. The tickTimeFunc 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.

Fields
float duration
float pauseTime
float startTime
float stopTimeElapsedTimeBuffer
bool canRepeat
Methods
bool isPaused()Returns true if the timer is currently paused.
bool isActive()Returns true if the timer is currently active (running).
bool hasStarted()Returns true if the timer has just started.
bool hasStopped()Returns true if the timer has just stopped.
void start(float newDuration, bool newCanRepeat)Starts the timer with new duration and repeat behavior.
void start(float newDuration = - 1.0f)Starts the timer with an optional new duration.
void stop()Stops the timer and records the time at which it stopped.
void toggleIsActive()Toggles the active state of the timer.
void pause()Pauses the time.
void resume()Resumes the timer from the paused state.
void toggleIsPaused()Toggles the paused state of the timer.
float time()Returns the current time of the timer and handles stop/repeat logic.
float timeLeft()Returns the remaining time of the timer and handles stop/repeat logic.
float timeLeftOrZero()Returns the remaining time, or zero if inactive.
void setTime(float newTime)Sets the current time of the timer. If the given value is non-zero, the timer becomes active.
float progress()Returns the current progress (between 0.0 to 1.0).
float progressLeft()Returns the remaining progress (between 0.0 to 1.0).
float progressLeftOrZero()Returns the remaining progress (between 0.0 to 1.0), or zero if inactive.
void setProgress(float value)Sets the progress to a specific value (between 0.0 to 1.0).
void setProgressLeft(float value)Sets the remaining progress to a specific value (between 0.0 to 1.0).
Constructors
this(float duration, bool canRepeat = false)Initializes the timer with the specified duration and repeat behavior.
enumStoryLineKind : ubyte

The kind of a story line.

empty = ' 'Not a line.
comment = '#'A comment.
label = '*'A label. Can be used to jump to a line.
text = '|'A line that just has text.
pause = '.'A line that ends the story.
menu = '^'A line that can provide user input.
expression = '$'A line that can execute story expressions.
procedure = '!'A line that can execute D functions.
enumStoryOp : ubyte

An operation in the story expression language.

ADD = '+'
SUB = '-'
MUL = '*'
DIV = '/'
MOD = '%'
AND = '&'
OR = '|'
LESS = '<'
GREATER = '>'
EQUAL = '='
NOT = '!'
POP = '~'
CLEAR
SWAP
COPY
COPYN
RANGE
IF
ELSE
THEN
CAT
SAME
WORD
NUMBER
LINE
DEBUG
LINEAR
ASSERT
END
ECHO
ECHON
LEAK
LEAKN
HERE
GET
GETN
SET
INIT
DROP
DROPN
INC
DEC
INCN
DECN
TOG
MENU
LOOP
SKIP
JUMP
aliasStoryWord = char[24]

A fixed-size word in the story expression language.

aliasStoryNumber = int

A number in the story expression language.

The underlying data of a story value.

A value in the story expression language, either a word or a number.

Fields
Methods
IStr toStr() @trusted

A named variable in the story expression language.

Fields

A start and end index pair used to identify ranges in the story.

Fields
uint a
uint b
structStory

A story script with its associated state for parsing and execution.

Fields
LStr script
StoryNumber lineIndex
StoryNumber nextLabelIndex
StoryNumber previousMenuResult
StoryNumber faultPrepareIndex
StoryOp faultOp
Sz faultTokenPosition
bool debugMode
bool linearMode
EchonFunc echonFunc
Methods
Fault prepare(IStr file = __FILE__, Sz line = __LINE__) @trusted
Fault parse(IStr text, IStr file = __FILE__, Sz line = __LINE__)
Fault execute(IStr expression, IStr file = __FILE__, Sz line = __LINE__) @trusted
Fault update(IStr file = __FILE__, Sz line = __LINE__)
Fault select(Sz i, IStr file = __FILE__, Sz line = __LINE__)
void reserve(Sz capacity, IStr file = __FILE__, Sz line = __LINE__)
void free(IStr file = __FILE__, Sz line = __LINE__)
void echon(IStr[] text...)
bool hasEnd()
bool hasPause()
bool hasMenu()
bool hasText()
void jumpLineIndex(StoryNumber labelIndex)
void ignoreLeak()
structGBoxIdPair(T)
Fields
T x
T y
aliasBoxId = ushort

A generic box ID.

aliasBoxFlags = ushort

Generic box flags.

aliasBoxUnionIdGroup = FixedList!(BoxUnionId, boxFixedCapacity)

An box actor ID.

structBoxWallId

A box wall ID.

A generic box ID pair.

A box actor ID pair.

A wall actor ID pair.

aliasBoxIdBuffer = FixedList!(BoxId, boxFixedCapacity)
aliasBoxActorIdBuffer = FixedList!(BoxActorId, boxFixedCapacity)
aliasBoxWallIdBuffer = FixedList!(BoxWallId, boxFixedCapacity)
enumBoxUnionType : ubyte
wall = 0x0
actor = 0x1

The flags of a box.

none = 0x0
isPassable = 0x1
isRiding = 0x2
enumBoxSide : ubyte

The side of a box.

none
top
left
right
bottom
aliasBox = SRect

The area of a box.

The properties of a box.

Fields
Vec2 remainder
BoxFlags flags
BoxSide side
structBoxData

The data of a box.

Fields
Box area
BoxProperties properties
structBoxMover

A helper for mobing things around a world.

Fields
Vec2 direction
Vec2 velocity
float speed
float acceleration
float gravity
float jump
float gravityFallFactor
float decelerationFactor
Methods
bool isSmooth()
bool isTopDown()
Vec2 move(Vec2 newDirection)
Constructors
this(float speed, float acceleration = 0.0f, float gravity = 0.0f, float jump = 0.0f)
structBoxWorld

A box world.

Fields
List!BoxData actors
BoxIdBuffer collisionIdBuffer
BoxIdBuffer squishedIdBuffer
int gridTileWidth
int gridTileHeight
Methods
BoxWallId pushWall(Box box, BoxSide side = BoxSide.none, IStr file = __FILE__, Sz line = __LINE__)
BoxActorId pushActor(Box box, BoxSide side = BoxSide.none, IStr file = __FILE__, Sz line = __LINE__)
Fault parseWallsCsv(IStr csv, int tileWidth, int tileHeight, IStr file = __FILE__, Sz line = __LINE__)
void reserve(Sz capacity, IStr file = __FILE__, Sz line = __LINE__)
void enableGrid(Sz rowCount, Sz colCount, int tileWidth, int tileHeight, IStr file = __FILE__, Sz line = __LINE__)
void free(IStr file = __FILE__, Sz line = __LINE__)
void clearWalls()
BoxWallId[] wallCollisions(Box box, bool canStopAtFirst = false) @trusted
BoxActorId[] actorCollisions(Box box, bool canStopAtFirst = false) @trusted
BoxWallId moveActorX(BoxActorId id, float amount)
BoxWallId moveActorXTo(BoxActorId id, float to, float amount)
BoxWallId moveActorXToWithSlowdown(BoxActorId id, float to, float amount, float slowdown)
BoxWallId moveActorY(BoxActorId id, float amount)
BoxWallId moveActorYTo(BoxActorId id, float to, float amount)
BoxWallId moveActorYToWithSlowdown(BoxActorId id, float to, float amount, float slowdown)
BoxWallIdPair moveActorToWithSlowdown(BoxActorId id, Vec2 to, Vec2 amount, float slowdown)
BoxActorId[] moveWallX(BoxWallId id, float amount)
BoxActorId[] moveWallXTo(BoxWallId id, float to, float amount)
BoxActorId[] moveWallXToWithSlowdown(BoxWallId id, float to, float amount, float slowdown)
BoxActorId[] moveWallY(BoxWallId id, float amount)
BoxActorId[] moveWallYTo(BoxWallId id, float to, float amount)
BoxActorId[] moveWallYToWithSlowdown(BoxWallId id, float to, float amount, float slowdown)
BoxActorId[] moveWall(BoxWallId id, Vec2 amount) @trusted
BoxActorId[] moveWallToWithSlowdown(BoxWallId id, Vec2 to, Vec2 amount, float slowdown)
void clear()
void ignoreLeak()
Constructors
this(Sz capacity, IStr file = __FILE__, Sz line = __LINE__)
structSlicePart

A part of a 9-slice.

Fields
IRect source
IRect target
IVec2 tileCount
bool isCorner
bool canTile

The parts of a 9-slice.

Functions 7

fnSliceParts computeSliceParts(IRect source, IRect target, Margin margin)Computes the parts of a 9-slice.
fnPalette!N csvRowToPalette(Sz N)(IStr csv, Sz row = 0, Sz startCol = 0)Converts a CSV row to a color palette. If the row can't be parsed, then the first value of the palette will be blank.
fnbool isMaybeStoryOp(IStr value)
fnbool isMaybeStoryNumber(IStr value)
fnbool isMaybeStoryWord(IStr value)

Variables 12

enumvardefaultStoryFixedListCapacity = 16
varHexPalette!2 wisp2

A 2-color palette inspired by the Playdate. Link: https://kapendev.itch.io/will-of-the-hair-wisp

varHexPalette!4 gb4

A 4-color palette inspired by the Game Boy. Link: https://lospec.com/palette-list/2-bit-matrix

varHexPalette!8 nes8

An 8-color palette inspired by the NES. Link: https://lospec.com/palette-list/mf-8

varHexPalette!16 pico8

A 16-color palette used by the PICO-8. Link: https://lospec.com/palette-list/pico-8

enumvarboxNoneId = 0
enumvarboxUnionTypeBit = (cast(BoxUnionId) 1) << (BoxUnionId.sizeof * 8 - 1)
enumvarboxErrorMessage = "Box is invalid or was never assigned."
enumvarboxFixedCapacity = 256