Options
All
  • Public
  • Public/Protected
  • All
Menu

Module utils

Index

Variables

FONT_NAME: "gs-bmp-font" = "gs-bmp-font"

Default font name

ITALIC_FONT_NAME: "gs-italic-bmp-font" = "gs-italic-bmp-font"

Italic font name

directions_angles: { 0: number; 1: number; 2: number; 3: number; 4: number; 5: number; 6: number; 7: number } = ...

The directions angles

Type declaration

  • 0: number
  • 1: number
  • 2: number
  • 3: number
  • 4: number
  • 5: number
  • 6: number
  • 7: number
element_colors: { jupiter: number; mars: number; mercury: number; venus: number } = ...

Element colors

Type declaration

  • jupiter: number
  • mars: number
  • mercury: number
  • venus: number
element_colors_in_battle: { jupiter: number; mars: number; mercury: number; no_element: number; venus: number } = ...

Element colors in battle

Type declaration

  • jupiter: number
  • mars: number
  • mercury: number
  • no_element: number
  • venus: number
element_names: { all_elements: string; jupiter: string; mars: string; mercury: string; venus: string } = ...

Element names

Type declaration

  • all_elements: string
  • jupiter: string
  • mars: string
  • mercury: string
  • venus: string
ordered_elements: elements[] = ...

Default elements order

reverse_directions: { 0: string; 1: string; 2: string; 3: string; 4: string; 5: string; 6: string; 7: string } = ...

8-Directional direction keys

Type declaration

  • 0: string
  • 1: string
  • 2: string
  • 3: string
  • 4: string
  • 5: string
  • 6: string
  • 7: string

