parin.joka.game
The game module provides game related types and functions.
Types 49
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.
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.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.A generic tile map. N is the maximum layer row or column size.
maxLayerRowColCountMaximum layer row or column size. maxLayerCapacityMaximum layer size. extraTileCountExtra tile padding added when computing visible tile ranges.TileMapLayers layersSz rowCountSz colCountshort tileWidthshort tileHeightVec2 positionshort 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.int width()Returns the total pixel width of the active map area.int height()Returns the total pixel height of the active map area.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 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 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 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.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)Picks 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)Picks 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)Picks 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)Picks 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 flipbool 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.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.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.
float durationfloat pauseTimefloat startTimefloat stopTimeElapsedTimeBufferbool canRepeatbool 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).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.
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 echonFuncbool hasKind(StoryLineKind kind)bool hasEnd()bool hasPause()bool hasProcedure()bool hasMenu()bool hasText()Fault throwOpFault(StoryOp op, Sz position)StoryNumber findVariable(StoryWord name)StoryNumber findLabel(StoryWord name)void setNextLabelIndex(StoryNumber value)void setLineIndex(StoryNumber value)void resetLineIndex()void jumpLineIndex(StoryNumber labelIndex)void ignoreLeak()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 gridTileHeightBoxActorId 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 enableGrid(Sz rowCount, Sz colCount, int tileWidth, int tileHeight, IStr file = __FILE__, Sz line = __LINE__)void disableGrid()void removeWall(BoxWallId id)void removeActor(BoxActorId id)void clearWalls()void clearActors()bool isGridPointValid(IVec2 point)BoxProperties wallProperties(BoxWallId id) refBox actor(BoxActorId id) refBoxProperties actorProperties(BoxActorId id) refBoxWallId[] wallCollisions(Box box, bool canStopAtFirst = false) @trustedBoxWallId hasWallCollision(Box box)BoxWallId hasWallCollision(BoxWallId id1, BoxWallId id2)BoxActorId[] actorCollisions(Box box, bool canStopAtFirst = false) @trustedBoxActorId hasActorCollision(BoxActorId id1, BoxActorId id2)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 moveActor(BoxActorId id, Vec2 amount)BoxWallIdPair moveActorTo(BoxActorId id, Vec2 to, Vec2 amount)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) @trustedBoxActorId[] moveWallTo(BoxWallId id, Vec2 to, Vec2 amount)BoxActorId[] moveWallToWithSlowdown(BoxWallId id, Vec2 to, Vec2 amount, float slowdown)void clear()void ignoreLeak()The parts of a 9-slice.
Functions 7
SliceParts computeSliceParts(IRect source, IRect target, Margin margin)Computes the parts of a 9-slice.Palette!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.bool isMaybeStoryOp(IStr value)bool isMaybeStoryNumber(IStr value)bool isMaybeStoryWord(IStr value)Maybe!StoryLineKind toStoryLineKind(char from)Variables 12
defaultStoryFixedListCapacity = 16HexPalette!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
HexPalette!16 oneDarkBased on monkyyy's repo: https://github.com/crazymonkyyy/leet-haker-colors Link: https://github.com/pulsar-edit/pulsar
HexPalette!16 gruvboxDarkBased on monkyyy's repo: https://github.com/crazymonkyyy/leet-haker-colors Link: https://github.com/morhetz/gruvbox
HexPalette!16 solarizedDarkBased on monkyyy's repo: https://github.com/crazymonkyyy/leet-haker-colors Link: https://ethanschoonover.com/solarized/
boxNoneId = 0boxUnionTypeBit = (cast(BoxUnionId) 1) << (BoxUnionId.sizeof * 8 - 1)boxErrorMessage = "Box is invalid or was never assigned."boxFixedCapacity = 256