Class

Collision

Collision()

Entity Collision
Constructor

# new Collision()

View Source browser/lib/Collision.js, line 8

Methods

# static arcBoxCollision(params) → {boolean}

Caclulate collision beween entity (arc) and wall (box). This method is a specialized function designed for detecting collisions between an arc-shaped entity (potentially representing the player) and a rectangular box-shaped entity (potentially representing a wall) on the canvas.
Parameters:
Name Type Description
params Object
arcX number the arc entity's x-coordinate
arcY number the arc entity's y-coordinate
rectX number the box entity's x-coordinate
rectY number the box entity's y-coordinate
size number the size of the box entity
radius number the radius of the arc entity

View Source browser/lib/Collision.js, line 83

boolean

# static distance(e1, e2, useVectors) → {number}

Determine distance between two vectors or two entities with vectors. This method calculates the Euclidean distance between two points. It's versatile, accepting either entity objects or numerical values as parameters. When `vectors` is set to `true`, the method considers the parameters as vector components, determining the distance between the points they represent.
Parameters:
Name Type Default Description
e1 Object | number the first entity or vector coordinates
e2 Object | number the second entity or vector coordinates
useVectors boolean true whether or not we're passing entities or vectors

View Source browser/lib/Collision.js, line 55

number

# static entityToPlayer(entity, game, callbackOptions) → {void}

Player-to-entity collision.
Parameters:
Name Type Description
entity Object the entity
game Game the managed game instance
callbackOptions Object
on string | null maps to the entity type to know which entity to execute on
onDistance number | null the distance between the player and the entity before the callback executes
onCallback function | null the callback to execute when the player and entity intersect
See:

View Source browser/lib/Collision.js, line 165

void

# static entityToWalls(entity, walls) → {Object}

Detect and handle collision between entities and walls.
Parameters:
Name Type Description
entity Object a game entity
walls array the walls
See:

View Source browser/lib/Collision.js, line 113

Object

# static intersection(r1, r2) → {boolean}

Determine whether or not two entities intersect on the canvas. This method is a basic collision check that determines if two entities, defined by their rectangular properties (x, y, width, height), intersect. The logic is straightforward: if any side of one entity is positioned to the left, right, above, or below the other, they do not intersect. Otherwise, they overlap, triggering a collision.
Parameters:
Name Type Description
r1 Object first entity
x number first entity x coordinate
y number first entity y coordinate
width number first entity width
height number first entity height
r2 Object second entity
x number second entity x coordinate
y number second entity y coordinate
width number second entity width
height number second entity height

View Source browser/lib/Collision.js, line 32

boolean