Options
All
  • Public
  • Public/Protected
  • All
Menu

Module utils

Index

Variables

Const FONT_NAME

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

Default font name

Const ITALIC_FONT_NAME

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

Italic font name

Const element_colors

element_colors: { jupiter: number; mars: number; mercury: number; venus: number } = ...

Element colors

Type declaration

  • jupiter: number
  • mars: number
  • mercury: number
  • venus: number

Const element_colors_in_battle

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

Const element_names

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

Const ordered_elements

ordered_elements: elements[] = ...

Default elements order

Const reverse_directions

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

  • 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.

direction_range

  • 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

  • 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.

get_direction_mask

  • get_direction_mask(direction: directions): number
  • 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

  • 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

  • get_distance(x1: number, x2: number, y1: number, y2: number, square_root?: boolean): 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.

    • square_root: boolean = true

      if false, returns the distance to the square.

    Returns number

    return the distance value.

get_front_position

  • 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

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

    Parameters

    Returns number

    returns the non diagonal direction.

get_opposite_direction

  • Returns the opposite of the given direction.

    Parameters

    Returns directions

    Opposite direction value

get_px_position

  • 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_surroundings

  • 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

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

    Parameters

    • game: Phaser.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

  • 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.

get_transition_directions

  • 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

hex2rgb

  • 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

  • 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

join_directions

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

    Parameters

    Returns directions

    Diagonal direction value

kill_all_sprites

  • kill_all_sprites(group: any, destroy?: boolean): void
  • Either kills or destroys each sprite in the group

    Parameters

    • group: any

      The parent group

    • destroy: boolean = false

      If true, child is destroyed instead

    Returns void

mount_collision_polygon

  • 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.

random_normal

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

    Returns number

    returns a normal pseudo-random number.

range_360

  • 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

  • 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_direction

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

    Parameters

    Returns directions[]

    Array with split direction values

variation

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

    Returns number

    Random number from 0 to 4

Generated using TypeDoc