This class manages collision between the main concepts of the engine: map, hero, npcs and interactable objects.

Constructors

Properties

_custom_bodies: {
    [label: string]: Phaser.Physics.P2.Body;
}

Type declaration

  • [label: string]: Phaser.Physics.P2.Body
_dynamic_events_collision_group: CollisionGroup
_hero_collision_group: CollisionGroup
_interactable_objs_collision_groups: {
    [layer_index: number]: Phaser.Physics.P2.CollisionGroup;
}

Type declaration

  • [layer_index: number]: Phaser.Physics.P2.CollisionGroup
_map_collision_group: CollisionGroup
_npc_collision_groups: {
    [layer_index: number]: Phaser.Physics.P2.CollisionGroup;
}

Type declaration

  • [layer_index: number]: Phaser.Physics.P2.CollisionGroup
data: GoldenSun
game: Game
max_layers_created: number
MINIMAL_SLOPE: 0.1 = 0.1
ROTATION_NORMAL: directions[] = ...

This variable converts from normal_angle region (floor((angle-15)/30)) to in-game rotation.

SPEED_LIMIT_TO_STOP: 13 = 13
SPEED_LIMIT_TO_STOP_WORLD_MAP: 9 = 9

Accessors

  • get custom_bodies(): {
        [label: string]: Phaser.Physics.P2.Body;
    }
  • Returns {
        [label: string]: Phaser.Physics.P2.Body;
    }

    • [label: string]: Phaser.Physics.P2.Body
  • get dynamic_events_collision_group(): CollisionGroup
  • Returns CollisionGroup

  • get interactable_objs_collision_groups(): {
        [layer_index: number]: Phaser.Physics.P2.CollisionGroup;
    }
  • Returns {
        [layer_index: number]: Phaser.Physics.P2.CollisionGroup;
    }

    • [layer_index: number]: Phaser.Physics.P2.CollisionGroup
  • get npc_collision_groups(): {
        [layer_index: number]: Phaser.Physics.P2.CollisionGroup;
    }
  • Returns {
        [layer_index: number]: Phaser.Physics.P2.CollisionGroup;
    }

    • [layer_index: number]: Phaser.Physics.P2.CollisionGroup

Methods

  • Changes the map body according to a given collision layer index.

    Parameters

    • new_collision_layer_index: number

      Target collision layer.

    • sort_sprites: boolean = false

      if true, it will also sort the sprites in the map after reordering the layers.

    Returns void

  • This function checks whether is necessary to stop when colliding or change the char direction in order to adapt its movement to the collision slope.

    Parameters

    Returns void

  • Creates npcs and interactable objects collision groups.

    Parameters

    • map: Map

      the current map.

    Returns void

  • Configs collisions between hero, map, npcs and interactable objects.

    Parameters

    • collision_layer: number

      the current collision layer.

    Returns void

  • Configs the world physics attributes.

    Returns void

  • Creates a custom body on interactable objects collision group. It can be a box, circle or polygon.

    Parameters

    • label: string

      the custom body unique label name.

    • x: number

      the x position of the body.

    • y: number

      the y position of the body.

    • body_type: "circle" | "box" | "polygon"
    • properties: {
          collision_layer?: number;
          height?: number;
          points?: number[][];
          radius?: number;
          width?: number;
      }

      some properties regarding the type of the body.

      • Optional collision_layer?: number

        The target collision layer for the body to be.

      • Optional height?: number

        The height of the box.

      • Optional points?: number[][]

        The array of polygon points.

      • Optional radius?: number

        The radius of the circle.

      • Optional width?: number

        The width of the box.

    Returns Body

    returns the created body.

  • Destroys a custom body.

    Parameters

    • label: string

      the unique label of the body to be destroyed.

    Returns void

  • Disables collision between hero and map.

    Parameters

    • sensor_method: boolean = false

      if true, disables collision by only setting the map shapes as a sensor.

    Returns void

  • Disables collision between hero and npcs.

    Parameters

    • Optional collision_layer: number

      if given, disables only on this layer.

    Returns void

  • Enables collision between hero and map.

    Parameters

    • sensor_method: boolean = false

      if true, enables collision by only setting the map shapes as not a sensor.

    Returns void

  • Enables collision between hero and npcs.

    Parameters

    • Optional collision_layer: number

      if given, enables only on this layer.

    Returns void

  • Given a surface range, loop over the tiles in this range and find the intersection polygons for each tile.

    Parameters

    • map: Map

      the current map object.

    • min_x: number

      the min x range in px.

    • max_x: number

      the max x range in px.

    • min_y: number

      the min y range in px.

    • max_y: number

      the max y range in px.

    • Optional polygon: number[][]

      The polygon. The first and last positions are equivalent, and they MUST contain identical values.

    Returns Map<number, number[][][]>

    Returns a JS Map where its key is a location key and its value is the list of polygons for this location key.