Functions

  • change_brightness(hex: string | number, percent: number): number
  • Changes the brightness of a given color code.

    Parameters

    • hex: string | number

      the input color in hex.

    • percent: number

      how much the brightness should change.

    Returns number

    returns the new color in hex.

  • Given a direction, returns this direction and its adjacent directions.

    Parameters

    Returns directions[]

    Returns the range of the given direction.

  • get_centered_pos_in_px(tile_pos: number, tile_size: number): number
  • Gets the center position of a tile in pixels.

    Parameters

    • tile_pos: number

      the tile position.

    • tile_size: number

      the tile size.

    Returns number

    centered tile position in pixels.

  • Generate a mask for the given direction. Examples:

    • The given direction is left, which is 4, then this function will return: 00010000
    • The given direction is right, which is 0, then this function will return: 00000001

    Parameters

    • direction: directions

      The direction to generate the mask.

    Returns number

    Returns the mask.

  • get_directions(with_diagonals?: boolean): directions[]
  • Lists all directions, diagonals optional.

    Parameters

    • with_diagonals: boolean = false

      If true, includes diagonals.

    Returns directions[]

    Returns the directions.

  • get_distance(x1: number, x2: number, y1: number, y2: number): number
  • Calculates the distance between two points.

    Parameters

    • x1: number

      source x position.

    • x2: number

      dest x position.

    • y1: number

      source y position.

    • y2: number

      dest y position.

    Returns number

    return the distance value.

  • get_front_position(x_pos: number, y_pos: number, direction: directions, strict_cardinal?: boolean): { x: number; y: number }
  • Given a direction and a current position, returns the next front position.

    Parameters

    • x_pos: number

      x tile position.

    • y_pos: number

      y tile position.

    • direction: directions

      the direction that's going towards.

    • strict_cardinal: boolean = true

      if true, returns null on diagonal input. Otherwise, returns input as is.

    Returns { x: number; y: number }

    the front position.

    • x: number
    • y: number
  • get_non_diagonal_direction(direction: directions): number
  • Transforms a direction into a non diagonal direction.

    Parameters

    Returns number

    returns the non diagonal direction.

  • get_px_position(tile_pos: number, tile_size: number): number
  • Gets the px position of a given position in tile.

    Parameters

    • tile_pos: number
    • tile_size: number

      the tile size.

    Returns number

    returns the px position.

  • get_sqr_distance(x1: number, x2: number, y1: number, y2: number): number
  • Calculates the squared distance between two points.

    Parameters

    • x1: number

      source x position.

    • x2: number

      dest x position.

    • y1: number

      source y position.

    • y2: number

      dest y position.

    Returns number

    return the squared distance value.

  • get_surroundings(x: number, y: number, with_diagonals?: boolean, shift?: number): { diag: boolean; direction: directions; x: number; y: number }[]
  • Returns the surrounding positions. Diagonals are optional.

    Parameters

    • x: number

      the x reference position.

    • y: number

      the y reference position.

    • with_diagonals: boolean = false

      if true, includes diagonals.

    • shift: number = 1

      how distant if the surrounding positions from the given position.

    Returns { diag: boolean; direction: directions; x: number; y: number }[]

    Returns the surrounding positions.

  • get_text_width(game: Game, text: string, italic?: boolean): number
  • Obtains the text width in pixels (INEFFICIENT).

    Parameters

    • game: Game

      the Phaser.Game instance

    • text: string

      the text string to measure width

    • italic: boolean = false

      whether the text is in italic

    Returns number

  • get_tile_position(pos: number, tile_size: number): number
  • Gets the tile position of a given position in px.

    Parameters

    • pos: number

      the position in px.

    • tile_size: number

      the tile size.

    Returns number

    returns the tile position.

  • Gets the directions between the current direction and a desired/target direction. Example of transition between left and right: left -> up left -> up -> up right -> right.

    Parameters

    • current_direction: directions

      Current direction value

    • desired_direction: directions

      Desired/Target direction value

    Returns directions

    The direction value to apply

  • get_vector_direction(x1: number, x2: number, y1: number, y2: number): directions
  • Gets the direction of a given vector.

    Parameters

    • x1: number

      x source pos.

    • x2: number

      x dest pos.

    • y1: number

      y source pos.

    • y2: number

      y dest pos.

    Returns directions

    The direction of the given vector.

  • hex2rgb(hex: string | number): { b: number; g: number; r: number }
  • Converts a color from hex to rgb.

    Parameters

    • hex: string | number

      the color in hex format.

    Returns { b: number; g: number; r: number }

    the color in rgb format.

    • b: number
    • g: number
    • r: number
  • hsv2rgb(h: number, s: number, v: number): number[]
  • Transforms HSV color into RGB color

    Parameters

    • h: number

      hue channel color value

    • s: number

      saturation channel color value

    • v: number

      value channel color value

    Returns number[]

    returns the color in RGB

  • Returns the diagonal value for its component directions Example: Input: 6, 0 (up, right) / Output: 7 (up_right)

    Parameters

    Returns directions

    Diagonal direction value

  • mount_collision_polygon(width: number, shift: number, bevel?: number): number[][]
  • Creates a collision polygon.

    Parameters

    • width: number

      Width of the body

    • shift: number

      Shift value

    • bevel: number = 0

      Body's bevel value

    Returns number[][]

    Returns a list of coodinates of the polygon.

  • next_px_step(current_x: number, current_y: number, distance: number, angle_direction: number): { x: number; y: number }
  • Advances a step in a given direction.

    Parameters

    • current_x: number

      the current x pos in px.

    • current_y: number

      the current x pos in px.

    • distance: number

      the step distance.

    • angle_direction: number

      the angle of the new direction.

    Returns { x: number; y: number }

    Returns the new x and y position.

    • x: number
    • y: number
  • parse_blend_mode(blend_mode: string): blendModes
  • Convert a string to a PIXI.blendModes enum value

    Parameters

    • blend_mode: string

      Desired blend mode string

    Returns blendModes

    returns a PIXI.blendModes enum value

  • promised_wait(game: Game, time: number, callback?: (() => void)): Promise<void>
  • Promised way to create and wait a Phaser.Timer. Waits for the amount of time given.

    Parameters

    • game: Game

      the Phaser game object.

    • time: number

      the time in ms.

    • Optional callback: (() => void)

      on timer finish callback.

        • (): void
        • Returns void

    Returns Promise<void>

  • random_normal(): number
  • Standard Normal variate using Box-Muller transform. Mean = 0, variance = 1.

    Returns number

    returns a normal pseudo-random number.

  • range_360(angle: number): number
  • Places the angle (radians) in the [0,2*PI[ range.

    Parameters

    • angle: number

      any angle in radians.

    Returns number

    Angle in the [0,2*PI[ range.

  • rgb2hsv(r: number, g: number, b: number): number[]
  • Transforms RGB color into HSV color.

    Parameters

    • r: number

      red channel color value [0, 255]

    • g: number

      green channel color value [0, 255]

    • b: number

      blue channel color value [0, 255]

    Returns number[]

    returns the color in HSV

  • split_diag_direction(direction: directions): { x: number; y: number }
  • Splits an diagonal direction into component cardinal directions.

    Parameters

    Returns { x: number; y: number }

    The x and y component cardinal directions.

    • x: number
    • y: number
  • Returns the direction values for diagonal directions Example: Input: 7 (up_right) / Output: [6,0]

    Parameters

    Returns directions[]

    Array with split direction values

  • variation(): number
  • Returns a random number from 0 to 4.

    Returns number

    Random number from 0 to 4

  • weighted_random_pick<T>(items: T[], weights: number[]): T
  • Picks an item from an input array randomly based on weights list. Items and weights array must agree.

    Type Parameters

    • T

    Parameters

    • items: T[]

      array of items to has one element picked.

    • weights: number[]

      weights for each element of items array.

    Returns T

    returns one element of items.

Generated using TypeDoc